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 start_pts; ///< base for output timestamps
48  uint32_t eof; ///< bitmask for end of stream
49  int hsub, vsub; ///< chroma subsampling values
50  int depth;
52  int bdiffsize;
53  int64_t *bdiffs;
54 
55  /* options */
56  int cycle;
57  double dupthresh_flt;
58  double scthresh_flt;
59  int64_t dupthresh;
60  int64_t scthresh;
61  int blockx, blocky;
62  int ppsrc;
63  int chroma;
65 
66 #define OFFSET(x) offsetof(DecimateContext, x)
67 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
68 
69 static const AVOption decimate_options[] = {
70  { "cycle", "set the number of frame from which one will be dropped", OFFSET(cycle), AV_OPT_TYPE_INT, {.i64 = 5}, 2, 25, FLAGS },
71  { "dupthresh", "set duplicate threshold", OFFSET(dupthresh_flt), AV_OPT_TYPE_DOUBLE, {.dbl = 1.1}, 0, 100, FLAGS },
72  { "scthresh", "set scene change threshold", OFFSET(scthresh_flt), AV_OPT_TYPE_DOUBLE, {.dbl = 15.0}, 0, 100, FLAGS },
73  { "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 },
74  { "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 },
75  { "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 },
76  { "chroma", "set whether or not chroma is considered in the metric calculations", OFFSET(chroma), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
77  { NULL }
78 };
79 
80 AVFILTER_DEFINE_CLASS(decimate);
81 
82 static void calc_diffs(const DecimateContext *dm, struct qitem *q,
83  const AVFrame *f1, const AVFrame *f2)
84 {
85  int64_t maxdiff = -1;
86  int64_t *bdiffs = dm->bdiffs;
87  int plane, i, j;
88 
89  memset(bdiffs, 0, dm->bdiffsize * sizeof(*bdiffs));
90 
91  for (plane = 0; plane < (dm->chroma && f1->data[2] ? 3 : 1); plane++) {
92  int x, y, xl;
93  const int linesize1 = f1->linesize[plane];
94  const int linesize2 = f2->linesize[plane];
95  const uint8_t *f1p = f1->data[plane];
96  const uint8_t *f2p = f2->data[plane];
97  int width = plane ? AV_CEIL_RSHIFT(f1->width, dm->hsub) : f1->width;
98  int height = plane ? AV_CEIL_RSHIFT(f1->height, dm->vsub) : f1->height;
99  int hblockx = dm->blockx / 2;
100  int hblocky = dm->blocky / 2;
101 
102  if (plane) {
103  hblockx >>= dm->hsub;
104  hblocky >>= dm->vsub;
105  }
106 
107  for (y = 0; y < height; y++) {
108  int ydest = y / hblocky;
109  int xdest = 0;
110 
111 #define CALC_DIFF(nbits) do { \
112  for (x = 0; x < width; x += hblockx) { \
113  int64_t acc = 0; \
114  int m = FFMIN(width, x + hblockx); \
115  for (xl = x; xl < m; xl++) \
116  acc += abs(((const uint##nbits##_t *)f1p)[xl] - \
117  ((const uint##nbits##_t *)f2p)[xl]); \
118  bdiffs[ydest * dm->nxblocks + xdest] += acc; \
119  xdest++; \
120  } \
121 } while (0)
122  if (dm->depth == 8) CALC_DIFF(8);
123  else CALC_DIFF(16);
124 
125  f1p += linesize1;
126  f2p += linesize2;
127  }
128  }
129 
130  for (i = 0; i < dm->nyblocks - 1; i++) {
131  for (j = 0; j < dm->nxblocks - 1; j++) {
132  int64_t tmp = bdiffs[ i * dm->nxblocks + j ]
133  + bdiffs[ i * dm->nxblocks + j + 1]
134  + bdiffs[(i + 1) * dm->nxblocks + j ]
135  + bdiffs[(i + 1) * dm->nxblocks + j + 1];
136  if (tmp > maxdiff)
137  maxdiff = tmp;
138  }
139  }
140 
141  q->totdiff = 0;
142  for (i = 0; i < dm->bdiffsize; i++)
143  q->totdiff += bdiffs[i];
144  q->maxbdiff = maxdiff;
145 }
146 
148 {
149  int scpos = -1, duppos = -1;
150  int drop = INT_MIN, i, lowest = 0, ret;
151  AVFilterContext *ctx = inlink->dst;
152  AVFilterLink *outlink = ctx->outputs[0];
153  DecimateContext *dm = ctx->priv;
154  AVFrame *prv;
155 
156  /* update frames queue(s) */
157  if (FF_INLINK_IDX(inlink) == INPUT_MAIN) {
158  dm->queue[dm->fid].frame = in;
159  dm->got_frame[INPUT_MAIN] = 1;
160  } else {
161  dm->clean_src[dm->fid] = in;
162  dm->got_frame[INPUT_CLEANSRC] = 1;
163  }
164  if (!dm->got_frame[INPUT_MAIN] || (dm->ppsrc && !dm->got_frame[INPUT_CLEANSRC]))
165  return 0;
167 
168  if (dm->ppsrc)
169  in = dm->queue[dm->fid].frame;
170 
171  if (in) {
172  /* update frame metrics */
173  prv = dm->fid ? dm->queue[dm->fid - 1].frame : dm->last;
174  if (!prv) {
175  dm->queue[dm->fid].maxbdiff = INT64_MAX;
176  dm->queue[dm->fid].totdiff = INT64_MAX;
177  } else {
178  calc_diffs(dm, &dm->queue[dm->fid], prv, in);
179  }
180  if (++dm->fid != dm->cycle)
181  return 0;
182  av_frame_free(&dm->last);
183  dm->last = av_frame_clone(in);
184  dm->fid = 0;
185 
186  /* we have a complete cycle, select the frame to drop */
187  lowest = 0;
188  for (i = 0; i < dm->cycle; i++) {
189  if (dm->queue[i].totdiff > dm->scthresh)
190  scpos = i;
191  if (dm->queue[i].maxbdiff < dm->queue[lowest].maxbdiff)
192  lowest = i;
193  }
194  if (dm->queue[lowest].maxbdiff < dm->dupthresh)
195  duppos = lowest;
196  drop = scpos >= 0 && duppos < 0 ? scpos : lowest;
197  }
198 
199  /* metrics debug */
200  if (av_log_get_level() >= AV_LOG_DEBUG) {
201  av_log(ctx, AV_LOG_DEBUG, "1/%d frame drop:\n", dm->cycle);
202  for (i = 0; i < dm->cycle && dm->queue[i].frame; i++) {
203  av_log(ctx, AV_LOG_DEBUG," #%d: totdiff=%08"PRIx64" maxbdiff=%08"PRIx64"%s%s%s%s\n",
204  i + 1, dm->queue[i].totdiff, dm->queue[i].maxbdiff,
205  i == scpos ? " sc" : "",
206  i == duppos ? " dup" : "",
207  i == lowest ? " lowest" : "",
208  i == drop ? " [DROP]" : "");
209  }
210  }
211 
212  /* push all frames except the drop */
213  ret = 0;
214  for (i = 0; i < dm->cycle && dm->queue[i].frame; i++) {
215  AVRational in_tb = ctx->inputs[INPUT_MAIN]->time_base;
216  if (i == drop) {
217  if (dm->ppsrc)
218  av_frame_free(&dm->clean_src[i]);
219  av_frame_free(&dm->queue[i].frame);
220  } else {
221  AVFrame *frame = dm->queue[i].frame;
222  dm->queue[i].frame = NULL;
223  if (frame->pts != AV_NOPTS_VALUE && dm->start_pts == AV_NOPTS_VALUE)
224  dm->start_pts = av_rescale_q(frame->pts, in_tb, outlink->time_base);
225 
226  if (dm->ppsrc) {
228  frame = dm->clean_src[i];
229  if (!frame)
230  continue;
231  dm->clean_src[i] = NULL;
232  }
233  frame->pts = outlink->frame_count_in +
234  (dm->start_pts == AV_NOPTS_VALUE ? 0 : dm->start_pts);
235  frame->duration = 1;
236  dm->last_pts = frame->pts;
237  ret = ff_filter_frame(outlink, frame);
238  if (ret < 0)
239  break;
240  }
241  }
242 
243  return ret;
244 }
245 
247 {
248  DecimateContext *dm = ctx->priv;
249  AVFrame *frame = NULL;
250  int ret = 0, status;
251  int64_t pts;
252 
254 
255  if ((dm->got_frame[INPUT_MAIN] == 0) && !(dm->eof & (1 << INPUT_MAIN)) &&
256  (ret = ff_inlink_consume_frame(ctx->inputs[INPUT_MAIN], &frame)) > 0) {
257  ret = filter_frame(ctx->inputs[INPUT_MAIN], frame);
258  if (ret < 0)
259  return ret;
260  }
261  if (ret < 0)
262  return ret;
263  if (dm->ppsrc &&
264  (dm->got_frame[INPUT_CLEANSRC] == 0) && !(dm->eof & (1 << INPUT_CLEANSRC)) &&
265  (ret = ff_inlink_consume_frame(ctx->inputs[INPUT_CLEANSRC], &frame)) > 0) {
266  ret = filter_frame(ctx->inputs[INPUT_CLEANSRC], frame);
267  if (ret < 0)
268  return ret;
269  }
270  if (ret < 0) {
271  return ret;
272  } else if (dm->eof == ((1 << INPUT_MAIN) | (dm->ppsrc << INPUT_CLEANSRC))) {
273  ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, dm->last_pts);
274  return 0;
275  } else if (!(dm->eof & (1 << INPUT_MAIN)) && ff_inlink_acknowledge_status(ctx->inputs[INPUT_MAIN], &status, &pts)) {
276  if (status == AVERROR_EOF) { // flushing
277  dm->eof |= 1 << INPUT_MAIN;
278  if (dm->ppsrc)
279  filter_frame(ctx->inputs[INPUT_CLEANSRC], NULL);
280  filter_frame(ctx->inputs[INPUT_MAIN], NULL);
281  ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, dm->last_pts);
282  return 0;
283  }
284  } else if (dm->ppsrc && !(dm->eof & (1 << INPUT_CLEANSRC)) && ff_inlink_acknowledge_status(ctx->inputs[INPUT_CLEANSRC], &status, &pts)) {
285  if (status == AVERROR_EOF) { // flushing
286  dm->eof |= 1 << INPUT_CLEANSRC;
287  filter_frame(ctx->inputs[INPUT_MAIN], NULL);
288  filter_frame(ctx->inputs[INPUT_CLEANSRC], NULL);
289  ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, dm->last_pts);
290  return 0;
291  }
292  }
293 
294  if (ff_inlink_queued_frames(ctx->inputs[INPUT_MAIN]) > 0 && (!dm->ppsrc ||
295  (dm->ppsrc && ff_inlink_queued_frames(ctx->inputs[INPUT_CLEANSRC]) > 0))) {
296  ff_filter_set_ready(ctx, 100);
297  } else if (ff_outlink_frame_wanted(ctx->outputs[0])) {
298  if (dm->got_frame[INPUT_MAIN] == 0)
300  if (dm->ppsrc && (dm->got_frame[INPUT_CLEANSRC] == 0))
302  }
303  return 0;
304 }
305 
307 {
308  DecimateContext *dm = ctx->priv;
309  AVFilterPad pad = {
310  .name = "main",
311  .type = AVMEDIA_TYPE_VIDEO,
312  };
313  int ret;
314 
315  if ((ret = ff_append_inpad(ctx, &pad)) < 0)
316  return ret;
317 
318  if (dm->ppsrc) {
319  pad.name = "clean_src";
320  pad.config_props = NULL;
321  if ((ret = ff_append_inpad(ctx, &pad)) < 0)
322  return ret;
323  }
324 
325  if ((dm->blockx & (dm->blockx - 1)) ||
326  (dm->blocky & (dm->blocky - 1))) {
327  av_log(ctx, AV_LOG_ERROR, "blockx and blocky settings must be power of two\n");
328  return AVERROR(EINVAL);
329  }
330 
332 
333  return 0;
334 }
335 
337 {
338  int i;
339  DecimateContext *dm = ctx->priv;
340 
341  av_frame_free(&dm->last);
342  av_freep(&dm->bdiffs);
343  if (dm->queue) {
344  for (i = 0; i < dm->cycle; i++)
345  av_frame_free(&dm->queue[i].frame);
346  }
347  av_freep(&dm->queue);
348  if (dm->clean_src) {
349  for (i = 0; i < dm->cycle; i++)
350  av_frame_free(&dm->clean_src[i]);
351  }
352  av_freep(&dm->clean_src);
353 }
354 
355 static const enum AVPixelFormat pix_fmts[] = {
356 #define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
357 #define PF_ALPHA(suf) AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
358 #define PF(suf) PF_NOALPHA(suf), PF_ALPHA(suf)
359  PF(P), PF(P9), PF(P10), PF_NOALPHA(P12), PF_NOALPHA(P14), PF(P16),
367 };
368 
369 static int config_output(AVFilterLink *outlink)
370 {
371  AVFilterContext *ctx = outlink->src;
372  DecimateContext *dm = ctx->priv;
373  const AVFilterLink *inlink = ctx->inputs[INPUT_MAIN];
374  AVRational fps = inlink->frame_rate;
375  int max_value;
376  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
377  const int w = inlink->w;
378  const int h = inlink->h;
379 
380  dm->hsub = pix_desc->log2_chroma_w;
381  dm->vsub = pix_desc->log2_chroma_h;
382  dm->depth = pix_desc->comp[0].depth;
383  max_value = (1 << dm->depth) - 1;
384  dm->scthresh = (int64_t)(((int64_t)max_value * w * h * dm->scthresh_flt) / 100);
385  dm->dupthresh = (int64_t)(((int64_t)max_value * dm->blockx * dm->blocky * dm->dupthresh_flt) / 100);
386  dm->nxblocks = (w + dm->blockx/2 - 1) / (dm->blockx/2);
387  dm->nyblocks = (h + dm->blocky/2 - 1) / (dm->blocky/2);
388  dm->bdiffsize = dm->nxblocks * dm->nyblocks;
389  dm->bdiffs = av_malloc_array(dm->bdiffsize, sizeof(*dm->bdiffs));
390  dm->queue = av_calloc(dm->cycle, sizeof(*dm->queue));
391 
392  if (!dm->bdiffs || !dm->queue)
393  return AVERROR(ENOMEM);
394 
395  if (dm->ppsrc) {
396  dm->clean_src = av_calloc(dm->cycle, sizeof(*dm->clean_src));
397  if (!dm->clean_src)
398  return AVERROR(ENOMEM);
399  }
400 
401  if (!fps.num || !fps.den) {
402  av_log(ctx, AV_LOG_ERROR, "The input needs a constant frame rate; "
403  "current rate of %d/%d is invalid\n", fps.num, fps.den);
404  return AVERROR(EINVAL);
405  }
406  fps = av_mul_q(fps, (AVRational){dm->cycle - 1, dm->cycle});
407  av_log(ctx, AV_LOG_VERBOSE, "FPS: %d/%d -> %d/%d\n",
408  inlink->frame_rate.num, inlink->frame_rate.den, fps.num, fps.den);
409  outlink->time_base = av_inv_q(fps);
410  outlink->frame_rate = fps;
411  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
412  if (dm->ppsrc) {
413  outlink->w = ctx->inputs[INPUT_CLEANSRC]->w;
414  outlink->h = ctx->inputs[INPUT_CLEANSRC]->h;
415  } else {
416  outlink->w = inlink->w;
417  outlink->h = inlink->h;
418  }
419  return 0;
420 }
421 
422 static const AVFilterPad decimate_outputs[] = {
423  {
424  .name = "default",
425  .type = AVMEDIA_TYPE_VIDEO,
426  .config_props = config_output,
427  },
428 };
429 
431  .name = "decimate",
432  .description = NULL_IF_CONFIG_SMALL("Decimate frames (post field matching filter)."),
433  .init = decimate_init,
434  .activate = activate,
435  .uninit = decimate_uninit,
436  .priv_size = sizeof(DecimateContext),
439  .priv_class = &decimate_class,
441 };
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:47
DecimateContext::depth
int depth
Definition: vf_decimate.c:50
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:1009
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
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_decimate.c:355
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:170
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:116
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
pixdesc.h
AVFrame::width
int width
Definition: frame.h:397
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:49
DecimateContext::scthresh_flt
double scthresh_flt
Definition: vf_decimate.c:58
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:175
PF_NOALPHA
#define PF_NOALPHA(suf)
DecimateContext::hsub
int hsub
Definition: vf_decimate.c:49
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:439
DecimateContext::blocky
int blocky
Definition: vf_decimate.c:61
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:346
qitem::frame
AVFrame * frame
Definition: vf_decimate.c:33
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_decimate.c:147
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:1404
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:654
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:116
activate
static int activate(AVFilterContext *ctx)
Definition: vf_decimate.c:246
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:82
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:52
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:1521
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:69
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:474
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:66
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::dupthresh
int64_t dupthresh
Definition: vf_decimate.c:59
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:51
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:440
DecimateContext::bdiffs
int64_t * bdiffs
Definition: vf_decimate.c:53
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:62
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:48
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:1358
DecimateContext::dupthresh_flt
double dupthresh_flt
Definition: vf_decimate.c:57
ff_inlink_queued_frames
size_t ff_inlink_queued_frames(AVFilterLink *link)
Get the number of frames available on the link.
Definition: avfilter.c:1373
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:63
height
#define height
decimate_uninit
static av_cold void decimate_uninit(AVFilterContext *ctx)
Definition: vf_decimate.c:336
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:61
internal.h
DecimateContext::scthresh
int64_t scthresh
Definition: vf_decimate.c:60
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
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:306
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:272
AVFilter
Filter definition.
Definition: avfilter.h:171
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::nyblocks
int nyblocks
Definition: vf_decimate.c:51
AVFrame::height
int height
Definition: frame.h:397
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:333
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:369
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:415
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:191
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:430
FLAGS
#define FLAGS
Definition: vf_decimate.c:67
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:370
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:56
decimate_outputs
static const AVFilterPad decimate_outputs[]
Definition: vf_decimate.c:422
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:199