FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_displace.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/imgutils.h"
22 #include "libavutil/pixdesc.h"
23 #include "libavutil/opt.h"
24 #include "avfilter.h"
25 #include "formats.h"
26 #include "framesync.h"
27 #include "internal.h"
28 #include "video.h"
29 
30 enum EdgeMode {
35 };
36 
37 typedef struct DisplaceContext {
38  const AVClass *class;
39  int width[4], height[4];
40  enum EdgeMode edge;
41  int nb_planes;
43  int step;
46 
47  void (*displace)(struct DisplaceContext *s, const AVFrame *in,
48  const AVFrame *xpic, const AVFrame *ypic, AVFrame *out);
50 
51 #define OFFSET(x) offsetof(DisplaceContext, x)
52 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
53 
54 static const AVOption displace_options[] = {
55  { "edge", "set edge mode", OFFSET(edge), AV_OPT_TYPE_INT, {.i64=EDGE_SMEAR}, 0, EDGE_NB-1, FLAGS, "edge" },
56  { "blank", "", 0, AV_OPT_TYPE_CONST, {.i64=EDGE_BLANK}, 0, 0, FLAGS, "edge" },
57  { "smear", "", 0, AV_OPT_TYPE_CONST, {.i64=EDGE_SMEAR}, 0, 0, FLAGS, "edge" },
58  { "wrap" , "", 0, AV_OPT_TYPE_CONST, {.i64=EDGE_WRAP}, 0, 0, FLAGS, "edge" },
59  { NULL }
60 };
61 
63 
65 {
66  static const enum AVPixelFormat pix_fmts[] = {
77  };
78 
79  return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
80 }
81 
83  const AVFrame *xpic, const AVFrame *ypic,
84  AVFrame *out)
85 {
86  int plane, x, y;
87 
88  for (plane = 0; plane < s->nb_planes; plane++) {
89  const int h = s->height[plane];
90  const int w = s->width[plane];
91  const int dlinesize = out->linesize[plane];
92  const int slinesize = in->linesize[plane];
93  const int xlinesize = xpic->linesize[plane];
94  const int ylinesize = ypic->linesize[plane];
95  const uint8_t *src = in->data[plane];
96  const uint8_t *ysrc = ypic->data[plane];
97  const uint8_t *xsrc = xpic->data[plane];
98  uint8_t *dst = out->data[plane];
99  const uint8_t blank = s->blank[plane];
100 
101  for (y = 0; y < h; y++) {
102  switch (s->edge) {
103  case EDGE_BLANK:
104  for (x = 0; x < w; x++) {
105  int Y = y + ysrc[x] - 128;
106  int X = x + xsrc[x] - 128;
107 
108  if (Y < 0 || Y >= h || X < 0 || X >= w)
109  dst[x] = blank;
110  else
111  dst[x] = src[Y * slinesize + X];
112  }
113  break;
114  case EDGE_SMEAR:
115  for (x = 0; x < w; x++) {
116  int Y = av_clip(y + ysrc[x] - 128, 0, h - 1);
117  int X = av_clip(x + xsrc[x] - 128, 0, w - 1);
118  dst[x] = src[Y * slinesize + X];
119  }
120  break;
121  case EDGE_WRAP:
122  for (x = 0; x < w; x++) {
123  int Y = (y + ysrc[x] - 128) % h;
124  int X = (x + xsrc[x] - 128) % w;
125 
126  if (Y < 0)
127  Y += h;
128  if (X < 0)
129  X += w;
130  dst[x] = src[Y * slinesize + X];
131  }
132  break;
133  }
134 
135  ysrc += ylinesize;
136  xsrc += xlinesize;
137  dst += dlinesize;
138  }
139  }
140 }
141 
143  const AVFrame *xpic, const AVFrame *ypic,
144  AVFrame *out)
145 {
146  const int step = s->step;
147  const int h = s->height[0];
148  const int w = s->width[0];
149  const int dlinesize = out->linesize[0];
150  const int slinesize = in->linesize[0];
151  const int xlinesize = xpic->linesize[0];
152  const int ylinesize = ypic->linesize[0];
153  const uint8_t *src = in->data[0];
154  const uint8_t *ysrc = ypic->data[0];
155  const uint8_t *xsrc = xpic->data[0];
156  const uint8_t *blank = s->blank;
157  uint8_t *dst = out->data[0];
158  int c, x, y;
159 
160  for (y = 0; y < h; y++) {
161  switch (s->edge) {
162  case EDGE_BLANK:
163  for (x = 0; x < w; x++) {
164  for (c = 0; c < s->nb_components; c++) {
165  int Y = y + (ysrc[x * step + c] - 128);
166  int X = x + (xsrc[x * step + c] - 128);
167 
168  if (Y < 0 || Y >= h || X < 0 || X >= w)
169  dst[x * step + c] = blank[c];
170  else
171  dst[x * step + c] = src[Y * slinesize + X * step + c];
172  }
173  }
174  break;
175  case EDGE_SMEAR:
176  for (x = 0; x < w; x++) {
177  for (c = 0; c < s->nb_components; c++) {
178  int Y = av_clip(y + (ysrc[x * step + c] - 128), 0, h - 1);
179  int X = av_clip(x + (xsrc[x * step + c] - 128), 0, w - 1);
180 
181  dst[x * step + c] = src[Y * slinesize + X * step + c];
182  }
183  }
184  break;
185  case EDGE_WRAP:
186  for (x = 0; x < w; x++) {
187  for (c = 0; c < s->nb_components; c++) {
188  int Y = (y + (ysrc[x * step + c] - 128)) % h;
189  int X = (x + (xsrc[x * step + c] - 128)) % w;
190 
191  if (Y < 0)
192  Y += h;
193  if (X < 0)
194  X += w;
195  dst[x * step + c] = src[Y * slinesize + X * step + c];
196  }
197  }
198  break;
199  }
200 
201  ysrc += ylinesize;
202  xsrc += xlinesize;
203  dst += dlinesize;
204  }
205 }
206 
208 {
209  AVFilterContext *ctx = fs->parent;
210  DisplaceContext *s = fs->opaque;
211  AVFilterLink *outlink = ctx->outputs[0];
212  AVFrame *out, *in, *xpic, *ypic;
213  int ret;
214 
215  if ((ret = ff_framesync_get_frame(&s->fs, 0, &in, 0)) < 0 ||
216  (ret = ff_framesync_get_frame(&s->fs, 1, &xpic, 0)) < 0 ||
217  (ret = ff_framesync_get_frame(&s->fs, 2, &ypic, 0)) < 0)
218  return ret;
219 
220  if (ctx->is_disabled) {
221  out = av_frame_clone(in);
222  if (!out)
223  return AVERROR(ENOMEM);
224  } else {
225  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
226  if (!out)
227  return AVERROR(ENOMEM);
228  av_frame_copy_props(out, in);
229 
230  s->displace(s, in, xpic, ypic, out);
231  }
232  out->pts = av_rescale_q(in->pts, s->fs.time_base, outlink->time_base);
233 
234  return ff_filter_frame(outlink, out);
235 }
236 
237 static int config_input(AVFilterLink *inlink)
238 {
239  AVFilterContext *ctx = inlink->dst;
240  DisplaceContext *s = ctx->priv;
242  int vsub, hsub;
243 
245  s->nb_components = desc->nb_components;
246 
247  if (s->nb_planes > 1 || s->nb_components == 1)
249  else
251 
252  if (!(desc->flags & AV_PIX_FMT_FLAG_RGB)) {
253  s->blank[1] = s->blank[2] = 128;
254  s->blank[0] = 16;
255  }
256 
257  s->step = av_get_padded_bits_per_pixel(desc) >> 3;
258  hsub = desc->log2_chroma_w;
259  vsub = desc->log2_chroma_h;
260  s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
261  s->height[0] = s->height[3] = inlink->h;
262  s->width[1] = s->width[2] = AV_CEIL_RSHIFT(inlink->w, hsub);
263  s->width[0] = s->width[3] = inlink->w;
264 
265  return 0;
266 }
267 
268 static int config_output(AVFilterLink *outlink)
269 {
270  AVFilterContext *ctx = outlink->src;
271  DisplaceContext *s = ctx->priv;
272  AVFilterLink *srclink = ctx->inputs[0];
273  AVFilterLink *xlink = ctx->inputs[1];
274  AVFilterLink *ylink = ctx->inputs[2];
275  FFFrameSyncIn *in;
276  int ret;
277 
278  if (srclink->format != xlink->format ||
279  srclink->format != ylink->format) {
280  av_log(ctx, AV_LOG_ERROR, "inputs must be of same pixel format\n");
281  return AVERROR(EINVAL);
282  }
283  if (srclink->w != xlink->w ||
284  srclink->h != xlink->h ||
285  srclink->sample_aspect_ratio.num != xlink->sample_aspect_ratio.num ||
286  srclink->sample_aspect_ratio.den != xlink->sample_aspect_ratio.den ||
287  srclink->w != ylink->w ||
288  srclink->h != ylink->h ||
289  srclink->sample_aspect_ratio.num != ylink->sample_aspect_ratio.num ||
290  srclink->sample_aspect_ratio.den != ylink->sample_aspect_ratio.den) {
291  av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
292  "(size %dx%d, SAR %d:%d) do not match the corresponding "
293  "second input link %s parameters (%dx%d, SAR %d:%d) "
294  "and/or third input link %s parameters (%dx%d, SAR %d:%d)\n",
295  ctx->input_pads[0].name, srclink->w, srclink->h,
296  srclink->sample_aspect_ratio.num,
297  srclink->sample_aspect_ratio.den,
298  ctx->input_pads[1].name, xlink->w, xlink->h,
299  xlink->sample_aspect_ratio.num,
300  xlink->sample_aspect_ratio.den,
301  ctx->input_pads[2].name, ylink->w, ylink->h,
302  ylink->sample_aspect_ratio.num,
303  ylink->sample_aspect_ratio.den);
304  return AVERROR(EINVAL);
305  }
306 
307  outlink->w = srclink->w;
308  outlink->h = srclink->h;
309  outlink->time_base = srclink->time_base;
310  outlink->sample_aspect_ratio = srclink->sample_aspect_ratio;
311  outlink->frame_rate = srclink->frame_rate;
312 
313  ret = ff_framesync_init(&s->fs, ctx, 3);
314  if (ret < 0)
315  return ret;
316 
317  in = s->fs.in;
318  in[0].time_base = srclink->time_base;
319  in[1].time_base = xlink->time_base;
320  in[2].time_base = ylink->time_base;
321  in[0].sync = 2;
322  in[0].before = EXT_STOP;
323  in[0].after = EXT_STOP;
324  in[1].sync = 1;
325  in[1].before = EXT_NULL;
326  in[1].after = EXT_INFINITY;
327  in[2].sync = 1;
328  in[2].before = EXT_NULL;
329  in[2].after = EXT_INFINITY;
330  s->fs.opaque = s;
332 
333  return ff_framesync_configure(&s->fs);
334 }
335 
336 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
337 {
338  DisplaceContext *s = inlink->dst->priv;
339  return ff_framesync_filter_frame(&s->fs, inlink, buf);
340 }
341 
342 static int request_frame(AVFilterLink *outlink)
343 {
344  DisplaceContext *s = outlink->src->priv;
345  return ff_framesync_request_frame(&s->fs, outlink);
346 }
347 
349 {
350  DisplaceContext *s = ctx->priv;
351 
352  ff_framesync_uninit(&s->fs);
353 }
354 
355 static const AVFilterPad displace_inputs[] = {
356  {
357  .name = "source",
358  .type = AVMEDIA_TYPE_VIDEO,
359  .filter_frame = filter_frame,
360  .config_props = config_input,
361  },
362  {
363  .name = "xmap",
364  .type = AVMEDIA_TYPE_VIDEO,
365  .filter_frame = filter_frame,
366  },
367  {
368  .name = "ymap",
369  .type = AVMEDIA_TYPE_VIDEO,
370  .filter_frame = filter_frame,
371  },
372  { NULL }
373 };
374 
375 static const AVFilterPad displace_outputs[] = {
376  {
377  .name = "default",
378  .type = AVMEDIA_TYPE_VIDEO,
379  .config_props = config_output,
380  .request_frame = request_frame,
381  },
382  { NULL }
383 };
384 
386  .name = "displace",
387  .description = NULL_IF_CONFIG_SMALL("Displace pixels."),
388  .priv_size = sizeof(DisplaceContext),
389  .uninit = uninit,
391  .inputs = displace_inputs,
392  .outputs = displace_outputs,
393  .priv_class = &displace_class,
395 };
int plane
Definition: avisynth_c.h:422
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2333
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
AVOption.
Definition: opt.h:246
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
misc image utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2373
AVFilter ff_vf_displace
Definition: vf_displace.c:385
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
const char * desc
Definition: nvenc.c:60
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
Definition: framesync.h:175
static const AVOption displace_options[]
Definition: vf_displace.c:54
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:180
int num
Numerator.
Definition: rational.h:59
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:80
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:253
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:92
void(* displace)(struct DisplaceContext *s, const AVFrame *in, const AVFrame *xpic, const AVFrame *ypic, AVFrame *out)
Definition: vf_displace.c:47
#define src
Definition: vp8dsp.c:254
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:370
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
Definition: framesync.h:93
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:60
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:331
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1125
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:102
uint8_t
#define av_cold
Definition: attributes.h:82
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:252
AVOptions.
void * parent
Definition: framesync.h:155
#define Y
Definition: vf_boxblur.c:76
AVFILTER_DEFINE_CLASS(displace)
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: vf_displace.c:336
static int config_output(AVFilterLink *outlink)
Definition: vf_displace.c:268
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:271
FFFrameSyncIn * in
Pointer to array of inputs.
Definition: framesync.h:206
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:95
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:101
static int flags
Definition: log.c:57
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:75
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:98
Input stream structure.
Definition: framesync.h:83
#define av_log(a,...)
static int request_frame(AVFilterLink *outlink)
Definition: vf_displace.c:342
A filter pad used for either input or output.
Definition: internal.h:54
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
int ff_framesync_filter_frame(FFFrameSync *fs, AVFilterLink *inlink, AVFrame *in)
Accept a frame on a filter input.
Definition: framesync.c:303
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:330
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:188
static const AVFilterPad displace_inputs[]
Definition: vf_displace.c:355
#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 FLAGS
Definition: vf_displace.c:52
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:269
Frame sync structure.
Definition: framesync.h:153
#define AVERROR(e)
Definition: error.h:43
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
static void displace_planar(DisplaceContext *s, const AVFrame *in, const AVFrame *xpic, const AVFrame *ypic, AVFrame *out)
Definition: vf_displace.c:82
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:96
void * priv
private data for use by the filter
Definition: avfilter.h:338
int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel for the pixel format described by pixdesc, including any padding ...
Definition: pixdesc.c:2298
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:103
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:93
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:94
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
static void displace_packed(DisplaceContext *s, const AVFrame *in, const AVFrame *xpic, const AVFrame *ypic, AVFrame *out)
Definition: vf_displace.c:142
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
static int process_frame(FFFrameSync *fs)
Definition: vf_displace.c:207
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:74
int ff_framesync_request_frame(FFFrameSync *fs, AVFilterLink *outlink)
Request a frame on the filter output.
Definition: framesync.c:317
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
AVFormatContext * ctx
Definition: movenc.c:48
AVRational time_base
Time base for the output events.
Definition: framesync.h:165
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:65
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:386
void * opaque
Opaque pointer, not used by the API.
Definition: framesync.h:180
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:485
#define OFFSET(x)
Definition: vf_displace.c:51
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:376
static const AVFilterPad displace_outputs[]
Definition: vf_displace.c:375
Extend the frame to infinity.
Definition: framesync.h:77
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:218
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:189
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
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
void * buf
Definition: avisynth_c.h:690
int ff_framesync_init(FFFrameSync *fs, void *parent, unsigned nb_in)
Initialize a frame sync structure.
Definition: framesync.c:52
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:68
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events...
Definition: framesync.h:146
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
Ignore this stream and continue processing the other ones.
Definition: framesync.h:72
static int query_formats(AVFilterContext *ctx)
Definition: vf_displace.c:64
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:254
const char * name
Filter name.
Definition: avfilter.h:148
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:133
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:335
enum EdgeMode edge
Definition: vf_displace.c:40
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:201
FFFrameSync fs
Definition: vf_displace.c:45
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_displace.c:348
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
Y , 8bpp.
Definition: pixfmt.h:70
uint8_t blank[4]
Definition: vf_displace.c:44
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:229
static double c[64]
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:69
int den
Denominator.
Definition: rational.h:60
static int config_input(AVFilterLink *inlink)
Definition: vf_displace.c:237
Completely stop all streams with this one.
Definition: framesync.h:67
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:272
An instance of a filter.
Definition: avfilter.h:323
FILE * out
Definition: movenc.c:54
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:100
EdgeMode
Definition: vf_displace.c:30
internal API functions
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
Definition: framesync.c:232
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:251
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:596
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58