FFmpeg  4.0
vf_remap.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Floris Sluiter
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 /**
22  * @file
23  * Pixel remap filter
24  * This filter copies pixel by pixel a source frame to a target frame.
25  * It remaps the pixels to a new x,y destination based on two files ymap/xmap.
26  * Map files are passed as a parameter and are in PGM format (P2 or P5),
27  * where the values are y(rows)/x(cols) coordinates of the source_frame.
28  * The *target* frame dimension is based on mapfile dimensions: specified in the
29  * header of the mapfile and reflected in the number of datavalues.
30  * Dimensions of ymap and xmap must be equal. Datavalues must be positive or zero.
31  * Any datavalue in the ymap or xmap which value is higher
32  * then the *source* frame height or width is silently ignored, leaving a
33  * blank/chromakey pixel. This can safely be used as a feature to create overlays.
34  *
35  * Algorithm digest:
36  * Target_frame[y][x] = Source_frame[ ymap[y][x] ][ [xmap[y][x] ];
37  */
38 
39 #include "libavutil/imgutils.h"
40 #include "libavutil/pixdesc.h"
41 #include "libavutil/opt.h"
42 #include "avfilter.h"
43 #include "formats.h"
44 #include "framesync.h"
45 #include "internal.h"
46 #include "video.h"
47 
48 typedef struct RemapContext {
49  const AVClass *class;
50  int nb_planes;
52  int step;
54 
55  void (*remap)(struct RemapContext *s, const AVFrame *in,
56  const AVFrame *xin, const AVFrame *yin,
57  AVFrame *out);
58 } RemapContext;
59 
60 #define OFFSET(x) offsetof(RemapContext, x)
61 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
62 
63 static const AVOption remap_options[] = {
64  { NULL }
65 };
66 
68 
70 {
71  static const enum AVPixelFormat pix_fmts[] = {
90  };
91  static const enum AVPixelFormat map_fmts[] = {
93  AV_PIX_FMT_NONE
94  };
95  AVFilterFormats *pix_formats = NULL, *map_formats = NULL;
96  int ret;
97 
98  if (!(pix_formats = ff_make_format_list(pix_fmts)) ||
99  !(map_formats = ff_make_format_list(map_fmts))) {
100  ret = AVERROR(ENOMEM);
101  goto fail;
102  }
103  if ((ret = ff_formats_ref(pix_formats, &ctx->inputs[0]->out_formats)) < 0 ||
104  (ret = ff_formats_ref(map_formats, &ctx->inputs[1]->out_formats)) < 0 ||
105  (ret = ff_formats_ref(map_formats, &ctx->inputs[2]->out_formats)) < 0 ||
106  (ret = ff_formats_ref(pix_formats, &ctx->outputs[0]->in_formats)) < 0)
107  goto fail;
108  return 0;
109 fail:
110  if (pix_formats)
111  av_freep(&pix_formats->formats);
112  av_freep(&pix_formats);
113  if (map_formats)
114  av_freep(&map_formats->formats);
115  av_freep(&map_formats);
116  return ret;
117 }
118 
119 /**
120  * remap_planar algorithm expects planes of same size
121  * pixels are copied from source to target using :
122  * Target_frame[y][x] = Source_frame[ ymap[y][x] ][ [xmap[y][x] ];
123  */
124 static void remap_planar(RemapContext *s, const AVFrame *in,
125  const AVFrame *xin, const AVFrame *yin,
126  AVFrame *out)
127 {
128  const int xlinesize = xin->linesize[0] / 2;
129  const int ylinesize = yin->linesize[0] / 2;
130  int x , y, plane;
131 
132  for (plane = 0; plane < s->nb_planes ; plane++) {
133  uint8_t *dst = out->data[plane];
134  const int dlinesize = out->linesize[plane];
135  const uint8_t *src = in->data[plane];
136  const int slinesize = in->linesize[plane];
137  const uint16_t *xmap = (const uint16_t *)xin->data[0];
138  const uint16_t *ymap = (const uint16_t *)yin->data[0];
139 
140  for (y = 0; y < out->height; y++) {
141  for (x = 0; x < out->width; x++) {
142  if (ymap[x] < in->height && xmap[x] < in->width) {
143  dst[x] = src[ymap[x] * slinesize + xmap[x]];
144  } else {
145  dst[x] = 0;
146  }
147  }
148  dst += dlinesize;
149  xmap += xlinesize;
150  ymap += ylinesize;
151  }
152  }
153 }
154 
155 static void remap_planar16(RemapContext *s, const AVFrame *in,
156  const AVFrame *xin, const AVFrame *yin,
157  AVFrame *out)
158 {
159  const int xlinesize = xin->linesize[0] / 2;
160  const int ylinesize = yin->linesize[0] / 2;
161  int x , y, plane;
162 
163  for (plane = 0; plane < s->nb_planes ; plane++) {
164  uint16_t *dst = (uint16_t *)out->data[plane];
165  const int dlinesize = out->linesize[plane] / 2;
166  const uint16_t *src = (const uint16_t *)in->data[plane];
167  const int slinesize = in->linesize[plane] / 2;
168  const uint16_t *xmap = (const uint16_t *)xin->data[0];
169  const uint16_t *ymap = (const uint16_t *)yin->data[0];
170 
171  for (y = 0; y < out->height; y++) {
172  for (x = 0; x < out->width; x++) {
173  if (ymap[x] < in->height && xmap[x] < in->width) {
174  dst[x] = src[ymap[x] * slinesize + xmap[x]];
175  } else {
176  dst[x] = 0;
177  }
178  }
179  dst += dlinesize;
180  xmap += xlinesize;
181  ymap += ylinesize;
182  }
183  }
184 }
185 
186 /**
187  * remap_packed algorithm expects pixels with both padded bits (step) and
188  * number of components correctly set.
189  * pixels are copied from source to target using :
190  * Target_frame[y][x] = Source_frame[ ymap[y][x] ][ [xmap[y][x] ];
191  */
192 static void remap_packed(RemapContext *s, const AVFrame *in,
193  const AVFrame *xin, const AVFrame *yin,
194  AVFrame *out)
195 {
196  uint8_t *dst = out->data[0];
197  const uint8_t *src = in->data[0];
198  const int dlinesize = out->linesize[0];
199  const int slinesize = in->linesize[0];
200  const int xlinesize = xin->linesize[0] / 2;
201  const int ylinesize = yin->linesize[0] / 2;
202  const uint16_t *xmap = (const uint16_t *)xin->data[0];
203  const uint16_t *ymap = (const uint16_t *)yin->data[0];
204  const int step = s->step;
205  int c, x, y;
206 
207  for (y = 0; y < out->height; y++) {
208  for (x = 0; x < out->width; x++) {
209  for (c = 0; c < s->nb_components; c++) {
210  if (ymap[x] < in->height && xmap[x] < in->width) {
211  dst[x * step + c] = src[ymap[x] * slinesize + xmap[x] * step + c];
212  } else {
213  dst[x * step + c] = 0;
214  }
215  }
216  }
217  dst += dlinesize;
218  xmap += xlinesize;
219  ymap += ylinesize;
220  }
221 }
222 
223 static void remap_packed16(RemapContext *s, const AVFrame *in,
224  const AVFrame *xin, const AVFrame *yin,
225  AVFrame *out)
226 {
227  uint16_t *dst = (uint16_t *)out->data[0];
228  const uint16_t *src = (const uint16_t *)in->data[0];
229  const int dlinesize = out->linesize[0] / 2;
230  const int slinesize = in->linesize[0] / 2;
231  const int xlinesize = xin->linesize[0] / 2;
232  const int ylinesize = yin->linesize[0] / 2;
233  const uint16_t *xmap = (const uint16_t *)xin->data[0];
234  const uint16_t *ymap = (const uint16_t *)yin->data[0];
235  const int step = s->step / 2;
236  int c, x, y;
237 
238  for (y = 0; y < out->height; y++) {
239  for (x = 0; x < out->width; x++) {
240  for (c = 0; c < s->nb_components; c++) {
241  if (ymap[x] < in->height && xmap[x] < in->width) {
242  dst[x * step + c] = src[ymap[x] * slinesize + xmap[x] * step + c];
243  } else {
244  dst[x * step + c] = 0;
245  }
246  }
247  }
248  dst += dlinesize;
249  xmap += xlinesize;
250  ymap += ylinesize;
251  }
252 }
253 
254 static int config_input(AVFilterLink *inlink)
255 {
256  AVFilterContext *ctx = inlink->dst;
257  RemapContext *s = ctx->priv;
259 
261  s->nb_components = desc->nb_components;
262 
263  if (desc->comp[0].depth == 8) {
264  if (s->nb_planes > 1 || s->nb_components == 1) {
265  s->remap = remap_planar;
266  } else {
267  s->remap = remap_packed;
268  }
269  } else {
270  if (s->nb_planes > 1 || s->nb_components == 1) {
271  s->remap = remap_planar16;
272  } else {
273  s->remap = remap_packed16;
274  }
275  }
276 
277  s->step = av_get_padded_bits_per_pixel(desc) >> 3;
278  return 0;
279 }
280 
282 {
283  AVFilterContext *ctx = fs->parent;
284  RemapContext *s = fs->opaque;
285  AVFilterLink *outlink = ctx->outputs[0];
286  AVFrame *out, *in, *xpic, *ypic;
287  int ret;
288 
289  if ((ret = ff_framesync_get_frame(&s->fs, 0, &in, 0)) < 0 ||
290  (ret = ff_framesync_get_frame(&s->fs, 1, &xpic, 0)) < 0 ||
291  (ret = ff_framesync_get_frame(&s->fs, 2, &ypic, 0)) < 0)
292  return ret;
293 
294  if (ctx->is_disabled) {
295  out = av_frame_clone(in);
296  if (!out)
297  return AVERROR(ENOMEM);
298  } else {
299  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
300  if (!out)
301  return AVERROR(ENOMEM);
302  av_frame_copy_props(out, in);
303 
304  s->remap(s, in, xpic, ypic, out);
305  }
306  out->pts = av_rescale_q(in->pts, s->fs.time_base, outlink->time_base);
307 
308  return ff_filter_frame(outlink, out);
309 }
310 
311 static int config_output(AVFilterLink *outlink)
312 {
313  AVFilterContext *ctx = outlink->src;
314  RemapContext *s = ctx->priv;
315  AVFilterLink *srclink = ctx->inputs[0];
316  AVFilterLink *xlink = ctx->inputs[1];
317  AVFilterLink *ylink = ctx->inputs[2];
318  FFFrameSyncIn *in;
319  int ret;
320 
321  if (xlink->w != ylink->w || xlink->h != ylink->h) {
322  av_log(ctx, AV_LOG_ERROR, "Second input link %s parameters "
323  "(size %dx%d) do not match the corresponding "
324  "third input link %s parameters (%dx%d)\n",
325  ctx->input_pads[1].name, xlink->w, xlink->h,
326  ctx->input_pads[2].name, ylink->w, ylink->h);
327  return AVERROR(EINVAL);
328  }
329 
330  outlink->w = xlink->w;
331  outlink->h = xlink->h;
332  outlink->time_base = srclink->time_base;
333  outlink->sample_aspect_ratio = srclink->sample_aspect_ratio;
334  outlink->frame_rate = srclink->frame_rate;
335 
336  ret = ff_framesync_init(&s->fs, ctx, 3);
337  if (ret < 0)
338  return ret;
339 
340  in = s->fs.in;
341  in[0].time_base = srclink->time_base;
342  in[1].time_base = xlink->time_base;
343  in[2].time_base = ylink->time_base;
344  in[0].sync = 2;
345  in[0].before = EXT_STOP;
346  in[0].after = EXT_STOP;
347  in[1].sync = 1;
348  in[1].before = EXT_NULL;
349  in[1].after = EXT_INFINITY;
350  in[2].sync = 1;
351  in[2].before = EXT_NULL;
352  in[2].after = EXT_INFINITY;
353  s->fs.opaque = s;
355 
356  return ff_framesync_configure(&s->fs);
357 }
358 
360 {
361  RemapContext *s = ctx->priv;
362  return ff_framesync_activate(&s->fs);
363 }
364 
365 
367 {
368  RemapContext *s = ctx->priv;
369 
370  ff_framesync_uninit(&s->fs);
371 }
372 
373 static const AVFilterPad remap_inputs[] = {
374  {
375  .name = "source",
376  .type = AVMEDIA_TYPE_VIDEO,
377  .config_props = config_input,
378  },
379  {
380  .name = "xmap",
381  .type = AVMEDIA_TYPE_VIDEO,
382  },
383  {
384  .name = "ymap",
385  .type = AVMEDIA_TYPE_VIDEO,
386  },
387  { NULL }
388 };
389 
390 static const AVFilterPad remap_outputs[] = {
391  {
392  .name = "default",
393  .type = AVMEDIA_TYPE_VIDEO,
394  .config_props = config_output,
395  },
396  { NULL }
397 };
398 
400  .name = "remap",
401  .description = NULL_IF_CONFIG_SMALL("Remap pixels."),
402  .priv_size = sizeof(RemapContext),
403  .uninit = uninit,
405  .activate = activate,
406  .inputs = remap_inputs,
407  .outputs = remap_outputs,
408  .priv_class = &remap_class,
410 };
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:2363
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
int nb_components
Definition: vf_remap.c:51
AVOption.
Definition: opt.h:246
AVFilter ff_vf_remap
Definition: vf_remap.c:399
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:378
AVFILTER_DEFINE_CLASS(remap)
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:388
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:2403
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
const char * desc
Definition: nvenc.c:65
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:358
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:164
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:384
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:363
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:349
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:117
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
#define src
Definition: vp8dsp.c:254
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:385
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
Definition: framesync.h:86
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:350
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:125
const char * name
Pad name.
Definition: internal.h:60
AVFilterContext * parent
Parent filter context.
Definition: framesync.h:152
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:351
static void remap_packed16(RemapContext *s, const AVFrame *in, const AVFrame *xin, const AVFrame *yin, AVFrame *out)
Definition: vf_remap.c:223
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:82
AVOptions.
static int config_input(AVFilterLink *inlink)
Definition: vf_remap.c:254
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:311
static void remap_planar(RemapContext *s, const AVFrame *in, const AVFrame *xin, const AVFrame *yin, AVFrame *out)
remap_planar algorithm expects planes of same size pixels are copied from source to target using : Ta...
Definition: vf_remap.c:124
FFFrameSyncIn * in
Pointer to array of inputs.
Definition: framesync.h:203
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:383
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:90
static int activate(AVFilterContext *ctx)
Definition: vf_remap.c:359
void(* remap)(struct RemapContext *s, const AVFrame *in, const AVFrame *xin, const AVFrame *yin, AVFrame *out)
Definition: vf_remap.c:55
static int flags
Definition: log.c:55
static int query_formats(AVFilterContext *ctx)
Definition: vf_remap.c:69
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:359
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:381
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:91
Input stream structure.
Definition: framesync.h:81
static int config_output(AVFilterLink *outlink)
Definition: vf_remap.c:311
#define av_log(a,...)
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
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:345
int width
Definition: frame.h:276
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:293
Frame sync structure.
Definition: framesync.h:146
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:91
void * priv
private data for use by the filter
Definition: avfilter.h:353
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:2328
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:408
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:389
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:354
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:96
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter&#39;s input and try to produce output.
Definition: framesync.c:344
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:371
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
Definition: framesync.h:172
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:88
#define fail()
Definition: checkasm.h:116
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:390
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:89
FFFrameSync fs
Definition: vf_remap.c:53
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:387
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:352
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
int nb_planes
Definition: vf_remap.c:50
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_remap.c:366
AVFormatContext * ctx
Definition: movenc.c:48
AVRational time_base
Time base for the output events.
Definition: framesync.h:162
static int process_frame(FFFrameSync *fs)
Definition: vf_remap.c:281
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:65
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:405
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
void * opaque
Opaque pointer, not used by the API.
Definition: framesync.h:177
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:367
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:386
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:538
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static const AVOption remap_options[]
Definition: vf_remap.c:63
Extend the frame to infinity.
Definition: framesync.h:75
typedef void(RENAME(mix_any_func_type))
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:249
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
Definition: framesync.c:77
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:173
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,(*(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)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events...
Definition: framesync.h:139
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:70
const char * name
Filter name.
Definition: avfilter.h:148
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static void remap_packed(RemapContext *s, const AVFrame *in, const AVFrame *xin, const AVFrame *yin, AVFrame *out)
remap_packed algorithm expects pixels with both padded bits (step) and number of components correctly...
Definition: vf_remap.c:192
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:385
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:375
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:232
static void remap_planar16(RemapContext *s, const AVFrame *in, const AVFrame *xin, const AVFrame *yin, AVFrame *out)
Definition: vf_remap.c:155
static const AVFilterPad remap_outputs[]
Definition: vf_remap.c:390
Y , 8bpp.
Definition: pixfmt.h:70
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:211
static double c[64]
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:402
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
Completely stop all streams with this one.
Definition: framesync.h:65
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:338
int height
Definition: frame.h:276
FILE * out
Definition: movenc.c:54
#define av_freep(p)
static const AVFilterPad remap_inputs[]
Definition: vf_remap.c:373
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:256
int depth
Number of bits in the component.
Definition: pixdesc.h:58
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:652
int * formats
list of media formats
Definition: formats.h:66