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  AVRational ts_unit; ///< timestamp units for the output frames
47  int64_t last_pts; ///< last output timestamp
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 
56  /* options */
57  int cycle;
58  double dupthresh_flt;
59  double scthresh_flt;
60  int64_t dupthresh;
61  int64_t scthresh;
62  int blockx, blocky;
63  int ppsrc;
64  int chroma;
66 
67 #define OFFSET(x) offsetof(DecimateContext, x)
68 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
69 
70 static const AVOption decimate_options[] = {
71  { "cycle", "set the number of frame from which one will be dropped", OFFSET(cycle), AV_OPT_TYPE_INT, {.i64 = 5}, 2, 25, FLAGS },
72  { "dupthresh", "set duplicate threshold", OFFSET(dupthresh_flt), AV_OPT_TYPE_DOUBLE, {.dbl = 1.1}, 0, 100, FLAGS },
73  { "scthresh", "set scene change threshold", OFFSET(scthresh_flt), AV_OPT_TYPE_DOUBLE, {.dbl = 15.0}, 0, 100, FLAGS },
74  { "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 },
75  { "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 },
76  { "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 },
77  { "chroma", "set whether or not chroma is considered in the metric calculations", OFFSET(chroma), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
78  { NULL }
79 };
80 
81 AVFILTER_DEFINE_CLASS(decimate);
82 
83 static void calc_diffs(const DecimateContext *dm, struct qitem *q,
84  const AVFrame *f1, const AVFrame *f2)
85 {
86  int64_t maxdiff = -1;
87  int64_t *bdiffs = dm->bdiffs;
88  int plane, i, j;
89 
90  memset(bdiffs, 0, dm->bdiffsize * sizeof(*bdiffs));
91 
92  for (plane = 0; plane < (dm->chroma && f1->data[2] ? 3 : 1); plane++) {
93  int x, y, xl;
94  const int linesize1 = f1->linesize[plane];
95  const int linesize2 = f2->linesize[plane];
96  const uint8_t *f1p = f1->data[plane];
97  const uint8_t *f2p = f2->data[plane];
98  int width = plane ? AV_CEIL_RSHIFT(f1->width, dm->hsub) : f1->width;
99  int height = plane ? AV_CEIL_RSHIFT(f1->height, dm->vsub) : f1->height;
100  int hblockx = dm->blockx / 2;
101  int hblocky = dm->blocky / 2;
102 
103  if (plane) {
104  hblockx >>= dm->hsub;
105  hblocky >>= dm->vsub;
106  }
107 
108  for (y = 0; y < height; y++) {
109  int ydest = y / hblocky;
110  int xdest = 0;
111 
112 #define CALC_DIFF(nbits) do { \
113  for (x = 0; x < width; x += hblockx) { \
114  int64_t acc = 0; \
115  int m = FFMIN(width, x + hblockx); \
116  for (xl = x; xl < m; xl++) \
117  acc += abs(((const uint##nbits##_t *)f1p)[xl] - \
118  ((const uint##nbits##_t *)f2p)[xl]); \
119  bdiffs[ydest * dm->nxblocks + xdest] += acc; \
120  xdest++; \
121  } \
122 } while (0)
123  if (dm->depth == 8) CALC_DIFF(8);
124  else CALC_DIFF(16);
125 
126  f1p += linesize1;
127  f2p += linesize2;
128  }
129  }
130 
131  for (i = 0; i < dm->nyblocks - 1; i++) {
132  for (j = 0; j < dm->nxblocks - 1; j++) {
133  int64_t tmp = bdiffs[ i * dm->nxblocks + j ]
134  + bdiffs[ i * dm->nxblocks + j + 1]
135  + bdiffs[(i + 1) * dm->nxblocks + j ]
136  + bdiffs[(i + 1) * dm->nxblocks + j + 1];
137  if (tmp > maxdiff)
138  maxdiff = tmp;
139  }
140  }
141 
142  q->totdiff = 0;
143  for (i = 0; i < dm->bdiffsize; i++)
144  q->totdiff += bdiffs[i];
145  q->maxbdiff = maxdiff;
146 }
147 
149 {
150  int scpos = -1, duppos = -1;
151  int drop = INT_MIN, i, lowest = 0, ret;
152  AVFilterContext *ctx = inlink->dst;
153  AVFilterLink *outlink = ctx->outputs[0];
154  DecimateContext *dm = ctx->priv;
155  AVFrame *prv;
156 
157  /* update frames queue(s) */
158  if (FF_INLINK_IDX(inlink) == INPUT_MAIN) {
159  dm->queue[dm->fid].frame = in;
160  dm->got_frame[INPUT_MAIN] = 1;
161  } else {
162  dm->clean_src[dm->fid] = in;
163  dm->got_frame[INPUT_CLEANSRC] = 1;
164  }
165  if (!dm->got_frame[INPUT_MAIN] || (dm->ppsrc && !dm->got_frame[INPUT_CLEANSRC]))
166  return 0;
168 
169  if (dm->ppsrc)
170  in = dm->queue[dm->fid].frame;
171 
172  if (in) {
173  /* update frame metrics */
174  prv = dm->fid ? dm->queue[dm->fid - 1].frame : dm->last;
175  if (!prv) {
176  dm->queue[dm->fid].maxbdiff = INT64_MAX;
177  dm->queue[dm->fid].totdiff = INT64_MAX;
178  } else {
179  calc_diffs(dm, &dm->queue[dm->fid], prv, in);
180  }
181  if (++dm->fid != dm->cycle)
182  return 0;
183  av_frame_free(&dm->last);
184  dm->last = av_frame_clone(in);
185  dm->fid = 0;
186 
187  /* we have a complete cycle, select the frame to drop */
188  lowest = 0;
189  for (i = 0; i < dm->cycle; i++) {
190  if (dm->queue[i].totdiff > dm->scthresh)
191  scpos = i;
192  if (dm->queue[i].maxbdiff < dm->queue[lowest].maxbdiff)
193  lowest = i;
194  }
195  if (dm->queue[lowest].maxbdiff < dm->dupthresh)
196  duppos = lowest;
197  drop = scpos >= 0 && duppos < 0 ? scpos : lowest;
198  }
199 
200  /* metrics debug */
201  if (av_log_get_level() >= AV_LOG_DEBUG) {
202  av_log(ctx, AV_LOG_DEBUG, "1/%d frame drop:\n", dm->cycle);
203  for (i = 0; i < dm->cycle && dm->queue[i].frame; i++) {
204  av_log(ctx, AV_LOG_DEBUG," #%d: totdiff=%08"PRIx64" maxbdiff=%08"PRIx64"%s%s%s%s\n",
205  i + 1, dm->queue[i].totdiff, dm->queue[i].maxbdiff,
206  i == scpos ? " sc" : "",
207  i == duppos ? " dup" : "",
208  i == lowest ? " lowest" : "",
209  i == drop ? " [DROP]" : "");
210  }
211  }
212 
213  /* push all frames except the drop */
214  ret = 0;
215  for (i = 0; i < dm->cycle && dm->queue[i].frame; i++) {
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 = frame->pts;
225  if (dm->ppsrc) {
227  frame = dm->clean_src[i];
228  if (!frame)
229  continue;
230  dm->clean_src[i] = NULL;
231  }
232  frame->pts = av_rescale_q(outlink->frame_count_in, dm->ts_unit, (AVRational){1,1}) +
233  (dm->start_pts == AV_NOPTS_VALUE ? 0 : dm->start_pts);
234  dm->last_pts = frame->pts;
235  ret = ff_filter_frame(outlink, frame);
236  if (ret < 0)
237  break;
238  }
239  }
240 
241  return ret;
242 }
243 
245 {
246  DecimateContext *dm = ctx->priv;
247  AVFrame *frame = NULL;
248  int ret = 0, status;
249  int64_t pts;
250 
252 
253  if ((dm->got_frame[INPUT_MAIN] == 0) && !(dm->eof & (1 << INPUT_MAIN)) &&
254  (ret = ff_inlink_consume_frame(ctx->inputs[INPUT_MAIN], &frame)) > 0) {
255  ret = filter_frame(ctx->inputs[INPUT_MAIN], frame);
256  if (ret < 0)
257  return ret;
258  }
259  if (ret < 0)
260  return ret;
261  if (dm->ppsrc &&
262  (dm->got_frame[INPUT_CLEANSRC] == 0) && !(dm->eof & (1 << INPUT_CLEANSRC)) &&
263  (ret = ff_inlink_consume_frame(ctx->inputs[INPUT_CLEANSRC], &frame)) > 0) {
264  ret = filter_frame(ctx->inputs[INPUT_CLEANSRC], frame);
265  if (ret < 0)
266  return ret;
267  }
268  if (ret < 0) {
269  return ret;
270  } else if (dm->eof == ((1 << INPUT_MAIN) | (dm->ppsrc << INPUT_CLEANSRC))) {
271  ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, dm->last_pts);
272  return 0;
273  } else if (!(dm->eof & (1 << INPUT_MAIN)) && ff_inlink_acknowledge_status(ctx->inputs[INPUT_MAIN], &status, &pts)) {
274  if (status == AVERROR_EOF) { // flushing
275  dm->eof |= 1 << INPUT_MAIN;
276  if (dm->ppsrc)
277  filter_frame(ctx->inputs[INPUT_CLEANSRC], NULL);
278  filter_frame(ctx->inputs[INPUT_MAIN], NULL);
279  ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, dm->last_pts);
280  return 0;
281  }
282  } else if (dm->ppsrc && !(dm->eof & (1 << INPUT_CLEANSRC)) && ff_inlink_acknowledge_status(ctx->inputs[INPUT_CLEANSRC], &status, &pts)) {
283  if (status == AVERROR_EOF) { // flushing
284  dm->eof |= 1 << INPUT_CLEANSRC;
285  filter_frame(ctx->inputs[INPUT_MAIN], NULL);
286  filter_frame(ctx->inputs[INPUT_CLEANSRC], NULL);
287  ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, dm->last_pts);
288  return 0;
289  }
290  }
291 
292  if (ff_inlink_queued_frames(ctx->inputs[INPUT_MAIN]) > 0 &&
293  (dm->ppsrc && ff_inlink_queued_frames(ctx->inputs[INPUT_CLEANSRC]) > 0)) {
294  ff_filter_set_ready(ctx, 100);
295  } else if (ff_outlink_frame_wanted(ctx->outputs[0])) {
296  if (dm->got_frame[INPUT_MAIN] == 0)
298  if (dm->ppsrc && (dm->got_frame[INPUT_CLEANSRC] == 0))
300  }
301  return 0;
302 }
303 
305 {
306  DecimateContext *dm = ctx->priv;
307  AVFilterPad pad = {
308  .name = "main",
309  .type = AVMEDIA_TYPE_VIDEO,
310  };
311  int ret;
312 
313  if ((ret = ff_insert_inpad(ctx, INPUT_MAIN, &pad)) < 0)
314  return ret;
315 
316  if (dm->ppsrc) {
317  pad.name = "clean_src";
318  pad.config_props = NULL;
319  if ((ret = ff_insert_inpad(ctx, INPUT_CLEANSRC, &pad)) < 0)
320  return ret;
321  }
322 
323  if ((dm->blockx & (dm->blockx - 1)) ||
324  (dm->blocky & (dm->blocky - 1))) {
325  av_log(ctx, AV_LOG_ERROR, "blockx and blocky settings must be power of two\n");
326  return AVERROR(EINVAL);
327  }
328 
330 
331  return 0;
332 }
333 
335 {
336  int i;
337  DecimateContext *dm = ctx->priv;
338 
339  av_frame_free(&dm->last);
340  av_freep(&dm->bdiffs);
341  if (dm->queue) {
342  for (i = 0; i < dm->cycle; i++)
343  av_frame_free(&dm->queue[i].frame);
344  }
345  av_freep(&dm->queue);
346  if (dm->clean_src) {
347  for (i = 0; i < dm->cycle; i++)
348  av_frame_free(&dm->clean_src[i]);
349  }
350  av_freep(&dm->clean_src);
351 }
352 
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  };
369  if (!fmts_list)
370  return AVERROR(ENOMEM);
371  return ff_set_common_formats(ctx, fmts_list);
372 }
373 
374 static int config_output(AVFilterLink *outlink)
375 {
376  AVFilterContext *ctx = outlink->src;
377  DecimateContext *dm = ctx->priv;
378  const AVFilterLink *inlink = ctx->inputs[INPUT_MAIN];
379  AVRational fps = inlink->frame_rate;
380  int max_value;
381  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
382  const int w = inlink->w;
383  const int h = inlink->h;
384 
385  dm->hsub = pix_desc->log2_chroma_w;
386  dm->vsub = pix_desc->log2_chroma_h;
387  dm->depth = pix_desc->comp[0].depth;
388  max_value = (1 << dm->depth) - 1;
389  dm->scthresh = (int64_t)(((int64_t)max_value * w * h * dm->scthresh_flt) / 100);
390  dm->dupthresh = (int64_t)(((int64_t)max_value * dm->blockx * dm->blocky * dm->dupthresh_flt) / 100);
391  dm->nxblocks = (w + dm->blockx/2 - 1) / (dm->blockx/2);
392  dm->nyblocks = (h + dm->blocky/2 - 1) / (dm->blocky/2);
393  dm->bdiffsize = dm->nxblocks * dm->nyblocks;
394  dm->bdiffs = av_malloc_array(dm->bdiffsize, sizeof(*dm->bdiffs));
395  dm->queue = av_calloc(dm->cycle, sizeof(*dm->queue));
396 
397  if (!dm->bdiffs || !dm->queue)
398  return AVERROR(ENOMEM);
399 
400  if (dm->ppsrc) {
401  dm->clean_src = av_calloc(dm->cycle, sizeof(*dm->clean_src));
402  if (!dm->clean_src)
403  return AVERROR(ENOMEM);
404  }
405 
406  if (!fps.num || !fps.den) {
407  av_log(ctx, AV_LOG_ERROR, "The input needs a constant frame rate; "
408  "current rate of %d/%d is invalid\n", fps.num, fps.den);
409  return AVERROR(EINVAL);
410  }
411  fps = av_mul_q(fps, (AVRational){dm->cycle - 1, dm->cycle});
412  av_log(ctx, AV_LOG_VERBOSE, "FPS: %d/%d -> %d/%d\n",
413  inlink->frame_rate.num, inlink->frame_rate.den, fps.num, fps.den);
414  outlink->time_base = inlink->time_base;
415  outlink->frame_rate = fps;
416  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
417  if (dm->ppsrc) {
418  outlink->w = ctx->inputs[INPUT_CLEANSRC]->w;
419  outlink->h = ctx->inputs[INPUT_CLEANSRC]->h;
420  } else {
421  outlink->w = inlink->w;
422  outlink->h = inlink->h;
423  }
424  dm->ts_unit = av_inv_q(av_mul_q(fps, outlink->time_base));
425  return 0;
426 }
427 
428 static const AVFilterPad decimate_outputs[] = {
429  {
430  .name = "default",
431  .type = AVMEDIA_TYPE_VIDEO,
432  .config_props = config_output,
433  },
434  { NULL }
435 };
436 
438  .name = "decimate",
439  .description = NULL_IF_CONFIG_SMALL("Decimate frames (post field matching filter)."),
440  .init = decimate_init,
441  .activate = activate,
442  .uninit = decimate_uninit,
443  .priv_size = sizeof(DecimateContext),
446  .priv_class = &decimate_class,
448 };
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
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
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:1096
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
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:203
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:27
pixdesc.h
AVFrame::width
int width
Definition: frame.h:376
w
uint8_t w
Definition: llviddspenc.c:39
DecimateContext::ts_unit
AVRational ts_unit
timestamp units for the output frames
Definition: vf_decimate.c:46
AVComponentDescriptor::depth
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVOption
AVOption.
Definition: opt.h:248
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:1624
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
DecimateContext::vsub
int vsub
chroma subsampling values
Definition: vf_decimate.c:50
DecimateContext::scthresh_flt
double scthresh_flt
Definition: vf_decimate.c:59
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:149
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:379
DecimateContext::blocky
int blocky
Definition: vf_decimate.c:62
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
qitem::frame
AVFrame * frame
Definition: vf_decimate.c:33
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:65
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_decimate.c:148
ff_insert_inpad
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
Definition: internal.h:240
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:1494
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
pts
static int64_t pts
Definition: transcode_aac.c:652
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:383
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:244
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:83
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
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:258
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:194
av_cold
#define av_cold
Definition: attributes.h:90
ff_set_common_formats
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:587
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:1620
width
#define width
CALC_DIFF
#define CALC_DIFF(nbits)
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
filters.h
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
decimate_options
static const AVOption decimate_options[]
Definition: vf_decimate.c:70
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:382
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:540
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:67
AVPixFmtDescriptor::log2_chroma_w
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
DecimateContext::dupthresh
int64_t dupthresh
Definition: vf_decimate.c:60
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:47
DecimateContext::nxblocks
int nxblocks
Definition: vf_decimate.c:52
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:380
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:435
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
DecimateContext::ppsrc
int ppsrc
Definition: vf_decimate.c:63
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:401
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:1449
DecimateContext::dupthresh_flt
double dupthresh_flt
Definition: vf_decimate.c:58
ff_inlink_queued_frames
size_t ff_inlink_queued_frames(AVFilterLink *link)
Get the number of frames available on the link.
Definition: avfilter.c:1464
AVFilterPad::config_props
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:118
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:117
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:64
height
#define height
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_decimate.c:353
decimate_uninit
static av_cold void decimate_uninit(AVFilterContext *ctx)
Definition: vf_decimate.c:334
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:62
internal.h
DecimateContext::scthresh
int64_t scthresh
Definition: vf_decimate.c:61
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
i
int i
Definition: input.c:407
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
decimate_init
static av_cold int decimate_init(AVFilterContext *ctx)
Definition: vf_decimate.c:304
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
uint8_t
uint8_t
Definition: audio_convert.c:194
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:60
AVFilter
Filter definition.
Definition: avfilter.h:145
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:52
AVFrame::height
int height
Definition: frame.h:376
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
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:302
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:117
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_decimate.c:374
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:341
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:81
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
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
FLAGS
#define FLAGS
Definition: vf_decimate.c:68
timestamp.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
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:28
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:405
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:381
DecimateContext::filled
int filled
1 if the queue is filled, 0 otherwise
Definition: vf_decimate.c:42
ff_vf_decimate
AVFilter ff_vf_decimate
Definition: vf_decimate.c:437
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:101
DecimateContext::cycle
int cycle
Definition: vf_decimate.c:57
decimate_outputs
static const AVFilterPad decimate_outputs[]
Definition: vf_decimate.c:428
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:193