Go to the documentation of this file.
55 const uint8_t *prev_line,
const uint8_t *next_line,
56 const uint8_t *prev2_line,
const uint8_t *next2_line,
57 const uint8_t *prev3_line,
const uint8_t *next3_line,
62 const uint8_t *
const next,
63 const uint8_t *
const prev2,
64 const uint8_t *
const next2,
65 const uint8_t *
const prev3,
66 const uint8_t *
const next3,
67 int end,
int x,
int k,
int depth);
70 const uint16_t *
const next,
71 const uint16_t *
const prev2,
72 const uint16_t *
const next2,
73 const uint16_t *
const prev3,
74 const uint16_t *
const next3,
75 int end,
int x,
int k,
int depth);
79 #define S (MAX_R * 2 + 1)
81 #define OFFSET(x) offsetof(ESTDIFContext, x)
82 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
83 #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, 0, 0, FLAGS, unit }
87 CONST(
"frame",
"send one frame for each frame", 0,
"mode"),
88 CONST(
"field",
"send one frame for each field", 1,
"mode"),
90 CONST(
"tff",
"assume top field first", 0,
"parity"),
91 CONST(
"bff",
"assume bottom field first", 1,
"parity"),
92 CONST(
"auto",
"auto detect parity", -1,
"parity"),
94 CONST(
"all",
"deinterlace all frames", 0,
"deint"),
95 CONST(
"interlaced",
"only deinterlace frames marked as interlaced", 1,
"deint"),
102 CONST(
"2p",
"two-point interpolation", 0,
"interp"),
103 CONST(
"4p",
"four-point interpolation", 1,
"interp"),
104 CONST(
"6p",
"six-point interpolation", 2,
"interp"),
151 #define MIDL(type, ss) \
152 static unsigned midl_##ss(const type *const prev, \
153 const type *const next, \
154 int end, int x, int k) \
156 return (prev[av_clip(x + k, 0, end)] + \
157 next[av_clip(x - k, 0, end)] + 1) >> 1; \
163 #define MID2(type, ss) \
164 static unsigned mid2_##ss(const type *const prev, \
165 const type *const next, \
166 const type *const prev2, \
167 const type *const next2, \
168 const type *const prev3, \
169 const type *const next3, \
170 int end, int x, int k, int depth) \
172 return (prev[av_clip(x + k, 0, end)] + \
173 next[av_clip(x - k, 0, end)] + 1) >> 1; \
179 #define MID4(type, ss) \
180 static unsigned mid4_##ss(const type *const prev, \
181 const type *const next, \
182 const type *const prev2, \
183 const type *const next2, \
184 const type *const prev3, \
185 const type *const next3, \
186 int end, int x, int k, int depth) \
188 return av_clip_uintp2_c(( \
189 9 * (prev[av_clip(x + k, 0, end)] + \
190 next[av_clip(x - k, 0, end)]) - \
191 1 * (prev2[av_clip(x + k*3, 0, end)] + \
192 next2[av_clip(x - k*3, 0, end)]) + 8) >> 4, \
199 #define MID6(type, ss) \
200 static unsigned mid6_##ss(const type *const prev, \
201 const type *const next, \
202 const type *const prev2, \
203 const type *const next2, \
204 const type *const prev3, \
205 const type *const next3, \
206 int end, int x, int k, int depth) \
208 return av_clip_uintp2_c(( \
209 20 * (prev[av_clip(x + k, 0, end)] + \
210 next[av_clip(x - k, 0, end)]) - \
211 5 * (prev2[av_clip(x + k*3, 0, end)] + \
212 next2[av_clip(x - k*3, 0, end)]) + \
213 1 * (prev3[av_clip(x + k*5, 0, end)] + \
214 next3[av_clip(x - k*5, 0, end)]) + 16) >> 5, \
221 #define DIFF(type, ss) \
222 static unsigned diff_##ss(const type *const prev, \
223 const type *const next, \
226 return FFABS(prev[x] - next[y]); \
232 #define COST(type, ss) \
233 static unsigned cost_##ss(const type *const prev, \
234 const type *const next, \
235 int end, int x, int k) \
237 const int m = midl_##ss(prev, next, end, x, k); \
238 const int p = prev[x]; \
239 const int n = next[x]; \
241 return FFABS(p - m) + FFABS(n - m); \
247 #define INTERPOLATE(type, atype, amax, ss) \
248 static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \
249 const uint8_t *const pprev_line, \
250 const uint8_t *const nnext_line, \
251 const uint8_t *const pprev2_line, \
252 const uint8_t *const nnext2_line, \
253 const uint8_t *const pprev3_line, \
254 const uint8_t *const nnext3_line, \
255 int x, int width, int rslope, \
256 int redge, int depth, \
259 type *dst = (type *)ddst; \
260 const type *const prev_line = (const type *const)pprev_line; \
261 const type *const prev2_line = (const type *const)pprev2_line; \
262 const type *const prev3_line = (const type *const)pprev3_line; \
263 const type *const next_line = (const type *const)nnext_line; \
264 const type *const next2_line = (const type *const)nnext2_line; \
265 const type *const next3_line = (const type *const)nnext3_line; \
266 const int interp = s->interp; \
267 const int ecost = s->ecost * 32.f; \
268 const int dcost = s->dcost * s->max; \
269 const int end = width - 1; \
270 const atype mcost = s->mcost * s->redge * 4.f; \
271 atype sd[S], sD[S], di = 0; \
275 for (int i = -rslope; i <= rslope && abs(k) > rslope; i++) { \
278 for (int j = -redge; j <= redge; j++) { \
279 const int xx = av_clip(x + i + j, 0, end); \
280 const int yy = av_clip(x - i + j, 0, end); \
281 sum += diff_##ss(prev_line, next_line, xx, yy); \
282 sum += diff_##ss(prev2_line, prev_line, xx, yy); \
283 sum += diff_##ss(next_line, next2_line, xx, yy); \
286 sD[i + rslope] = ecost * sum; \
287 sD[i + rslope] += mcost * cost_##ss(prev_line, next_line, end, x, i);\
288 sD[i + rslope] += dcost * abs(i); \
290 dmin = FFMIN(sD[i + rslope], dmin); \
293 for (int i = -rslope; i <= rslope; i++) { \
296 for (int j = -redge; j <= redge; j++) { \
297 const int xx = av_clip(x + k + i + j, 0, end); \
298 const int yy = av_clip(x - k - i + j, 0, end); \
299 sum += diff_##ss(prev_line, next_line, xx, yy); \
300 sum += diff_##ss(prev2_line, prev_line, xx, yy); \
301 sum += diff_##ss(next_line, next2_line, xx, yy); \
304 sd[i + rslope] = ecost * sum; \
305 sd[i + rslope] += mcost * cost_##ss(prev_line, next_line, end, x, k+i);\
306 sd[i + rslope] += dcost * abs(k + i); \
308 dmin = FFMIN(sd[i + rslope], dmin); \
311 for (int i = -rslope; i <= rslope && abs(k) > rslope; i++) { \
312 if (dmin == sD[i + rslope]) { \
319 for (int i = -rslope; i <= rslope && !di; i++) { \
320 if (dmin == sd[i + rslope]) { \
326 dst[x] = s->mid_##ss[interp](prev_line, next_line, \
327 prev2_line, next2_line, \
328 prev3_line, next3_line, \
338 int jobnr,
int nb_jobs)
344 const int rslope =
s->rslope;
345 const int redge =
s->redge;
346 const int depth =
s->depth;
351 for (
int plane = 0; plane <
s->nb_planes; plane++) {
352 const uint8_t *src_data = in->
data[plane];
353 uint8_t *dst_data =
out->data[plane];
354 const int linesize =
s->linesize[plane];
355 const int width =
s->planewidth[plane];
356 const int height =
s->planeheight[plane];
357 const int src_linesize = in->
linesize[plane];
358 const int dst_linesize =
out->linesize[plane];
359 const int start = (
height * jobnr) / nb_jobs;
360 const int end = (
height * (jobnr+1)) / nb_jobs;
361 const uint8_t *prev_line, *prev2_line, *next_line, *next2_line, *in_line;
362 const uint8_t *prev3_line, *next3_line;
366 y_out = start + (tff ^ (start & 1));
368 in_line = src_data + (y_out * src_linesize);
369 out_line = dst_data + (y_out * dst_linesize);
371 while (y_out < end) {
372 memcpy(out_line, in_line, linesize);
374 in_line += src_linesize * 2;
375 out_line += dst_linesize * 2;
378 y_out = start + ((!tff) ^ (start & 1));
379 out_line = dst_data + (y_out * dst_linesize);
381 for (
int y = y_out; y < end; y += 2) {
382 int y_prev3_in = y - 5;
383 int y_next3_in = y + 5;
384 int y_prev2_in = y - 3;
385 int y_next2_in = y + 3;
386 int y_prev_in = y - 1;
387 int y_next_in = y + 1;
390 while (y_prev3_in < 0)
393 while (y_next3_in >=
height)
396 while (y_prev2_in < 0)
399 while (y_next2_in >=
height)
402 while (y_prev_in < 0)
405 while (y_next_in >=
height)
408 prev3_line = src_data + (y_prev3_in * src_linesize);
409 next3_line = src_data + (y_next3_in * src_linesize);
411 prev2_line = src_data + (y_prev2_in * src_linesize);
412 next2_line = src_data + (y_next2_in * src_linesize);
414 prev_line = src_data + (y_prev_in * src_linesize);
415 next_line = src_data + (y_next_in * src_linesize);
419 for (
int x = 0; x <
width; x++) {
420 s->interpolate(
s, out_line,
421 prev_line, next_line,
422 prev2_line, next2_line,
423 prev3_line, next3_line,
424 x,
width, rslope, redge, depth, &k);
427 out_line += 2 * dst_linesize;
445 out->interlaced_frame = 0;
450 FFMIN(
s->planeheight[1] / 2,
s->nb_threads));
453 s->field = !
s->field;
469 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
471 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
480 s->depth =
desc->comp[0].depth;
481 s->interpolate =
s->depth <= 8 ? interpolate_8 : interpolate_16;
482 s->mid_8[0] = mid2_8;
483 s->mid_8[1] = mid4_8;
484 s->mid_8[2] = mid6_8;
485 s->mid_16[0] = mid2_16;
486 s->mid_16[1] = mid4_16;
487 s->mid_16[2] = mid6_16;
488 s->max = (1 << (
s->depth)) - 1;
503 if ((
s->deint && !
s->prev->interlaced_frame) ||
ctx->is_disabled) {
510 s->pts =
s->prev->pts * 2;
512 if (ret < 0 || s->
mode == 0) {
518 s->pts =
s->prev->pts + in->
pts;
543 ctx->outputs[0]->time_base);
546 }
else if (
ret < 0) {
582 .priv_class = &estdif_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRAP16
void(* interpolate)(struct ESTDIFContext *s, uint8_t *dst, const uint8_t *prev_line, const uint8_t *next_line, const uint8_t *prev2_line, const uint8_t *next2_line, const uint8_t *prev3_line, const uint8_t *next3_line, int x, int width, int rslope, int redge, int depth, int *K)
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AVERROR_EOF
End of file.
static int deinterlace_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define FILTER_PIXFMTS_ARRAY(array)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
static const AVFilterPad estdif_inputs[]
float ecost
edge cost for edge matching
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_PIX_FMT_YUVA422P9
This structure describes decoded (raw) audio or video data.
int parity
frame field parity
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P10
int top_field_first
If the content is interlaced, is top field displayed first.
unsigned(* mid_16[3])(const uint16_t *const prev, const uint16_t *const next, const uint16_t *const prev2, const uint16_t *const next2, const uint16_t *const prev3, const uint16_t *const next3, int end, int x, int k, int depth)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
#define AV_PIX_FMT_YUV420P10
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
int deint
which frames to deinterlace
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
A link between two filters.
#define AV_PIX_FMT_YUVA422P10
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_GBRP14
static enum AVPixelFormat pix_fmts[]
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
#define AV_PIX_FMT_GBRP10
static int config_output(AVFilterLink *outlink)
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_GRAY16
A filter pad used for either input or output.
#define AV_PIX_FMT_YUV444P10
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_PIX_FMT_YUV422P16
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_PIX_FMT_GBRAP10
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
#define AV_PIX_FMT_GBRAP12
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
int field
which field are we on, 0 or 1
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P16
float dcost
distance cost for edge matching
#define AV_PIX_FMT_GRAY14
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_INPUTS(array)
static int config_input(AVFilterLink *inlink)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
int mode
0 is frame, 1 is field
#define AV_PIX_FMT_GRAY10
int interp
type of interpolation
#define AV_PIX_FMT_GBRP16
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Rational number (pair of numerator and denominator).
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
float mcost
middle cost for edge matching
#define AV_PIX_FMT_YUV440P10
static av_cold void uninit(AVFilterContext *ctx)
#define AV_PIX_FMT_YUV422P10
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static const AVFilterPad estdif_outputs[]
int linesize[4]
bytes of pixel data per line for each plane
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
unsigned(* mid_8[3])(const uint8_t *const prev, const uint8_t *const next, const uint8_t *const prev2, const uint8_t *const next2, const uint8_t *const prev3, const uint8_t *const next3, int end, int x, int k, int depth)
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV444P12
AVFilterContext * src
source filter
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define INTERPOLATE(type, atype, amax, ss)
#define AV_PIX_FMT_YUVA444P10
int interlaced_frame
The content of the picture is interlaced.
const AVFilter ff_vf_estdif
int planeheight[4]
height of each plane
int w
agreed upon image width
#define AV_PIX_FMT_GBRP12
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Used for passing data between threads.
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
#define CONST(name, help, val, unit)
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
const char * name
Pad name.
#define AV_PIX_FMT_YUV444P9
static const AVOption estdif_options[]
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P14
int h
agreed upon image height
static int request_frame(AVFilterLink *link)
#define AV_PIX_FMT_YUVA422P12
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
AVFILTER_DEFINE_CLASS(estdif)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static int filter(AVFilterContext *ctx, int is_second, AVFrame *in)
int redge
best edge match search radius
#define AV_PIX_FMT_YUV440P12
int planewidth[4]
width of each plane
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_GRAY12
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int rslope
best edge slope search radius
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_PIX_FMT_YUV420P14