FFmpeg
vf_decimate.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Fredrik Mellbin
3  * Copyright (c) 2013 Clément Bœsch
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/opt.h"
23 #include "libavutil/pixdesc.h"
24 #include "libavutil/timestamp.h"
25 #include "avfilter.h"
26 #include "filters.h"
27 #include "internal.h"
28 
29 #define INPUT_MAIN 0
30 #define INPUT_CLEANSRC 1
31 
32 struct qitem {
34  int64_t maxbdiff;
35  int64_t totdiff;
36 };
37 
38 typedef struct DecimateContext {
39  const AVClass *class;
40  struct qitem *queue; ///< window of cycle frames and the associated data diff
41  int fid; ///< current frame id in the queue
42  int filled; ///< 1 if the queue is filled, 0 otherwise
43  AVFrame *last; ///< last frame from the previous queue
44  AVFrame **clean_src; ///< frame queue for the clean source
45  int got_frame[2]; ///< frame request flag for each input stream
46  int64_t last_pts; ///< last output timestamp
47  int64_t last_duration; ///< last output duration
48  int64_t start_pts; ///< base for output timestamps
49  uint32_t eof; ///< bitmask for end of stream
50  int hsub, vsub; ///< chroma subsampling values
51  int depth;
53  int bdiffsize;
54  int64_t *bdiffs;
55  AVRational in_tb; // input time-base
56  AVRational nondec_tb; // non-decimated time-base
57  AVRational dec_tb; // decimated time-base
58 
59  /* options */
60  int cycle;
61  double dupthresh_flt;
62  double scthresh_flt;
63  int64_t dupthresh;
64  int64_t scthresh;
65  int blockx, blocky;
66  int ppsrc;
67  int chroma;
68  int mixed;
70 
71 #define OFFSET(x) offsetof(DecimateContext, x)
72 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
73 
74 static const AVOption decimate_options[] = {
75  { "cycle", "set the number of frame from which one will be dropped", OFFSET(cycle), AV_OPT_TYPE_INT, {.i64 = 5}, 2, 25, FLAGS },
76  { "dupthresh", "set duplicate threshold", OFFSET(dupthresh_flt), AV_OPT_TYPE_DOUBLE, {.dbl = 1.1}, 0, 100, FLAGS },
77  { "scthresh", "set scene change threshold", OFFSET(scthresh_flt), AV_OPT_TYPE_DOUBLE, {.dbl = 15.0}, 0, 100, FLAGS },
78  { "blockx", "set the size of the x-axis blocks used during metric calculations", OFFSET(blockx), AV_OPT_TYPE_INT, {.i64 = 32}, 4, 1<<9, FLAGS },
79  { "blocky", "set the size of the y-axis blocks used during metric calculations", OFFSET(blocky), AV_OPT_TYPE_INT, {.i64 = 32}, 4, 1<<9, FLAGS },
80  { "ppsrc", "mark main input as a pre-processed input and activate clean source input stream", OFFSET(ppsrc), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
81  { "chroma", "set whether or not chroma is considered in the metric calculations", OFFSET(chroma), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
82  { "mixed", "set whether or not the input only partially contains content to be decimated", OFFSET(mixed), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
83  { NULL }
84 };
85 
86 AVFILTER_DEFINE_CLASS(decimate);
87 
88 static void calc_diffs(const DecimateContext *dm, struct qitem *q,
89  const AVFrame *f1, const AVFrame *f2)
90 {
91  int64_t maxdiff = -1;
92  int64_t *bdiffs = dm->bdiffs;
93  int plane, i, j;
94 
95  memset(bdiffs, 0, dm->bdiffsize * sizeof(*bdiffs));
96 
97  for (plane = 0; plane < (dm->chroma && f1->data[2] ? 3 : 1); plane++) {
98  int x, y, xl;
99  const int linesize1 = f1->linesize[plane];
100  const int linesize2 = f2->linesize[plane];
101  const uint8_t *f1p = f1->data[plane];
102  const uint8_t *f2p = f2->data[plane];
103  int width = plane ? AV_CEIL_RSHIFT(f1->width, dm->hsub) : f1->width;
104  int height = plane ? AV_CEIL_RSHIFT(f1->height, dm->vsub) : f1->height;
105  int hblockx = dm->blockx / 2;
106  int hblocky = dm->blocky / 2;
107 
108  if (plane) {
109  hblockx >>= dm->hsub;
110  hblocky >>= dm->vsub;
111  }
112 
113  for (y = 0; y < height; y++) {
114  int ydest = y / hblocky;
115  int xdest = 0;
116 
117 #define CALC_DIFF(nbits) do { \
118  for (x = 0; x < width; x += hblockx) { \
119  int64_t acc = 0; \
120  int m = FFMIN(width, x + hblockx); \
121  for (xl = x; xl < m; xl++) \
122  acc += abs(((const uint##nbits##_t *)f1p)[xl] - \
123  ((const uint##nbits##_t *)f2p)[xl]); \
124  bdiffs[ydest * dm->nxblocks + xdest] += acc; \
125  xdest++; \
126  } \
127 } while (0)
128  if (dm->depth == 8) CALC_DIFF(8);
129  else CALC_DIFF(16);
130 
131  f1p += linesize1;
132  f2p += linesize2;
133  }
134  }
135 
136  for (i = 0; i < dm->nyblocks - 1; i++) {
137  for (j = 0; j < dm->nxblocks - 1; j++) {
138  int64_t tmp = bdiffs[ i * dm->nxblocks + j ]
139  + bdiffs[ i * dm->nxblocks + j + 1]
140  + bdiffs[(i + 1) * dm->nxblocks + j ]
141  + bdiffs[(i + 1) * dm->nxblocks + j + 1];
142  if (tmp > maxdiff)
143  maxdiff = tmp;
144  }
145  }
146 
147  q->totdiff = 0;
148  for (i = 0; i < dm->bdiffsize; i++)
149  q->totdiff += bdiffs[i];
150  q->maxbdiff = maxdiff;
151 }
152 
154 {
155  int scpos = -1, duppos = -1;
156  int drop = INT_MIN, i, lowest = 0, ret;
157  AVFilterContext *ctx = inlink->dst;
158  AVFilterLink *outlink = ctx->outputs[0];
159  DecimateContext *dm = ctx->priv;
160  AVFrame *prv;
161 
162  /* update frames queue(s) */
163  if (FF_INLINK_IDX(inlink) == INPUT_MAIN) {
164  dm->queue[dm->fid].frame = in;
165  dm->got_frame[INPUT_MAIN] = 1;
166  } else {
167  dm->clean_src[dm->fid] = in;
168  dm->got_frame[INPUT_CLEANSRC] = 1;
169  }
170  if (!dm->got_frame[INPUT_MAIN] || (dm->ppsrc && !dm->got_frame[INPUT_CLEANSRC]))
171  return 0;
173 
174  if (dm->ppsrc)
175  in = dm->queue[dm->fid].frame;
176 
177  if (in) {
178  /* update frame metrics */
179  prv = dm->fid ? dm->queue[dm->fid - 1].frame : dm->last;
180  if (!prv) {
181  dm->queue[dm->fid].maxbdiff = INT64_MAX;
182  dm->queue[dm->fid].totdiff = INT64_MAX;
183  } else {
184  calc_diffs(dm, &dm->queue[dm->fid], prv, in);
185  }
186  if (++dm->fid != dm->cycle)
187  return 0;
188  av_frame_free(&dm->last);
189  dm->last = av_frame_clone(in);
190  dm->fid = 0;
191 
192  /* we have a complete cycle, select the frame to drop */
193  lowest = 0;
194  for (i = 0; i < dm->cycle; i++) {
195  if (dm->queue[i].totdiff > dm->scthresh)
196  scpos = i;
197  if (dm->queue[i].maxbdiff < dm->queue[lowest].maxbdiff)
198  lowest = i;
199  }
200  if (dm->queue[lowest].maxbdiff < dm->dupthresh)
201  duppos = lowest;
202 
203  if (dm->mixed && duppos < 0) {
204  drop = -1; // no drop if mixed content + no frame in cycle below threshold
205  } else {
206  drop = scpos >= 0 && duppos < 0 ? scpos : lowest;
207  }
208  }
209 
210  /* metrics debug */
211  if (av_log_get_level() >= AV_LOG_DEBUG) {
212  av_log(ctx, AV_LOG_DEBUG, "1/%d frame drop:\n", dm->cycle);
213  for (i = 0; i < dm->cycle && dm->queue[i].frame; i++) {
214  av_log(ctx, AV_LOG_DEBUG," #%d: totdiff=%08"PRIx64" maxbdiff=%08"PRIx64"%s%s%s%s\n",
215  i + 1, dm->queue[i].totdiff, dm->queue[i].maxbdiff,
216  i == scpos ? " sc" : "",
217  i == duppos ? " dup" : "",
218  i == lowest ? " lowest" : "",
219  i == drop ? " [DROP]" : "");
220  }
221  }
222 
223  /* push all frames except the drop */
224  ret = 0;
225  for (i = 0; i < dm->cycle && dm->queue[i].frame; i++) {
226  if (i == drop) {
227  if (dm->ppsrc)
228  av_frame_free(&dm->clean_src[i]);
229  av_frame_free(&dm->queue[i].frame);
230  } else {
231  AVFrame *frame = dm->queue[i].frame;
232  dm->queue[i].frame = NULL;
233  if (frame->pts != AV_NOPTS_VALUE && dm->start_pts == AV_NOPTS_VALUE)
234  dm->start_pts = av_rescale_q(frame->pts, dm->in_tb, outlink->time_base);
235 
236  if (dm->ppsrc) {
238  frame = dm->clean_src[i];
239  if (!frame)
240  continue;
241  dm->clean_src[i] = NULL;
242  }
243 
244  frame->pts = dm->last_duration ? dm->last_pts + dm->last_duration :
245  (dm->start_pts == AV_NOPTS_VALUE ? 0 : dm->start_pts);
246  frame->duration = dm->mixed ? av_div_q(drop < 0 ? dm->nondec_tb : dm->dec_tb, outlink->time_base).num : 1;
247  dm->last_duration = frame->duration;
248  dm->last_pts = frame->pts;
249  ret = ff_filter_frame(outlink, frame);
250  if (ret < 0)
251  break;
252  }
253  }
254 
255  return ret;
256 }
257 
259 {
260  DecimateContext *dm = ctx->priv;
261  AVFrame *frame = NULL;
262  int ret = 0, status;
263  int64_t pts;
264 
266 
267  if ((dm->got_frame[INPUT_MAIN] == 0) && !(dm->eof & (1 << INPUT_MAIN)) &&
268  (ret = ff_inlink_consume_frame(ctx->inputs[INPUT_MAIN], &frame)) > 0) {
269  ret = filter_frame(ctx->inputs[INPUT_MAIN], frame);
270  if (ret < 0)
271  return ret;
272  }
273  if (ret < 0)
274  return ret;
275  if (dm->ppsrc &&
276  (dm->got_frame[INPUT_CLEANSRC] == 0) && !(dm->eof & (1 << INPUT_CLEANSRC)) &&
277  (ret = ff_inlink_consume_frame(ctx->inputs[INPUT_CLEANSRC], &frame)) > 0) {
278  ret = filter_frame(ctx->inputs[INPUT_CLEANSRC], frame);
279  if (ret < 0)
280  return ret;
281  }
282  if (ret < 0) {
283  return ret;
284  } else if (dm->eof == ((1 << INPUT_MAIN) | (dm->ppsrc << INPUT_CLEANSRC))) {
285  ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, dm->last_pts);
286  return 0;
287  } else if (!(dm->eof & (1 << INPUT_MAIN)) && ff_inlink_acknowledge_status(ctx->inputs[INPUT_MAIN], &status, &pts)) {
288  if (status == AVERROR_EOF) { // flushing
289  dm->eof |= 1 << INPUT_MAIN;
290  if (dm->ppsrc)
291  filter_frame(ctx->inputs[INPUT_CLEANSRC], NULL);
292  filter_frame(ctx->inputs[INPUT_MAIN], NULL);
293  ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, dm->last_pts);
294  return 0;
295  }
296  } else if (dm->ppsrc && !(dm->eof & (1 << INPUT_CLEANSRC)) && ff_inlink_acknowledge_status(ctx->inputs[INPUT_CLEANSRC], &status, &pts)) {
297  if (status == AVERROR_EOF) { // flushing
298  dm->eof |= 1 << INPUT_CLEANSRC;
299  filter_frame(ctx->inputs[INPUT_MAIN], NULL);
300  filter_frame(ctx->inputs[INPUT_CLEANSRC], NULL);
301  ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, dm->last_pts);
302  return 0;
303  }
304  }
305 
306  if (ff_inlink_queued_frames(ctx->inputs[INPUT_MAIN]) > 0 && (!dm->ppsrc ||
307  (dm->ppsrc && ff_inlink_queued_frames(ctx->inputs[INPUT_CLEANSRC]) > 0))) {
308  ff_filter_set_ready(ctx, 100);
309  } else if (ff_outlink_frame_wanted(ctx->outputs[0])) {
310  if (dm->got_frame[INPUT_MAIN] == 0)
312  if (dm->ppsrc && (dm->got_frame[INPUT_CLEANSRC] == 0))
314  }
315  return 0;
316 }
317 
319 {
320  DecimateContext *dm = ctx->priv;
321  AVFilterPad pad = {
322  .name = "main",
323  .type = AVMEDIA_TYPE_VIDEO,
324  };
325  int ret;
326 
327  if ((ret = ff_append_inpad(ctx, &pad)) < 0)
328  return ret;
329 
330  if (dm->ppsrc) {
331  pad.name = "clean_src";
332  pad.config_props = NULL;
333  if ((ret = ff_append_inpad(ctx, &pad)) < 0)
334  return ret;
335  }
336 
337  if ((dm->blockx & (dm->blockx - 1)) ||
338  (dm->blocky & (dm->blocky - 1))) {
339  av_log(ctx, AV_LOG_ERROR, "blockx and blocky settings must be power of two\n");
340  return AVERROR(EINVAL);
341  }
342 
344  dm->last_duration = 0;
345 
346  return 0;
347 }
348 
350 {
351  int i;
352  DecimateContext *dm = ctx->priv;
353 
354  av_frame_free(&dm->last);
355  av_freep(&dm->bdiffs);
356  if (dm->queue) {
357  for (i = 0; i < dm->cycle; i++)
358  av_frame_free(&dm->queue[i].frame);
359  }
360  av_freep(&dm->queue);
361  if (dm->clean_src) {
362  for (i = 0; i < dm->cycle; i++)
363  av_frame_free(&dm->clean_src[i]);
364  }
365  av_freep(&dm->clean_src);
366 }
367 
368 static const enum AVPixelFormat pix_fmts[] = {
369 #define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
370 #define PF_ALPHA(suf) AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
371 #define PF(suf) PF_NOALPHA(suf), PF_ALPHA(suf)
372  PF(P), PF(P9), PF(P10), PF_NOALPHA(P12), PF_NOALPHA(P14), PF(P16),
380 };
381 
382 static int config_output(AVFilterLink *outlink)
383 {
384  AVFilterContext *ctx = outlink->src;
385  DecimateContext *dm = ctx->priv;
386  const AVFilterLink *inlink = ctx->inputs[INPUT_MAIN];
387  AVRational fps = inlink->frame_rate;
388  int max_value;
389  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
390  const int w = inlink->w;
391  const int h = inlink->h;
392 
393  dm->hsub = pix_desc->log2_chroma_w;
394  dm->vsub = pix_desc->log2_chroma_h;
395  dm->depth = pix_desc->comp[0].depth;
396  max_value = (1 << dm->depth) - 1;
397  dm->scthresh = (int64_t)(((int64_t)max_value * w * h * dm->scthresh_flt) / 100);
398  dm->dupthresh = (int64_t)(((int64_t)max_value * dm->blockx * dm->blocky * dm->dupthresh_flt) / 100);
399  dm->nxblocks = (w + dm->blockx/2 - 1) / (dm->blockx/2);
400  dm->nyblocks = (h + dm->blocky/2 - 1) / (dm->blocky/2);
401  dm->bdiffsize = dm->nxblocks * dm->nyblocks;
402  dm->bdiffs = av_malloc_array(dm->bdiffsize, sizeof(*dm->bdiffs));
403  dm->queue = av_calloc(dm->cycle, sizeof(*dm->queue));
404  dm->in_tb = inlink->time_base;
405  dm->nondec_tb = av_inv_q(fps);
406  dm->dec_tb = av_mul_q(dm->nondec_tb, (AVRational){dm->cycle, dm->cycle - 1});
407 
408  if (!dm->bdiffs || !dm->queue)
409  return AVERROR(ENOMEM);
410 
411  if (dm->ppsrc) {
412  dm->clean_src = av_calloc(dm->cycle, sizeof(*dm->clean_src));
413  if (!dm->clean_src)
414  return AVERROR(ENOMEM);
415  }
416 
417  if (!fps.num || !fps.den) {
418  av_log(ctx, AV_LOG_ERROR, "The input needs a constant frame rate; "
419  "current rate of %d/%d is invalid\n", fps.num, fps.den);
420  return AVERROR(EINVAL);
421  }
422 
423  if (dm->mixed) {
424  outlink->time_base = av_gcd_q(dm->nondec_tb, dm->dec_tb, AV_TIME_BASE / 2, AV_TIME_BASE_Q);
425  av_log(ctx, AV_LOG_VERBOSE, "FPS: %d/%d -> VFR (use %d/%d if CFR required)\n",
426  fps.num, fps.den, outlink->time_base.den, outlink->time_base.num);
427  } else {
428  outlink->time_base = dm->dec_tb;
429  outlink->frame_rate = av_inv_q(outlink->time_base);
430  av_log(ctx, AV_LOG_VERBOSE, "FPS: %d/%d -> %d/%d\n",
431  fps.num, fps.den, outlink->frame_rate.num, outlink->frame_rate.den);
432  }
433  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
434  if (dm->ppsrc) {
435  outlink->w = ctx->inputs[INPUT_CLEANSRC]->w;
436  outlink->h = ctx->inputs[INPUT_CLEANSRC]->h;
437  } else {
438  outlink->w = inlink->w;
439  outlink->h = inlink->h;
440  }
441  return 0;
442 }
443 
444 static const AVFilterPad decimate_outputs[] = {
445  {
446  .name = "default",
447  .type = AVMEDIA_TYPE_VIDEO,
448  .config_props = config_output,
449  },
450 };
451 
453  .name = "decimate",
454  .description = NULL_IF_CONFIG_SMALL("Decimate frames (post field matching filter)."),
455  .init = decimate_init,
456  .activate = activate,
457  .uninit = decimate_uninit,
458  .priv_size = sizeof(DecimateContext),
461  .priv_class = &decimate_class,
463 };
PF
#define PF(suf)
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
status
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
AVERROR
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
opt.h
DecimateContext::start_pts
int64_t start_pts
base for output timestamps
Definition: vf_decimate.c:48
DecimateContext::in_tb
AVRational in_tb
Definition: vf_decimate.c:55
DecimateContext::depth
int depth
Definition: vf_decimate.c:51
DecimateContext::queue
struct qitem * queue
window of cycle frames and the associated data diff
Definition: vf_decimate.c:40
qitem
Definition: vf_decimate.c:32
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:969
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2888
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
av_div_q
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_decimate.c:368
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:174
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
inlink
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
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:99
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
pixdesc.h
AVFrame::width
int width
Definition: frame.h:402
w
uint8_t w
Definition: llviddspenc.c:38
AVComponentDescriptor::depth
int depth
Number of bits in the component.
Definition: pixdesc.h:57
AVOption
AVOption.
Definition: opt.h:251
chroma
static av_always_inline void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror, int jobnr, int nb_jobs)
Definition: vf_waveform.c:1635
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
DecimateContext::vsub
int vsub
chroma subsampling values
Definition: vf_decimate.c:50
DecimateContext::scthresh_flt
double scthresh_flt
Definition: vf_decimate.c:62
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
DecimateContext::got_frame
int got_frame[2]
frame request flag for each input stream
Definition: vf_decimate.c:45
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:165
PF_NOALPHA
#define PF_NOALPHA(suf)
DecimateContext::hsub
int hsub
Definition: vf_decimate.c:50
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:439
DecimateContext::blocky
int blocky
Definition: vf_decimate.c:65
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:351
qitem::frame
AVFrame * frame
Definition: vf_decimate.c:33
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_decimate.c:153
ff_inlink_consume_frame
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1364
FF_FILTER_FORWARD_STATUS_BACK_ALL
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
Definition: filters.h:212
ff_append_inpad
int ff_append_inpad(AVFilterContext *f, AVFilterPad *p)
Append a new input/output pad to the filter's list of such pads.
Definition: avfilter.c:126
pts
static int64_t pts
Definition: transcode_aac.c:653
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:443
AVFILTER_FLAG_DYNAMIC_INPUTS
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:106
activate
static int activate(AVFilterContext *ctx)
Definition: vf_decimate.c:258
AVRational::num
int num
Numerator.
Definition: rational.h:59
calc_diffs
static void calc_diffs(const DecimateContext *dm, struct qitem *q, const AVFrame *f1, const AVFrame *f2)
Definition: vf_decimate.c:88
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:276
DecimateContext::bdiffsize
int bdiffsize
Definition: vf_decimate.c:53
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:189
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1481
width
#define width
CALC_DIFF
#define CALC_DIFF(nbits)
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:50
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
filters.h
decimate_options
static const AVOption decimate_options[]
Definition: vf_decimate.c:74
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:442
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:465
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
OFFSET
#define OFFSET(x)
Definition: vf_decimate.c:71
AVPixFmtDescriptor::log2_chroma_w
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
DecimateContext::nondec_tb
AVRational nondec_tb
Definition: vf_decimate.c:56
DecimateContext::dupthresh
int64_t dupthresh
Definition: vf_decimate.c:63
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
DecimateContext::last_pts
int64_t last_pts
last output timestamp
Definition: vf_decimate.c:46
DecimateContext::nxblocks
int nxblocks
Definition: vf_decimate.c:52
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:440
DecimateContext::bdiffs
int64_t * bdiffs
Definition: vf_decimate.c:54
av_log_get_level
int av_log_get_level(void)
Get the current log level.
Definition: log.c:437
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
DecimateContext::ppsrc
int ppsrc
Definition: vf_decimate.c:66
INPUT_MAIN
#define INPUT_MAIN
Definition: vf_decimate.c:29
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:461
DecimateContext::eof
uint32_t eof
bitmask for end of stream
Definition: vf_decimate.c:49
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1318
DecimateContext::dupthresh_flt
double dupthresh_flt
Definition: vf_decimate.c:61
ff_inlink_queued_frames
size_t ff_inlink_queued_frames(AVFilterLink *link)
Get the number of frames available on the link.
Definition: avfilter.c:1333
AVFilterPad::config_props
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:129
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:115
P
#define P
qitem::totdiff
int64_t totdiff
Definition: vf_decimate.c:35
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
DecimateContext::chroma
int chroma
Definition: vf_decimate.c:67
height
#define height
decimate_uninit
static av_cold void decimate_uninit(AVFilterContext *ctx)
Definition: vf_decimate.c:349
DecimateContext::clean_src
AVFrame ** clean_src
frame queue for the clean source
Definition: vf_decimate.c:44
INPUT_CLEANSRC
#define INPUT_CLEANSRC
Definition: vf_decimate.c:30
DecimateContext::blockx
int blockx
Definition: vf_decimate.c:65
internal.h
DecimateContext::scthresh
int64_t scthresh
Definition: vf_decimate.c:64
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
av_gcd_q
AVRational av_gcd_q(AVRational a, AVRational b, int max_den, AVRational def)
Return the best rational so that a and b are multiple of it.
Definition: rational.c:186
DecimateContext::mixed
int mixed
Definition: vf_decimate.c:68
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
decimate_init
static av_cold int decimate_init(AVFilterContext *ctx)
Definition: vf_decimate.c:318
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:55
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
AVFilter
Filter definition.
Definition: avfilter.h:161
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
DecimateContext::dec_tb
AVRational dec_tb
Definition: vf_decimate.c:57
DecimateContext::nyblocks
int nyblocks
Definition: vf_decimate.c:52
AVFrame::height
int height
Definition: frame.h:402
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
FF_INLINK_IDX
#define FF_INLINK_IDX(link)
Find the index of a link.
Definition: internal.h:337
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(decimate)
DecimateContext::fid
int fid
current frame id in the queue
Definition: vf_decimate.c:41
AVPixFmtDescriptor::comp
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:105
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_decimate.c:382
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
AVFilterContext
An instance of a filter.
Definition: avfilter.h:392
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:195
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
DecimateContext
Definition: vf_decimate.c:38
ff_vf_decimate
const AVFilter ff_vf_decimate
Definition: vf_decimate.c:452
FLAGS
#define FLAGS
Definition: vf_decimate.c:72
timestamp.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:375
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:465
h
h
Definition: vp9dsp_template.c:2038
ff_outlink_frame_wanted
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:441
DecimateContext::filled
int filled
1 if the queue is filled, 0 otherwise
Definition: vf_decimate.c:42
DecimateContext::last
AVFrame * last
last frame from the previous queue
Definition: vf_decimate.c:43
qitem::maxbdiff
int64_t maxbdiff
Definition: vf_decimate.c:34
AVPixFmtDescriptor::log2_chroma_h
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
DecimateContext::cycle
int cycle
Definition: vf_decimate.c:60
decimate_outputs
static const AVFilterPad decimate_outputs[]
Definition: vf_decimate.c:444
ff_filter_set_ready
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:204
DecimateContext::last_duration
int64_t last_duration
last output duration
Definition: vf_decimate.c:47