53 #define OFFSET(x) offsetof(W3FDIFContext, x)
54 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
55 #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, 0, 0, FLAGS, unit }
62 CONST(
"frame",
"send one frame for each frame", 0,
"mode"),
63 CONST(
"field",
"send one frame for each field", 1,
"mode"),
65 CONST(
"tff",
"assume top field first", 0,
"parity"),
66 CONST(
"bff",
"assume bottom field first", 1,
"parity"),
67 CONST(
"auto",
"auto detect parity", -1,
"parity"),
69 CONST(
"all",
"deinterlace all frames", 0,
"deint"),
70 CONST(
"interlaced",
"only deinterlace frames marked as interlaced", 1,
"deint"),
112 const int16_t *coef,
int linesize)
116 for (
i = 0;
i < linesize;
i++) {
117 *work_line = *in_lines_cur[0]++ * coef[0];
118 *work_line++ += *in_lines_cur[1]++ * coef[1];
124 const int16_t *coef,
int linesize)
128 for (
i = 0;
i < linesize;
i++) {
129 *work_line = *in_lines_cur[0]++ * coef[0];
130 *work_line += *in_lines_cur[1]++ * coef[1];
131 *work_line += *in_lines_cur[2]++ * coef[2];
132 *work_line++ += *in_lines_cur[3]++ * coef[3];
139 const int16_t *coef,
int linesize)
143 for (
i = 0;
i < linesize;
i++) {
144 *work_line += *in_lines_cur[0]++ * coef[0];
145 *work_line += *in_lines_adj[0]++ * coef[0];
146 *work_line += *in_lines_cur[1]++ * coef[1];
147 *work_line += *in_lines_adj[1]++ * coef[1];
148 *work_line += *in_lines_cur[2]++ * coef[2];
149 *work_line++ += *in_lines_adj[2]++ * coef[2];
156 const int16_t *coef,
int linesize)
160 for (
i = 0;
i < linesize;
i++) {
161 *work_line += *in_lines_cur[0]++ * coef[0];
162 *work_line += *in_lines_adj[0]++ * coef[0];
163 *work_line += *in_lines_cur[1]++ * coef[1];
164 *work_line += *in_lines_adj[1]++ * coef[1];
165 *work_line += *in_lines_cur[2]++ * coef[2];
166 *work_line += *in_lines_adj[2]++ * coef[2];
167 *work_line += *in_lines_cur[3]++ * coef[3];
168 *work_line += *in_lines_adj[3]++ * coef[3];
169 *work_line += *in_lines_cur[4]++ * coef[4];
170 *work_line++ += *in_lines_adj[4]++ * coef[4];
178 for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
179 *out_pixel =
av_clip(*work_pixel, 0, 255 * 256 * 128) >> 15;
184 const int16_t *coef,
int linesize)
186 uint16_t *in_lines_cur[2] = { (uint16_t *)in_lines_cur8[0], (uint16_t *)in_lines_cur8[1] };
190 for (
i = 0;
i < linesize;
i++) {
191 *work_line = *in_lines_cur[0]++ * coef[0];
192 *work_line++ += *in_lines_cur[1]++ * coef[1];
198 const int16_t *coef,
int linesize)
200 uint16_t *in_lines_cur[4] = { (uint16_t *)in_lines_cur8[0],
201 (uint16_t *)in_lines_cur8[1],
202 (uint16_t *)in_lines_cur8[2],
203 (uint16_t *)in_lines_cur8[3] };
207 for (
i = 0;
i < linesize;
i++) {
208 *work_line = *in_lines_cur[0]++ * coef[0];
209 *work_line += *in_lines_cur[1]++ * coef[1];
210 *work_line += *in_lines_cur[2]++ * coef[2];
211 *work_line++ += *in_lines_cur[3]++ * coef[3];
218 const int16_t *coef,
int linesize)
220 uint16_t *in_lines_cur[3] = { (uint16_t *)in_lines_cur8[0],
221 (uint16_t *)in_lines_cur8[1],
222 (uint16_t *)in_lines_cur8[2] };
223 uint16_t *in_lines_adj[3] = { (uint16_t *)in_lines_adj8[0],
224 (uint16_t *)in_lines_adj8[1],
225 (uint16_t *)in_lines_adj8[2] };
229 for (
i = 0;
i < linesize;
i++) {
230 *work_line += *in_lines_cur[0]++ * coef[0];
231 *work_line += *in_lines_adj[0]++ * coef[0];
232 *work_line += *in_lines_cur[1]++ * coef[1];
233 *work_line += *in_lines_adj[1]++ * coef[1];
234 *work_line += *in_lines_cur[2]++ * coef[2];
235 *work_line++ += *in_lines_adj[2]++ * coef[2];
242 const int16_t *coef,
int linesize)
244 uint16_t *in_lines_cur[5] = { (uint16_t *)in_lines_cur8[0],
245 (uint16_t *)in_lines_cur8[1],
246 (uint16_t *)in_lines_cur8[2],
247 (uint16_t *)in_lines_cur8[3],
248 (uint16_t *)in_lines_cur8[4] };
249 uint16_t *in_lines_adj[5] = { (uint16_t *)in_lines_adj8[0],
250 (uint16_t *)in_lines_adj8[1],
251 (uint16_t *)in_lines_adj8[2],
252 (uint16_t *)in_lines_adj8[3],
253 (uint16_t *)in_lines_adj8[4] };
257 for (
i = 0;
i < linesize;
i++) {
258 *work_line += *in_lines_cur[0]++ * coef[0];
259 *work_line += *in_lines_adj[0]++ * coef[0];
260 *work_line += *in_lines_cur[1]++ * coef[1];
261 *work_line += *in_lines_adj[1]++ * coef[1];
262 *work_line += *in_lines_cur[2]++ * coef[2];
263 *work_line += *in_lines_adj[2]++ * coef[2];
264 *work_line += *in_lines_cur[3]++ * coef[3];
265 *work_line += *in_lines_adj[3]++ * coef[3];
266 *work_line += *in_lines_cur[4]++ * coef[4];
267 *work_line++ += *in_lines_adj[4]++ * coef[4];
273 uint16_t *out_pixel = (uint16_t *)out_pixel8;
277 for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
278 *out_pixel =
av_clip(*work_pixel, 0,
max) >> 15;
286 int ret,
i, depth, nb_threads;
292 s->planeheight[0] =
s->planeheight[3] = inlink->
h;
301 s->work_line =
av_calloc(nb_threads,
sizeof(*
s->work_line));
304 s->nb_threads = nb_threads;
306 for (
i = 0;
i <
s->nb_threads;
i++) {
308 if (!
s->work_line[
i])
312 depth =
desc->comp[0].depth;
313 s->max = ((1 << depth) - 1) * 256 * 128;
355 static const int16_t
coef_lf[2][4] = {{ 16384, 16384, 0, 0},
356 { -852, 17236, 17236, -852}};
358 static const int16_t
coef_hf[2][5] = {{ -2048, 4096, -2048, 0, 0},
359 { 1016, -3801, 5570, -3801, 1016}};
366 int jobnr,
int nb_jobs,
int plane)
374 uint8_t *in_line, *in_lines_cur[5], *in_lines_adj[5];
376 int32_t *work_line, *work_pixel;
380 const int linesize =
s->linesize[plane];
381 const int height =
s->planeheight[plane];
382 const int cur_line_stride = cur->
linesize[plane];
383 const int adj_line_stride = adj->
linesize[plane];
384 const int dst_line_stride =
out->linesize[plane];
385 const int start = (
height * jobnr) / nb_jobs;
386 const int end = (
height * (jobnr+1)) / nb_jobs;
387 const int max =
s->max;
394 y_out = start + (tff ^ (start & 1));
396 in_line = cur_data + (y_out * cur_line_stride);
397 out_line = dst_data + (y_out * dst_line_stride);
399 while (y_out < end) {
400 memcpy(out_line, in_line, linesize);
402 in_line += cur_line_stride * 2;
403 out_line += dst_line_stride * 2;
407 y_out = start + ((!tff) ^ (start & 1));
409 out_line = dst_data + (y_out * dst_line_stride);
411 while (y_out < end) {
421 in_lines_cur[j] = cur_data + (y_in * cur_line_stride);
424 work_line =
s->work_line[jobnr];
427 s->dsp.filter_simple_low(work_line, in_lines_cur,
431 s->dsp.filter_complex_low(work_line, in_lines_cur,
444 in_lines_cur[j] = cur_data + (y_in * cur_line_stride);
445 in_lines_adj[j] = adj_data + (y_in * adj_line_stride);
448 work_line =
s->work_line[jobnr];
451 s->dsp.filter_simple_high(work_line, in_lines_cur, in_lines_adj,
455 s->dsp.filter_complex_high(work_line, in_lines_cur, in_lines_adj,
460 work_pixel =
s->work_line[jobnr];
461 out_pixel = out_line;
463 s->dsp.filter_scale(out_pixel, work_pixel, linesize,
max);
467 out_line += dst_line_stride * 2;
474 int jobnr,
int nb_jobs)
478 for (
int p = 0; p <
s->nb_planes; p++)
495 out->interlaced_frame = 0;
501 int64_t cur_pts =
s->cur->pts;
502 int64_t next_pts =
s->next->pts;
505 out->pts = cur_pts + next_pts;
511 adj =
s->field ?
s->next :
s->prev;
516 s->field = !
s->field;
538 if ((
s->deint && !
s->cur->interlaced_frame) ||
ctx->is_disabled) {
553 if (ret < 0 || s->
mode == 0)
574 next->
pts =
s->next->pts * 2 -
s->cur->pts;
577 }
else if (ret < 0) {
593 for (
i = 0;
i <
s->nb_threads;
i++)
623 .priv_class = &w3fdif_class,
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next 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.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
#define flags(name, subs,...)
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
mode
Use these values in ebur128_init (or'ed).
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
#define AVERROR_EOF
End of file.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
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_NOPTS_VALUE
Undefined timestamp value.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUV420P14
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
Describe the class of an AVClass context structure.
AVFilterLink ** inputs
array of pointers to input links
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int top_field_first
If the content is interlaced, is top field displayed first.
int interlaced_frame
The content of the picture is interlaced.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Used for passing data between threads.
int deint
which frames to deinterlace
int32_t ** work_line
lines we are calculating
int linesize[4]
bytes of pixel data per line for each plane
int mode
0 is frame, 1 is field
int parity
frame field parity
AVFrame * next
previous, current, next frames
int planeheight[4]
height of each plane
int filter
0 is simple, 1 is more complex
int field
which field are we on, 0 or 1
static int deinterlace_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
AVFILTER_DEFINE_CLASS(w3fdif)
static void filter_complex_low(int32_t *work_line, uint8_t *in_lines_cur[4], const int16_t *coef, int linesize)
static int deinterlace_plane_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs, int plane)
static const int8_t n_coef_hf[2]
static const int8_t n_coef_lf[2]
static const int16_t coef_lf[2][4]
#define CONST(name, help, val, unit)
static int query_formats(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
static const AVOption w3fdif_options[]
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
static void filter16_simple_high(int32_t *work_line, uint8_t *in_lines_cur8[3], uint8_t *in_lines_adj8[3], const int16_t *coef, int linesize)
static int request_frame(AVFilterLink *outlink)
static const AVFilterPad w3fdif_inputs[]
static void filter_scale(uint8_t *out_pixel, const int32_t *work_pixel, int linesize, int max)
static const AVFilterPad w3fdif_outputs[]
static int filter(AVFilterContext *ctx, int is_second)
static void filter_simple_high(int32_t *work_line, uint8_t *in_lines_cur[3], uint8_t *in_lines_adj[3], const int16_t *coef, int linesize)
static void filter16_scale(uint8_t *out_pixel8, const int32_t *work_pixel, int linesize, int max)
static void filter16_simple_low(int32_t *work_line, uint8_t *in_lines_cur8[2], const int16_t *coef, int linesize)
static void filter16_complex_high(int32_t *work_line, uint8_t *in_lines_cur8[5], uint8_t *in_lines_adj8[5], const int16_t *coef, int linesize)
static av_cold void uninit(AVFilterContext *ctx)
static void filter16_complex_low(int32_t *work_line, uint8_t *in_lines_cur8[4], const int16_t *coef, int linesize)
static void filter_complex_high(int32_t *work_line, uint8_t *in_lines_cur[5], uint8_t *in_lines_adj[5], const int16_t *coef, int linesize)
static const int16_t coef_hf[2][5]
static int config_output(AVFilterLink *outlink)
static void filter_simple_low(int32_t *work_line, uint8_t *in_lines_cur[2], const int16_t *coef, int linesize)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
void ff_w3fdif_init_x86(W3FDIFDSPContext *dsp, int depth)