FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "internal.h"
27 
28 #define INPUT_MAIN 0
29 #define INPUT_CLEANSRC 1
30 
31 struct qitem {
33  int64_t maxbdiff;
34  int64_t totdiff;
35 };
36 
37 typedef struct {
38  const AVClass *class;
39  struct qitem *queue; ///< window of cycle frames and the associated data diff
40  int fid; ///< current frame id in the queue
41  int filled; ///< 1 if the queue is filled, 0 otherwise
42  AVFrame *last; ///< last frame from the previous queue
43  AVFrame **clean_src; ///< frame queue for the clean source
44  int got_frame[2]; ///< frame request flag for each input stream
45  AVRational ts_unit; ///< timestamp units for the output frames
46  int64_t start_pts; ///< base for output timestamps
47  uint32_t eof; ///< bitmask for end of stream
48  int hsub, vsub; ///< chroma subsampling values
49  int depth;
50  int nxblocks, nyblocks;
51  int bdiffsize;
52  int64_t *bdiffs;
53 
54  /* options */
55  int cycle;
56  double dupthresh_flt;
57  double scthresh_flt;
58  int64_t dupthresh;
59  int64_t scthresh;
60  int blockx, blocky;
61  int ppsrc;
62  int chroma;
64 
65 #define OFFSET(x) offsetof(DecimateContext, x)
66 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
67 
68 static const AVOption decimate_options[] = {
69  { "cycle", "set the number of frame from which one will be dropped", OFFSET(cycle), AV_OPT_TYPE_INT, {.i64 = 5}, 2, 25, FLAGS },
70  { "dupthresh", "set duplicate threshold", OFFSET(dupthresh_flt), AV_OPT_TYPE_DOUBLE, {.dbl = 1.1}, 0, 100, FLAGS },
71  { "scthresh", "set scene change threshold", OFFSET(scthresh_flt), AV_OPT_TYPE_DOUBLE, {.dbl = 15.0}, 0, 100, FLAGS },
72  { "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 },
73  { "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 },
74  { "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 },
75  { "chroma", "set whether or not chroma is considered in the metric calculations", OFFSET(chroma), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
76  { NULL }
77 };
78 
79 AVFILTER_DEFINE_CLASS(decimate);
80 
81 static void calc_diffs(const DecimateContext *dm, struct qitem *q,
82  const AVFrame *f1, const AVFrame *f2)
83 {
84  int64_t maxdiff = -1;
85  int64_t *bdiffs = dm->bdiffs;
86  int plane, i, j;
87 
88  memset(bdiffs, 0, dm->bdiffsize * sizeof(*bdiffs));
89 
90  for (plane = 0; plane < (dm->chroma && f1->data[2] ? 3 : 1); plane++) {
91  int x, y, xl;
92  const int linesize1 = f1->linesize[plane];
93  const int linesize2 = f2->linesize[plane];
94  const uint8_t *f1p = f1->data[plane];
95  const uint8_t *f2p = f2->data[plane];
96  int width = plane ? AV_CEIL_RSHIFT(f1->width, dm->hsub) : f1->width;
97  int height = plane ? AV_CEIL_RSHIFT(f1->height, dm->vsub) : f1->height;
98  int hblockx = dm->blockx / 2;
99  int hblocky = dm->blocky / 2;
100 
101  if (plane) {
102  hblockx >>= dm->hsub;
103  hblocky >>= dm->vsub;
104  }
105 
106  for (y = 0; y < height; y++) {
107  int ydest = y / hblocky;
108  int xdest = 0;
109 
110 #define CALC_DIFF(nbits) do { \
111  for (x = 0; x < width; x += hblockx) { \
112  int64_t acc = 0; \
113  int m = FFMIN(width, x + hblockx); \
114  for (xl = x; xl < m; xl++) \
115  acc += abs(((const uint##nbits##_t *)f1p)[xl] - \
116  ((const uint##nbits##_t *)f2p)[xl]); \
117  bdiffs[ydest * dm->nxblocks + xdest] += acc; \
118  xdest++; \
119  } \
120 } while (0)
121  if (dm->depth == 8) CALC_DIFF(8);
122  else CALC_DIFF(16);
123 
124  f1p += linesize1;
125  f2p += linesize2;
126  }
127  }
128 
129  for (i = 0; i < dm->nyblocks - 1; i++) {
130  for (j = 0; j < dm->nxblocks - 1; j++) {
131  int64_t tmp = bdiffs[ i * dm->nxblocks + j ]
132  + bdiffs[ i * dm->nxblocks + j + 1]
133  + bdiffs[(i + 1) * dm->nxblocks + j ]
134  + bdiffs[(i + 1) * dm->nxblocks + j + 1];
135  if (tmp > maxdiff)
136  maxdiff = tmp;
137  }
138  }
139 
140  q->totdiff = 0;
141  for (i = 0; i < dm->bdiffsize; i++)
142  q->totdiff += bdiffs[i];
143  q->maxbdiff = maxdiff;
144 }
145 
146 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
147 {
148  int scpos = -1, duppos = -1;
149  int drop = INT_MIN, i, lowest = 0, ret;
150  AVFilterContext *ctx = inlink->dst;
151  AVFilterLink *outlink = ctx->outputs[0];
152  DecimateContext *dm = ctx->priv;
153  AVFrame *prv;
154 
155  /* update frames queue(s) */
156  if (FF_INLINK_IDX(inlink) == INPUT_MAIN) {
157  dm->queue[dm->fid].frame = in;
158  dm->got_frame[INPUT_MAIN] = 1;
159  } else {
160  dm->clean_src[dm->fid] = in;
161  dm->got_frame[INPUT_CLEANSRC] = 1;
162  }
163  if (!dm->got_frame[INPUT_MAIN] || (dm->ppsrc && !dm->got_frame[INPUT_CLEANSRC]))
164  return 0;
166 
167  if (in) {
168  /* update frame metrics */
169  prv = dm->fid ? dm->queue[dm->fid - 1].frame : dm->last;
170  if (!prv) {
171  dm->queue[dm->fid].maxbdiff = INT64_MAX;
172  dm->queue[dm->fid].totdiff = INT64_MAX;
173  } else {
174  calc_diffs(dm, &dm->queue[dm->fid], prv, in);
175  }
176  if (++dm->fid != dm->cycle)
177  return 0;
178  av_frame_free(&dm->last);
179  dm->last = av_frame_clone(in);
180  dm->fid = 0;
181 
182  /* we have a complete cycle, select the frame to drop */
183  lowest = 0;
184  for (i = 0; i < dm->cycle; i++) {
185  if (dm->queue[i].totdiff > dm->scthresh)
186  scpos = i;
187  if (dm->queue[i].maxbdiff < dm->queue[lowest].maxbdiff)
188  lowest = i;
189  }
190  if (dm->queue[lowest].maxbdiff < dm->dupthresh)
191  duppos = lowest;
192  drop = scpos >= 0 && duppos < 0 ? scpos : lowest;
193  }
194 
195  /* metrics debug */
196  if (av_log_get_level() >= AV_LOG_DEBUG) {
197  av_log(ctx, AV_LOG_DEBUG, "1/%d frame drop:\n", dm->cycle);
198  for (i = 0; i < dm->cycle && dm->queue[i].frame; i++) {
199  av_log(ctx, AV_LOG_DEBUG," #%d: totdiff=%08"PRIx64" maxbdiff=%08"PRIx64"%s%s%s%s\n",
200  i + 1, dm->queue[i].totdiff, dm->queue[i].maxbdiff,
201  i == scpos ? " sc" : "",
202  i == duppos ? " dup" : "",
203  i == lowest ? " lowest" : "",
204  i == drop ? " [DROP]" : "");
205  }
206  }
207 
208  /* push all frames except the drop */
209  ret = 0;
210  for (i = 0; i < dm->cycle && dm->queue[i].frame; i++) {
211  if (i == drop) {
212  if (dm->ppsrc)
213  av_frame_free(&dm->clean_src[i]);
214  av_frame_free(&dm->queue[i].frame);
215  } else {
216  AVFrame *frame = dm->queue[i].frame;
217  if (frame->pts != AV_NOPTS_VALUE && dm->start_pts == AV_NOPTS_VALUE)
218  dm->start_pts = frame->pts;
219  if (dm->ppsrc) {
220  av_frame_free(&frame);
221  frame = dm->clean_src[i];
222  }
223  frame->pts = av_rescale_q(outlink->frame_count, dm->ts_unit, (AVRational){1,1}) +
224  (dm->start_pts == AV_NOPTS_VALUE ? 0 : dm->start_pts);
225  ret = ff_filter_frame(outlink, frame);
226  if (ret < 0)
227  break;
228  }
229  }
230 
231  return ret;
232 }
233 
234 static int config_input(AVFilterLink *inlink)
235 {
236  int max_value;
237  AVFilterContext *ctx = inlink->dst;
238  DecimateContext *dm = ctx->priv;
239  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
240  const int w = inlink->w;
241  const int h = inlink->h;
242 
243  dm->hsub = pix_desc->log2_chroma_w;
244  dm->vsub = pix_desc->log2_chroma_h;
245  dm->depth = pix_desc->comp[0].depth;
246  max_value = (1 << dm->depth) - 1;
247  dm->scthresh = (int64_t)(((int64_t)max_value * w * h * dm->scthresh_flt) / 100);
248  dm->dupthresh = (int64_t)(((int64_t)max_value * dm->blockx * dm->blocky * dm->dupthresh_flt) / 100);
249  dm->nxblocks = (w + dm->blockx/2 - 1) / (dm->blockx/2);
250  dm->nyblocks = (h + dm->blocky/2 - 1) / (dm->blocky/2);
251  dm->bdiffsize = dm->nxblocks * dm->nyblocks;
252  dm->bdiffs = av_malloc_array(dm->bdiffsize, sizeof(*dm->bdiffs));
253  dm->queue = av_calloc(dm->cycle, sizeof(*dm->queue));
254 
255  if (!dm->bdiffs || !dm->queue)
256  return AVERROR(ENOMEM);
257 
258  if (dm->ppsrc) {
259  dm->clean_src = av_calloc(dm->cycle, sizeof(*dm->clean_src));
260  if (!dm->clean_src)
261  return AVERROR(ENOMEM);
262  }
263 
264  return 0;
265 }
266 
268 {
269  DecimateContext *dm = ctx->priv;
270  AVFilterPad pad = {
271  .name = av_strdup("main"),
272  .type = AVMEDIA_TYPE_VIDEO,
273  .filter_frame = filter_frame,
274  .config_props = config_input,
275  };
276 
277  if (!pad.name)
278  return AVERROR(ENOMEM);
279  ff_insert_inpad(ctx, INPUT_MAIN, &pad);
280 
281  if (dm->ppsrc) {
282  pad.name = av_strdup("clean_src");
283  pad.config_props = NULL;
284  if (!pad.name)
285  return AVERROR(ENOMEM);
286  ff_insert_inpad(ctx, INPUT_CLEANSRC, &pad);
287  }
288 
289  if ((dm->blockx & (dm->blockx - 1)) ||
290  (dm->blocky & (dm->blocky - 1))) {
291  av_log(ctx, AV_LOG_ERROR, "blockx and blocky settings must be power of two\n");
292  return AVERROR(EINVAL);
293  }
294 
296 
297  return 0;
298 }
299 
301 {
302  int i;
303  DecimateContext *dm = ctx->priv;
304 
305  av_frame_free(&dm->last);
306  av_freep(&dm->bdiffs);
307  av_freep(&dm->queue);
308  av_freep(&dm->clean_src);
309  for (i = 0; i < ctx->nb_inputs; i++)
310  av_freep(&ctx->input_pads[i].name);
311 }
312 
313 static int request_inlink(AVFilterContext *ctx, int lid)
314 {
315  int ret = 0;
316  DecimateContext *dm = ctx->priv;
317 
318  if (!dm->got_frame[lid]) {
319  AVFilterLink *inlink = ctx->inputs[lid];
320  ret = ff_request_frame(inlink);
321  if (ret == AVERROR_EOF) { // flushing
322  dm->eof |= 1 << lid;
323  ret = filter_frame(inlink, NULL);
324  }
325  }
326  return ret;
327 }
328 
329 static int request_frame(AVFilterLink *outlink)
330 {
331  int ret;
332  AVFilterContext *ctx = outlink->src;
333  DecimateContext *dm = ctx->priv;
334  const uint32_t eof_mask = 1<<INPUT_MAIN | dm->ppsrc<<INPUT_CLEANSRC;
335 
336  if ((dm->eof & eof_mask) == eof_mask) // flush done?
337  return AVERROR_EOF;
338  if ((ret = request_inlink(ctx, INPUT_MAIN)) < 0)
339  return ret;
340  if (dm->ppsrc && (ret = request_inlink(ctx, INPUT_CLEANSRC)) < 0)
341  return ret;
342  return 0;
343 }
344 
346 {
347  static const enum AVPixelFormat pix_fmts[] = {
348 #define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
349 #define PF_ALPHA(suf) AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
350 #define PF(suf) PF_NOALPHA(suf), PF_ALPHA(suf)
351  PF(P), PF(P9), PF(P10), PF_NOALPHA(P12), PF_NOALPHA(P14), PF(P16),
355  };
356  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
357  if (!fmts_list)
358  return AVERROR(ENOMEM);
359  return ff_set_common_formats(ctx, fmts_list);
360 }
361 
362 static int config_output(AVFilterLink *outlink)
363 {
364  AVFilterContext *ctx = outlink->src;
365  DecimateContext *dm = ctx->priv;
366  const AVFilterLink *inlink =
367  ctx->inputs[dm->ppsrc ? INPUT_CLEANSRC : INPUT_MAIN];
368  const AVFilterLink *inlink_main =
369  ctx->inputs[INPUT_MAIN];
370  AVRational fps = inlink->frame_rate;
371 
372  if (!fps.num || !fps.den) {
373  av_log(ctx, AV_LOG_ERROR, "The input needs a constant frame rate; "
374  "current rate of %d/%d is invalid\n", fps.num, fps.den);
375  return AVERROR(EINVAL);
376  }
377 
378  if (inlink->w != inlink_main->w ||
379  inlink->h != inlink_main->h ||
380  inlink->format != inlink_main->format) {
381  av_log(ctx, AV_LOG_ERROR, "frame parameters differ between inputs\n");
382  return AVERROR_PATCHWELCOME;
383  }
384  fps = av_mul_q(fps, (AVRational){dm->cycle - 1, dm->cycle});
385  av_log(ctx, AV_LOG_VERBOSE, "FPS: %d/%d -> %d/%d\n",
386  inlink->frame_rate.num, inlink->frame_rate.den, fps.num, fps.den);
387  outlink->time_base = inlink->time_base;
388  outlink->frame_rate = fps;
389  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
390  outlink->w = inlink->w;
391  outlink->h = inlink->h;
392  dm->ts_unit = av_inv_q(av_mul_q(fps, outlink->time_base));
393  return 0;
394 }
395 
396 static const AVFilterPad decimate_outputs[] = {
397  {
398  .name = "default",
399  .type = AVMEDIA_TYPE_VIDEO,
400  .request_frame = request_frame,
401  .config_props = config_output,
402  },
403  { NULL }
404 };
405 
407  .name = "decimate",
408  .description = NULL_IF_CONFIG_SMALL("Decimate frames (post field matching filter)."),
409  .init = decimate_init,
410  .uninit = decimate_uninit,
411  .priv_size = sizeof(DecimateContext),
413  .outputs = decimate_outputs,
414  .priv_class = &decimate_class,
416 };
int plane
Definition: avisynth_c.h:291
static const AVFilterPad decimate_outputs[]
Definition: vf_decimate.c:396
#define NULL
Definition: coverity.c:32
#define P
uint32_t eof
bitmask for end of stream
Definition: vf_decimate.c:47
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2157
This structure describes decoded (raw) audio or video data.
Definition: frame.h:181
AVOption.
Definition: opt.h:245
AVFormatContext * ctx
Definition: movenc-test.c:48
Main libavfilter public API header.
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:102
int num
numerator
Definition: rational.h:44
int64_t maxbdiff
Definition: vf_decimate.c:33
int64_t totdiff
Definition: vf_decimate.c:34
#define PF(suf)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
AVFrame ** clean_src
frame queue for the clean source
Definition: vf_decimate.c:43
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
int64_t scthresh
Definition: vf_decimate.c:59
const char * name
Pad name.
Definition: internal.h:59
#define CALC_DIFF(nbits)
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:312
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1163
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:82
AVOptions.
timestamp utils, mostly useful for debugging/logging purposes
#define OFFSET(x)
Definition: vf_decimate.c:65
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:262
int fid
current frame id in the queue
Definition: vf_decimate.c:40
AVFILTER_DEFINE_CLASS(decimate)
static AVFrame * frame
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:53
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
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:311
int width
width and height of the video frame
Definition: frame.h:230
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
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:568
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
#define AVERROR(e)
Definition: error.h:43
AVFilter ff_vf_decimate
Definition: vf_decimate.c:406
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:154
AVFrame * last
last frame from the previous queue
Definition: vf_decimate.c:42
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
void * priv
private data for use by the filter
Definition: avfilter.h:319
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
AVFrame * frame
Definition: vf_decimate.c:32
int av_log_get_level(void)
Get the current log level.
Definition: log.c:377
int64_t start_pts
base for output timestamps
Definition: vf_decimate.c:46
int filled
1 if the queue is filled, 0 otherwise
Definition: vf_decimate.c:41
static av_cold void decimate_uninit(AVFilterContext *ctx)
Definition: vf_decimate.c:300
unsigned nb_inputs
number of input pads
Definition: avfilter.h:313
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:314
static int config_input(AVFilterLink *inlink)
Definition: vf_decimate.c:234
#define PF_NOALPHA(suf)
static int request_inlink(AVFilterContext *ctx, int lid)
Definition: vf_decimate.c:313
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:385
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:461
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
struct qitem * queue
window of cycle frames and the associated data diff
Definition: vf_decimate.c:39
double scthresh_flt
Definition: vf_decimate.c:57
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:267
static const AVOption decimate_options[]
Definition: vf_decimate.c:68
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:209
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
AVRational ts_unit
timestamp units for the output frames
Definition: vf_decimate.c:45
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:69
Describe the class of an AVClass context structure.
Definition: log.h:67
static av_cold int decimate_init(AVFilterContext *ctx)
Definition: vf_decimate.c:267
#define FLAGS
Definition: vf_decimate.c:66
Filter definition.
Definition: avfilter.h:141
int vsub
chroma subsampling values
Definition: vf_decimate.c:48
rational number numerator/denominator
Definition: rational.h:43
static void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset, int column)
Definition: vf_waveform.c:740
static int request_frame(AVFilterLink *outlink)
Definition: vf_decimate.c:329
int got_frame[2]
frame request flag for each input stream
Definition: vf_decimate.c:44
const char * name
Filter name.
Definition: avfilter.h:145
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:316
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_decimate.c:146
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
Definition: mem.c:260
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:133
static int flags
Definition: cpu.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:192
#define INPUT_CLEANSRC
Definition: vf_decimate.c:29
#define FF_INLINK_IDX(link)
Find the index of a link.
Definition: internal.h:353
Y , 8bpp.
Definition: pixfmt.h:71
static void calc_diffs(const DecimateContext *dm, struct qitem *q, const AVFrame *f1, const AVFrame *f2)
Definition: vf_decimate.c:81
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:70
int den
denominator
Definition: rational.h:45
int64_t dupthresh
Definition: vf_decimate.c:58
A list of supported formats for one end of a filter link.
Definition: formats.h:64
static int config_output(AVFilterLink *outlink)
Definition: vf_decimate.c:362
An instance of a filter.
Definition: avfilter.h:304
#define INPUT_MAIN
Definition: vf_decimate.c:28
int height
Definition: frame.h:230
#define av_freep(p)
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:128
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:101
#define av_malloc_array(a, b)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:356
internal API functions
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
static int query_formats(AVFilterContext *ctx)
Definition: vf_decimate.c:345
int64_t * bdiffs
Definition: vf_decimate.c:52
double dupthresh_flt
Definition: vf_decimate.c:56
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:240
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
Definition: internal.h:283
static int width