FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_framerate.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Mark Himsley
3  *
4  * get_scene_score() Copyright (c) 2011 Stefano Sabatini
5  * taken from libavfilter/vf_select.c
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 /**
25  * @file
26  * filter for upsampling or downsampling a progressive source
27  */
28 
29 #define DEBUG
30 
31 #include "libavutil/avassert.h"
32 #include "libavutil/imgutils.h"
33 #include "libavutil/internal.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/pixdesc.h"
36 #include "libavutil/pixelutils.h"
37 
38 #include "avfilter.h"
39 #include "internal.h"
40 #include "video.h"
41 
42 #define N_SRCE 3
43 
44 typedef struct FrameRateContext {
45  const AVClass *class;
46  // parameters
47  AVRational dest_frame_rate; ///< output frames per second
48  int flags; ///< flags affecting frame rate conversion algorithm
49  double scene_score; ///< score that denotes a scene change has happened
50  int interp_start; ///< start of range to apply linear interpolation
51  int interp_end; ///< end of range to apply linear interpolation
52 
53  int line_size[4]; ///< bytes of pixel data per line for each plane
54  int vsub;
55 
56  int frst, next, prev, crnt, last;
57  int pending_srce_frames; ///< how many input frames are still waiting to be processed
58  int flush; ///< are we flushing final frames
59  int pending_end_frame; ///< flag indicating we are waiting to call filter_frame()
60 
61  AVRational srce_time_base; ///< timebase of source
62 
63  AVRational dest_time_base; ///< timebase of destination
65  int64_t last_dest_frame_pts; ///< pts of the last frame output
66  int64_t average_srce_pts_dest_delta;///< average input pts delta converted from input rate to output rate
67  int64_t average_dest_pts_delta; ///< calculated average output pts delta
68 
69  av_pixelutils_sad_fn sad; ///< Sum of the absolute difference function (scene detect only)
70  double prev_mafd; ///< previous MAFD (scene detect only)
71 
72  AVFrame *srce[N_SRCE]; ///< buffered source frames
73  int64_t srce_pts_dest[N_SRCE]; ///< pts for source frames scaled to output timebase
74  int64_t pts; ///< pts of frame we are working on
76 
77 #define OFFSET(x) offsetof(FrameRateContext, x)
78 #define V AV_OPT_FLAG_VIDEO_PARAM
79 #define F AV_OPT_FLAG_FILTERING_PARAM
80 #define FRAMERATE_FLAG_SCD 01
81 
82 static const AVOption framerate_options[] = {
83  {"fps", "required output frames per second rate", OFFSET(dest_frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="50"}, 0, INT_MAX, V|F },
84 
85  {"interp_start", "point to start linear interpolation", OFFSET(interp_start), AV_OPT_TYPE_INT, {.i64=15}, 0, 255, V|F },
86  {"interp_end", "point to end linear interpolation", OFFSET(interp_end), AV_OPT_TYPE_INT, {.i64=240}, 0, 255, V|F },
87  {"scene", "scene change level", OFFSET(scene_score), AV_OPT_TYPE_DOUBLE, {.dbl=7.0}, 0, INT_MAX, V|F },
88 
89  {"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, INT_MAX, V|F, "flags" },
90  {"scene_change_detect", "enable scene change detection", 0, AV_OPT_TYPE_CONST, {.i64=FRAMERATE_FLAG_SCD}, INT_MIN, INT_MAX, V|F, "flags" },
91  {"scd", "enable scene change detection", 0, AV_OPT_TYPE_CONST, {.i64=FRAMERATE_FLAG_SCD}, INT_MIN, INT_MAX, V|F, "flags" },
92 
93  {NULL}
94 };
95 
96 AVFILTER_DEFINE_CLASS(framerate);
97 
98 static void next_source(AVFilterContext *ctx)
99 {
100  FrameRateContext *s = ctx->priv;
101  int i;
102 
103  ff_dlog(ctx, "next_source()\n");
104 
105  if (s->srce[s->last] && s->srce[s->last] != s->srce[s->last-1]) {
106  ff_dlog(ctx, "next_source() unlink %d\n", s->last);
107  av_frame_free(&s->srce[s->last]);
108  }
109  for (i = s->last; i > s->frst; i--) {
110  ff_dlog(ctx, "next_source() copy %d to %d\n", i - 1, i);
111  s->srce[i] = s->srce[i - 1];
112  }
113  ff_dlog(ctx, "next_source() make %d null\n", s->frst);
114  s->srce[s->frst] = NULL;
115 }
116 
117 static double get_scene_score(AVFilterContext *ctx, AVFrame *crnt, AVFrame *next)
118 {
119  FrameRateContext *s = ctx->priv;
120  double ret = 0;
121 
122  ff_dlog(ctx, "get_scene_score()\n");
123 
124  if (crnt &&
125  crnt->height == next->height &&
126  crnt->width == next->width) {
127  int x, y;
128  int64_t sad;
129  double mafd, diff;
130  uint8_t *p1 = crnt->data[0];
131  uint8_t *p2 = next->data[0];
132  const int p1_linesize = crnt->linesize[0];
133  const int p2_linesize = next->linesize[0];
134 
135  ff_dlog(ctx, "get_scene_score() process\n");
136 
137  for (sad = y = 0; y < crnt->height; y += 8) {
138  for (x = 0; x < p1_linesize; x += 8) {
139  sad += s->sad(p1 + y * p1_linesize + x,
140  p1_linesize,
141  p2 + y * p2_linesize + x,
142  p2_linesize);
143  }
144  }
145  emms_c();
146  mafd = sad / (crnt->height * crnt->width * 3);
147  diff = fabs(mafd - s->prev_mafd);
148  ret = av_clipf(FFMIN(mafd, diff), 0, 100.0);
149  s->prev_mafd = mafd;
150  }
151  ff_dlog(ctx, "get_scene_score() result is:%f\n", ret);
152  return ret;
153 }
154 
155 static int process_work_frame(AVFilterContext *ctx, int stop)
156 {
157  FrameRateContext *s = ctx->priv;
158  AVFilterLink *outlink = ctx->outputs[0];
159  int64_t work_next_pts;
160  AVFrame *copy_src1, *copy_src2, *work;
161  int interpolate;
162 
163  ff_dlog(ctx, "process_work_frame()\n");
164 
165  ff_dlog(ctx, "process_work_frame() pending_input_frames %d\n", s->pending_srce_frames);
166 
167  if (s->srce[s->prev]) ff_dlog(ctx, "process_work_frame() srce prev pts:%"PRId64"\n", s->srce[s->prev]->pts);
168  if (s->srce[s->crnt]) ff_dlog(ctx, "process_work_frame() srce crnt pts:%"PRId64"\n", s->srce[s->crnt]->pts);
169  if (s->srce[s->next]) ff_dlog(ctx, "process_work_frame() srce next pts:%"PRId64"\n", s->srce[s->next]->pts);
170 
171  if (!s->srce[s->crnt]) {
172  // the filter cannot do anything
173  ff_dlog(ctx, "process_work_frame() no current frame cached: move on to next frame, do not output a frame\n");
174  next_source(ctx);
175  return 0;
176  }
177 
178  work_next_pts = s->pts + s->average_dest_pts_delta;
179 
180  ff_dlog(ctx, "process_work_frame() work crnt pts:%"PRId64"\n", s->pts);
181  ff_dlog(ctx, "process_work_frame() work next pts:%"PRId64"\n", work_next_pts);
182  if (s->srce[s->prev])
183  ff_dlog(ctx, "process_work_frame() srce prev pts:%"PRId64" at dest time base:%u/%u\n",
185  if (s->srce[s->crnt])
186  ff_dlog(ctx, "process_work_frame() srce crnt pts:%"PRId64" at dest time base:%u/%u\n",
188  if (s->srce[s->next])
189  ff_dlog(ctx, "process_work_frame() srce next pts:%"PRId64" at dest time base:%u/%u\n",
191 
192  av_assert0(s->srce[s->next]);
193 
194  // should filter be skipping input frame (output frame rate is lower than input frame rate)
195  if (!s->flush && s->pts >= s->srce_pts_dest[s->next]) {
196  ff_dlog(ctx, "process_work_frame() work crnt pts >= srce next pts: SKIP FRAME, move on to next frame, do not output a frame\n");
197  next_source(ctx);
198  s->pending_srce_frames--;
199  return 0;
200  }
201 
202  // calculate interpolation
203  interpolate = (int) ((s->pts - s->srce_pts_dest[s->crnt]) * 256.0 / s->average_srce_pts_dest_delta);
204  ff_dlog(ctx, "process_work_frame() interpolate:%d/256\n", interpolate);
205  copy_src1 = s->srce[s->crnt];
206  if (interpolate > s->interp_end) {
207  ff_dlog(ctx, "process_work_frame() source is:NEXT\n");
208  copy_src1 = s->srce[s->next];
209  }
210  if (s->srce[s->prev] && interpolate < -s->interp_end) {
211  ff_dlog(ctx, "process_work_frame() source is:PREV\n");
212  copy_src1 = s->srce[s->prev];
213  }
214 
215  // decide whether to blend two frames
216  if ((interpolate >= s->interp_start && interpolate <= s->interp_end) || (interpolate <= -s->interp_start && interpolate >= -s->interp_end)) {
217  double interpolate_scene_score = 0;
218 
219  if (interpolate > 0) {
220  ff_dlog(ctx, "process_work_frame() interpolate source is:NEXT\n");
221  copy_src2 = s->srce[s->next];
222  } else {
223  ff_dlog(ctx, "process_work_frame() interpolate source is:PREV\n");
224  copy_src2 = s->srce[s->prev];
225  }
226  if ((s->flags & FRAMERATE_FLAG_SCD) && copy_src2) {
227  interpolate_scene_score = get_scene_score(ctx, copy_src1, copy_src2);
228  ff_dlog(ctx, "process_work_frame() interpolate scene score:%f\n", interpolate_scene_score);
229  }
230  // decide if the shot-change detection allows us to blend two frames
231  if (interpolate_scene_score < s->scene_score && copy_src2) {
232  uint16_t src2_factor = abs(interpolate);
233  uint16_t src1_factor = 256 - src2_factor;
234  int plane, line, pixel;
235 
236  // get work-space for output frame
237  work = ff_get_video_buffer(outlink, outlink->w, outlink->h);
238  if (!work)
239  return AVERROR(ENOMEM);
240 
241  av_frame_copy_props(work, s->srce[s->crnt]);
242 
243  ff_dlog(ctx, "process_work_frame() INTERPOLATE to create work frame\n");
244  for (plane = 0; plane < 4 && copy_src1->data[plane] && copy_src2->data[plane]; plane++) {
245  int cpy_line_width = s->line_size[plane];
246  uint8_t *cpy_src1_data = copy_src1->data[plane];
247  int cpy_src1_line_size = copy_src1->linesize[plane];
248  uint8_t *cpy_src2_data = copy_src2->data[plane];
249  int cpy_src2_line_size = copy_src2->linesize[plane];
250  int cpy_src_h = (plane > 0 && plane < 3) ? (copy_src1->height >> s->vsub) : (copy_src1->height);
251  uint8_t *cpy_dst_data = work->data[plane];
252  int cpy_dst_line_size = work->linesize[plane];
253  if (plane <1 || plane >2) {
254  // luma or alpha
255  for (line = 0; line < cpy_src_h; line++) {
256  for (pixel = 0; pixel < cpy_line_width; pixel++) {
257  // integer version of (src1 * src1_factor) + (src2 + src2_factor) + 0.5
258  // 0.5 is for rounding
259  // 128 is the integer representation of 0.5 << 8
260  cpy_dst_data[pixel] = ((cpy_src1_data[pixel] * src1_factor) + (cpy_src2_data[pixel] * src2_factor) + 128) >> 8;
261  }
262  cpy_src1_data += cpy_src1_line_size;
263  cpy_src2_data += cpy_src2_line_size;
264  cpy_dst_data += cpy_dst_line_size;
265  }
266  } else {
267  // chroma
268  for (line = 0; line < cpy_src_h; line++) {
269  for (pixel = 0; pixel < cpy_line_width; pixel++) {
270  // as above
271  // because U and V are based around 128 we have to subtract 128 from the components.
272  // 32896 is the integer representation of 128.5 << 8
273  cpy_dst_data[pixel] = (((cpy_src1_data[pixel] - 128) * src1_factor) + ((cpy_src2_data[pixel] - 128) * src2_factor) + 32896) >> 8;
274  }
275  cpy_src1_data += cpy_src1_line_size;
276  cpy_src2_data += cpy_src2_line_size;
277  cpy_dst_data += cpy_dst_line_size;
278  }
279  }
280  }
281  goto copy_done;
282  }
283  else {
284  ff_dlog(ctx, "process_work_frame() CUT - DON'T INTERPOLATE\n");
285  }
286  }
287 
288  ff_dlog(ctx, "process_work_frame() COPY to the work frame\n");
289  // copy the frame we decided is our base source
290  work = av_frame_clone(copy_src1);
291  if (!work)
292  return AVERROR(ENOMEM);
293 
294 copy_done:
295  work->pts = s->pts;
296 
297  // should filter be re-using input frame (output frame rate is higher than input frame rate)
298  if (!s->flush && (work_next_pts + s->average_dest_pts_delta) < (s->srce_pts_dest[s->crnt] + s->average_srce_pts_dest_delta)) {
299  ff_dlog(ctx, "process_work_frame() REPEAT FRAME\n");
300  } else {
301  ff_dlog(ctx, "process_work_frame() CONSUME FRAME, move to next frame\n");
302  s->pending_srce_frames--;
303  next_source(ctx);
304  }
305  ff_dlog(ctx, "process_work_frame() output a frame\n");
306  s->dest_frame_num++;
307  if (stop)
308  s->pending_end_frame = 0;
309  s->last_dest_frame_pts = work->pts;
310 
311  return ff_filter_frame(ctx->outputs[0], work);
312 }
313 
315 {
316  FrameRateContext *s = ctx->priv;
317 
318  ff_dlog(ctx, "set_srce_frame_output_pts()\n");
319 
320  // scale the input pts from the timebase difference between input and output
321  if (s->srce[s->prev])
323  if (s->srce[s->crnt])
325  if (s->srce[s->next])
327 }
328 
330 {
331  FrameRateContext *s = ctx->priv;
332  int64_t pts, average_srce_pts_delta = 0;
333 
334  ff_dlog(ctx, "set_work_frame_pts()\n");
335 
336  av_assert0(s->srce[s->next]);
337  av_assert0(s->srce[s->crnt]);
338 
339  ff_dlog(ctx, "set_work_frame_pts() srce crnt pts:%"PRId64"\n", s->srce[s->crnt]->pts);
340  ff_dlog(ctx, "set_work_frame_pts() srce next pts:%"PRId64"\n", s->srce[s->next]->pts);
341  if (s->srce[s->prev])
342  ff_dlog(ctx, "set_work_frame_pts() srce prev pts:%"PRId64"\n", s->srce[s->prev]->pts);
343 
344  average_srce_pts_delta = s->average_srce_pts_dest_delta;
345  ff_dlog(ctx, "set_work_frame_pts() initial average srce pts:%"PRId64"\n", average_srce_pts_delta);
346 
347  // calculate the PTS delta
348  if ((pts = (s->srce[s->next]->pts - s->srce[s->crnt]->pts))) {
349  average_srce_pts_delta = average_srce_pts_delta?((average_srce_pts_delta+pts)>>1):pts;
350  } else if (s->srce[s->prev] && (pts = (s->srce[s->crnt]->pts - s->srce[s->prev]->pts))) {
351  average_srce_pts_delta = average_srce_pts_delta?((average_srce_pts_delta+pts)>>1):pts;
352  }
353 
354  s->average_srce_pts_dest_delta = av_rescale_q(average_srce_pts_delta, s->srce_time_base, s->dest_time_base);
355  ff_dlog(ctx, "set_work_frame_pts() average srce pts:%"PRId64"\n", average_srce_pts_delta);
356  ff_dlog(ctx, "set_work_frame_pts() average srce pts:%"PRId64" at dest time base:%u/%u\n",
358 
360 
361  if (ctx->inputs[0] && !s->average_dest_pts_delta) {
362  int64_t d = av_q2d(av_inv_q(av_mul_q(s->srce_time_base, s->dest_frame_rate)));
363  if (d == 0) { // FIXME
364  av_log(ctx, AV_LOG_WARNING, "Buggy path reached, use settb filter before this filter!\n");
365  d = av_q2d(av_mul_q(ctx->inputs[0]->time_base, s->dest_frame_rate));
366  }
368  ff_dlog(ctx, "set_frame_pts() average output pts from input timebase\n");
369  ff_dlog(ctx, "set_work_frame_pts() average dest pts delta:%"PRId64"\n", s->average_dest_pts_delta);
370  }
371 
372  if (!s->dest_frame_num) {
373  s->pts = s->last_dest_frame_pts = s->srce_pts_dest[s->crnt];
374  } else {
376  }
377 
378  ff_dlog(ctx, "set_work_frame_pts() calculated pts:%"PRId64" at dest time base:%u/%u\n",
380 }
381 
382 static av_cold int init(AVFilterContext *ctx)
383 {
384  FrameRateContext *s = ctx->priv;
385 
386  s->dest_frame_num = 0;
387 
388  s->crnt = (N_SRCE)>>1;
389  s->last = N_SRCE - 1;
390 
391  s->next = s->crnt - 1;
392  s->prev = s->crnt + 1;
393 
394  return 0;
395 }
396 
397 static av_cold void uninit(AVFilterContext *ctx)
398 {
399  FrameRateContext *s = ctx->priv;
400  int i;
401 
402  for (i = s->frst + 1; i > s->last; i++) {
403  if (s->srce[i] && (s->srce[i] != s->srce[i + 1]))
404  av_frame_free(&s->srce[i]);
405  }
406  av_frame_free(&s->srce[s->last]);
407 }
408 
410 {
411  static const enum AVPixelFormat pix_fmts[] = {
419  };
420 
421  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
422  if (!fmts_list)
423  return AVERROR(ENOMEM);
424  return ff_set_common_formats(ctx, fmts_list);
425 }
426 
427 static int config_input(AVFilterLink *inlink)
428 {
429  AVFilterContext *ctx = inlink->dst;
430  FrameRateContext *s = ctx->priv;
431  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
432  int plane;
433 
434  for (plane = 0; plane < 4; plane++) {
435  s->line_size[plane] = av_image_get_linesize(inlink->format, inlink->w,
436  plane);
437  }
438 
439  s->vsub = pix_desc->log2_chroma_h;
440 
441  s->sad = av_pixelutils_get_sad_fn(3, 3, 2, s); // 8x8 both sources aligned
442  if (!s->sad)
443  return AVERROR(EINVAL);
444 
445  s->srce_time_base = inlink->time_base;
446 
447  return 0;
448 }
449 
450 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
451 {
452  AVFilterContext *ctx = inlink->dst;
453  FrameRateContext *s = ctx->priv;
454 
455  // we have one new frame
456  s->pending_srce_frames++;
457 
458  if (inpicref->interlaced_frame)
459  av_log(ctx, AV_LOG_WARNING, "Interlaced frame found - the output will not be correct.\n");
460 
461  // store the pointer to the new frame
462  av_frame_free(&s->srce[s->frst]);
463  s->srce[s->frst] = inpicref;
464 
465  if (!s->pending_end_frame && s->srce[s->crnt]) {
466  set_work_frame_pts(ctx);
467  s->pending_end_frame = 1;
468  } else {
470  }
471 
472  return process_work_frame(ctx, 1);
473 }
474 
475 static int config_output(AVFilterLink *outlink)
476 {
477  AVFilterContext *ctx = outlink->src;
478  FrameRateContext *s = ctx->priv;
479  int exact;
480 
481  ff_dlog(ctx, "config_output()\n");
482 
483  ff_dlog(ctx,
484  "config_output() input time base:%u/%u (%f)\n",
485  ctx->inputs[0]->time_base.num,ctx->inputs[0]->time_base.den,
486  av_q2d(ctx->inputs[0]->time_base));
487 
488  // make sure timebase is small enough to hold the framerate
489 
490  exact = av_reduce(&s->dest_time_base.num, &s->dest_time_base.den,
491  av_gcd((int64_t)s->srce_time_base.num * s->dest_frame_rate.num,
492  (int64_t)s->srce_time_base.den * s->dest_frame_rate.den ),
493  (int64_t)s->srce_time_base.den * s->dest_frame_rate.num, INT_MAX);
494 
495  av_log(ctx, AV_LOG_INFO,
496  "time base:%u/%u -> %u/%u exact:%d\n",
498  s->dest_time_base.num, s->dest_time_base.den, exact);
499  if (!exact) {
500  av_log(ctx, AV_LOG_WARNING, "Timebase conversion is not exact\n");
501  }
502 
503  outlink->frame_rate = s->dest_frame_rate;
504  outlink->time_base = s->dest_time_base;
505  outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
506 
507  ff_dlog(ctx,
508  "config_output() output time base:%u/%u (%f) w:%d h:%d\n",
509  outlink->time_base.num, outlink->time_base.den,
510  av_q2d(outlink->time_base),
511  outlink->w, outlink->h);
512 
513 
514  av_log(ctx, AV_LOG_INFO, "fps -> fps:%u/%u scene score:%f interpolate start:%d end:%d\n",
516  s->scene_score, s->interp_start, s->interp_end);
517 
518  return 0;
519 }
520 
521 static int request_frame(AVFilterLink *outlink)
522 {
523  AVFilterContext *ctx = outlink->src;
524  FrameRateContext *s = ctx->priv;
525  int val, i;
526 
527  ff_dlog(ctx, "request_frame()\n");
528 
529  // if there is no "next" frame AND we are not in flush then get one from our input filter
530  if (!s->srce[s->frst] && !s->flush) {
531  ff_dlog(ctx, "request_frame() call source's request_frame()\n");
532  if ((val = ff_request_frame(outlink->src->inputs[0])) < 0) {
533  ff_dlog(ctx, "request_frame() source's request_frame() returned error:%d\n", val);
534  return val;
535  }
536  ff_dlog(ctx, "request_frame() source's request_frame() returned:%d\n", val);
537  return 0;
538  }
539 
540  ff_dlog(ctx, "request_frame() REPEAT or FLUSH\n");
541 
542  if (s->pending_srce_frames <= 0) {
543  ff_dlog(ctx, "request_frame() nothing else to do, return:EOF\n");
544  return AVERROR_EOF;
545  }
546 
547  // otherwise, make brand-new frame and pass to our output filter
548  ff_dlog(ctx, "request_frame() FLUSH\n");
549 
550  // back fill at end of file when source has no more frames
551  for (i = s->last; i > s->frst; i--) {
552  if (!s->srce[i - 1] && s->srce[i]) {
553  ff_dlog(ctx, "request_frame() copy:%d to:%d\n", i, i - 1);
554  s->srce[i - 1] = s->srce[i];
555  }
556  }
557 
558  set_work_frame_pts(ctx);
559  return process_work_frame(ctx, 0);
560 }
561 
562 static const AVFilterPad framerate_inputs[] = {
563  {
564  .name = "default",
565  .type = AVMEDIA_TYPE_VIDEO,
566  .config_props = config_input,
567  .filter_frame = filter_frame,
568  },
569  { NULL }
570 };
571 
572 static const AVFilterPad framerate_outputs[] = {
573  {
574  .name = "default",
575  .type = AVMEDIA_TYPE_VIDEO,
576  .request_frame = request_frame,
577  .config_props = config_output,
578  },
579  { NULL }
580 };
581 
583  .name = "framerate",
584  .description = NULL_IF_CONFIG_SMALL("Upsamples or downsamples progressive source between specified frame rates."),
585  .priv_size = sizeof(FrameRateContext),
586  .priv_class = &framerate_class,
587  .init = init,
588  .uninit = uninit,
590  .inputs = framerate_inputs,
591  .outputs = framerate_outputs,
592 };
int plane
Definition: avisynth_c.h:291
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:634
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane...
Definition: imgutils.c:75
const char * s
Definition: avisynth_c.h:631
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2129
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_framerate.c:397
AVOption.
Definition: opt.h:255
double scene_score
score that denotes a scene change has happened
Definition: vf_framerate.c:49
#define N_SRCE
Definition: vf_framerate.c:42
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:68
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
Main libavfilter public API header.
static double get_scene_score(AVFilterContext *ctx, AVFrame *crnt, AVFrame *next)
Definition: vf_framerate.c:117
int num
numerator
Definition: rational.h:44
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
AVFILTER_DEFINE_CLASS(framerate)
int interp_end
end of range to apply linear interpolation
Definition: vf_framerate.c:51
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:69
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:641
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1158
uint8_t
#define av_cold
Definition: attributes.h:74
AVOptions.
AVFrame * srce[N_SRCE]
buffered source frames
Definition: vf_framerate.c:72
AVRational dest_frame_rate
output frames per second
Definition: vf_framerate.c:47
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:257
static void interpolate(float *out, float v1, float v2, int size)
Definition: twinvq.c:84
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:80
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:102
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:76
static int request_frame(AVFilterLink *outlink)
Definition: vf_framerate.c:521
#define ff_dlog(a,...)
#define AVERROR_EOF
End of file.
Definition: error.h:55
static void set_srce_frame_dest_pts(AVFilterContext *ctx)
Definition: vf_framerate.c:314
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:367
int flags
flags affecting frame rate conversion algorithm
Definition: vf_framerate.c:48
#define av_log(a,...)
int line_size[4]
bytes of pixel data per line for each plane
Definition: vf_framerate.c:53
A filter pad used for either input or output.
Definition: internal.h:63
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:140
int width
width and height of the video frame
Definition: frame.h:220
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:542
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
int interp_start
start of range to apply linear interpolation
Definition: vf_framerate.c:50
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
void * priv
private data for use by the filter
Definition: avfilter.h:654
int(* av_pixelutils_sad_fn)(const uint8_t *src1, ptrdiff_t stride1, const uint8_t *src2, ptrdiff_t stride2)
Sum of abs(src1[x] - src2[x])
Definition: pixelutils.h:29
Definition: graph2dot.c:48
simple assert() macros that are a bit more flexible than ISO C assert().
#define FRAMERATE_FLAG_SCD
Definition: vf_framerate.c:80
int64_t av_gcd(int64_t a, int64_t b)
Return the greatest common divisor of a and b.
Definition: mathematics.c:55
static void next_source(AVFilterContext *ctx)
Definition: vf_framerate.c:98
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
common internal API header
#define FFMIN(a, b)
Definition: common.h:81
float y
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:75
int32_t
double prev_mafd
previous MAFD (scene detect only)
Definition: vf_framerate.c:70
AVFilter ff_vf_framerate
Definition: vf_framerate.c:582
int64_t average_srce_pts_dest_delta
average input pts delta converted from input rate to output rate
Definition: vf_framerate.c:66
AVRational srce_time_base
timebase of source
Definition: vf_framerate.c:61
Frame requests may need to loop in order to be fulfilled.
Definition: internal.h:374
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:451
int64_t srce_pts_dest[N_SRCE]
pts for source frames scaled to output timebase
Definition: vf_framerate.c:73
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
static const AVFilterPad framerate_outputs[]
Definition: vf_framerate.c:572
static int query_formats(AVFilterContext *ctx)
Definition: vf_framerate.c:409
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
int pending_srce_frames
how many input frames are still waiting to be processed
Definition: vf_framerate.c:57
int64_t last_dest_frame_pts
pts of the last frame output
Definition: vf_framerate.c:65
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:69
av_pixelutils_sad_fn av_pixelutils_get_sad_fn(int w_bits, int h_bits, int aligned, void *log_ctx)
Get a potentially optimized pointer to a Sum-of-absolute-differences function (see the av_pixelutils_...
Definition: pixelutils.c:64
Describe the class of an AVClass context structure.
Definition: log.h:67
int pending_end_frame
flag indicating we are waiting to call filter_frame()
Definition: vf_framerate.c:59
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
rational number numerator/denominator
Definition: rational.h:43
AVRational dest_time_base
timebase of destination
Definition: vf_framerate.c:63
offset must point to AVRational
Definition: opt.h:235
const char * name
Filter name.
Definition: avfilter.h:474
static av_cold int init(AVFilterContext *ctx)
Definition: vf_framerate.c:382
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:209
uint8_t pixel
Definition: tiny_ssim.c:42
static int64_t pts
Global timestamp for the audio frames.
static int process_work_frame(AVFilterContext *ctx, int stop)
Definition: vf_framerate.c:155
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:133
static int flags
Definition: cpu.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
int32_t dest_frame_num
Definition: vf_framerate.c:64
static void set_work_frame_pts(AVFilterContext *ctx)
Definition: vf_framerate.c:329
#define F
Definition: vf_framerate.c:79
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
av_pixelutils_sad_fn sad
Sum of the absolute difference function (scene detect only)
Definition: vf_framerate.c:69
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:77
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:70
int den
denominator
Definition: rational.h:45
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
Definition: vf_framerate.c:450
#define V
Definition: vf_framerate.c:78
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static const AVOption framerate_options[]
Definition: vf_framerate.c:82
static int config_input(AVFilterLink *inlink)
Definition: vf_framerate.c:427
A list of supported formats for one end of a filter link.
Definition: formats.h:64
#define OFFSET(x)
Definition: vf_framerate.c:77
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:302
static const AVFilterPad framerate_inputs[]
Definition: vf_framerate.c:562
An instance of a filter.
Definition: avfilter.h:633
int height
Definition: frame.h:220
int flush
are we flushing final frames
Definition: vf_framerate.c:58
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:101
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:343
static int config_output(AVFilterLink *outlink)
Definition: vf_framerate.c:475
int64_t average_dest_pts_delta
calculated average output pts delta
Definition: vf_framerate.c:67
internal API functions
int64_t pts
pts of frame we are working on
Definition: vf_framerate.c:74
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:553