FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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[] = {
87  };
88  static const enum AVPixelFormat map_fmts[] = {
91  };
92  AVFilterFormats *pix_formats = NULL, *map_formats = NULL;
93  int ret;
94 
95  if (!(pix_formats = ff_make_format_list(pix_fmts)) ||
96  !(map_formats = ff_make_format_list(map_fmts))) {
97  ret = AVERROR(ENOMEM);
98  goto fail;
99  }
100  if ((ret = ff_formats_ref(pix_formats, &ctx->inputs[0]->out_formats)) < 0 ||
101  (ret = ff_formats_ref(map_formats, &ctx->inputs[1]->out_formats)) < 0 ||
102  (ret = ff_formats_ref(map_formats, &ctx->inputs[2]->out_formats)) < 0 ||
103  (ret = ff_formats_ref(pix_formats, &ctx->outputs[0]->in_formats)) < 0)
104  goto fail;
105  return 0;
106 fail:
107  if (pix_formats)
108  av_freep(&pix_formats->formats);
109  av_freep(&pix_formats);
110  if (map_formats)
111  av_freep(&map_formats->formats);
112  av_freep(&map_formats);
113  return ret;
114 }
115 
116 /**
117  * remap_planar algorithm expects planes of same size
118  * pixels are copied from source to target using :
119  * Target_frame[y][x] = Source_frame[ ymap[y][x] ][ [xmap[y][x] ];
120  */
121 static void remap_planar(RemapContext *s, const AVFrame *in,
122  const AVFrame *xin, const AVFrame *yin,
123  AVFrame *out)
124 {
125  const int xlinesize = xin->linesize[0] / 2;
126  const int ylinesize = yin->linesize[0] / 2;
127  int x , y, plane;
128 
129  for (plane = 0; plane < s->nb_planes ; plane++) {
130  uint8_t *dst = out->data[plane];
131  const int dlinesize = out->linesize[plane];
132  const uint8_t *src = in->data[plane];
133  const int slinesize = in->linesize[plane];
134  const uint16_t *xmap = (const uint16_t *)xin->data[0];
135  const uint16_t *ymap = (const uint16_t *)yin->data[0];
136 
137  for (y = 0; y < out->height; y++) {
138  for (x = 0; x < out->width; x++) {
139  if (ymap[x] < in->height && xmap[x] < in->width) {
140  dst[x] = src[ymap[x] * slinesize + xmap[x]];
141  } else {
142  dst[x] = 0;
143  }
144  }
145  dst += dlinesize;
146  xmap += xlinesize;
147  ymap += ylinesize;
148  }
149  }
150 }
151 
152 static void remap_planar16(RemapContext *s, const AVFrame *in,
153  const AVFrame *xin, const AVFrame *yin,
154  AVFrame *out)
155 {
156  const int xlinesize = xin->linesize[0] / 2;
157  const int ylinesize = yin->linesize[0] / 2;
158  int x , y, plane;
159 
160  for (plane = 0; plane < s->nb_planes ; plane++) {
161  uint16_t *dst = (uint16_t *)out->data[plane];
162  const int dlinesize = out->linesize[plane] / 2;
163  const uint16_t *src = (const uint16_t *)in->data[plane];
164  const int slinesize = in->linesize[plane] / 2;
165  const uint16_t *xmap = (const uint16_t *)xin->data[0];
166  const uint16_t *ymap = (const uint16_t *)yin->data[0];
167 
168  for (y = 0; y < out->height; y++) {
169  for (x = 0; x < out->width; x++) {
170  if (ymap[x] < in->height && xmap[x] < in->width) {
171  dst[x] = src[ymap[x] * slinesize + xmap[x]];
172  } else {
173  dst[x] = 0;
174  }
175  }
176  dst += dlinesize;
177  xmap += xlinesize;
178  ymap += ylinesize;
179  }
180  }
181 }
182 
183 /**
184  * remap_packed algorithm expects pixels with both padded bits (step) and
185  * number of components correctly set.
186  * pixels are copied from source to target using :
187  * Target_frame[y][x] = Source_frame[ ymap[y][x] ][ [xmap[y][x] ];
188  */
189 static void remap_packed(RemapContext *s, const AVFrame *in,
190  const AVFrame *xin, const AVFrame *yin,
191  AVFrame *out)
192 {
193  uint8_t *dst = out->data[0];
194  const uint8_t *src = in->data[0];
195  const int dlinesize = out->linesize[0];
196  const int slinesize = in->linesize[0];
197  const int xlinesize = xin->linesize[0] / 2;
198  const int ylinesize = yin->linesize[0] / 2;
199  const uint16_t *xmap = (const uint16_t *)xin->data[0];
200  const uint16_t *ymap = (const uint16_t *)yin->data[0];
201  const int step = s->step;
202  int c, x, y;
203 
204  for (y = 0; y < out->height; y++) {
205  for (x = 0; x < out->width; x++) {
206  for (c = 0; c < s->nb_components; c++) {
207  if (ymap[x] < in->height && xmap[x] < in->width) {
208  dst[x * step + c] = src[ymap[x] * slinesize + xmap[x] * step + c];
209  } else {
210  dst[x * step + c] = 0;
211  }
212  }
213  }
214  dst += dlinesize;
215  xmap += xlinesize;
216  ymap += ylinesize;
217  }
218 }
219 
220 static void remap_packed16(RemapContext *s, const AVFrame *in,
221  const AVFrame *xin, const AVFrame *yin,
222  AVFrame *out)
223 {
224  uint16_t *dst = (uint16_t *)out->data[0];
225  const uint16_t *src = (const uint16_t *)in->data[0];
226  const int dlinesize = out->linesize[0] / 2;
227  const int slinesize = in->linesize[0] / 2;
228  const int xlinesize = xin->linesize[0] / 2;
229  const int ylinesize = yin->linesize[0] / 2;
230  const uint16_t *xmap = (const uint16_t *)xin->data[0];
231  const uint16_t *ymap = (const uint16_t *)yin->data[0];
232  const int step = s->step / 2;
233  int c, x, y;
234 
235  for (y = 0; y < out->height; y++) {
236  for (x = 0; x < out->width; x++) {
237  for (c = 0; c < s->nb_components; c++) {
238  if (ymap[x] < in->height && xmap[x] < in->width) {
239  dst[x * step + c] = src[ymap[x] * slinesize + xmap[x] * step + c];
240  } else {
241  dst[x * step + c] = 0;
242  }
243  }
244  }
245  dst += dlinesize;
246  xmap += xlinesize;
247  ymap += ylinesize;
248  }
249 }
250 
251 static int config_input(AVFilterLink *inlink)
252 {
253  AVFilterContext *ctx = inlink->dst;
254  RemapContext *s = ctx->priv;
256 
258  s->nb_components = desc->nb_components;
259 
260  if (desc->comp[0].depth == 8) {
261  if (s->nb_planes > 1 || s->nb_components == 1) {
262  s->remap = remap_planar;
263  } else {
264  s->remap = remap_packed;
265  }
266  } else {
267  if (s->nb_planes > 1 || s->nb_components == 1) {
268  s->remap = remap_planar16;
269  } else {
270  s->remap = remap_packed16;
271  }
272  }
273 
274  s->step = av_get_padded_bits_per_pixel(desc) >> 3;
275  return 0;
276 }
277 
279 {
280  AVFilterContext *ctx = fs->parent;
281  RemapContext *s = fs->opaque;
282  AVFilterLink *outlink = ctx->outputs[0];
283  AVFrame *out, *in, *xpic, *ypic;
284  int ret;
285 
286  if ((ret = ff_framesync_get_frame(&s->fs, 0, &in, 0)) < 0 ||
287  (ret = ff_framesync_get_frame(&s->fs, 1, &xpic, 0)) < 0 ||
288  (ret = ff_framesync_get_frame(&s->fs, 2, &ypic, 0)) < 0)
289  return ret;
290 
291  if (ctx->is_disabled) {
292  out = av_frame_clone(in);
293  if (!out)
294  return AVERROR(ENOMEM);
295  } else {
296  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
297  if (!out)
298  return AVERROR(ENOMEM);
299  av_frame_copy_props(out, in);
300 
301  s->remap(s, in, xpic, ypic, out);
302  }
303  out->pts = av_rescale_q(in->pts, s->fs.time_base, outlink->time_base);
304 
305  return ff_filter_frame(outlink, out);
306 }
307 
308 static int config_output(AVFilterLink *outlink)
309 {
310  AVFilterContext *ctx = outlink->src;
311  RemapContext *s = ctx->priv;
312  AVFilterLink *srclink = ctx->inputs[0];
313  AVFilterLink *xlink = ctx->inputs[1];
314  AVFilterLink *ylink = ctx->inputs[2];
315  FFFrameSyncIn *in;
316  int ret;
317 
318  if (xlink->w != ylink->w || xlink->h != ylink->h) {
319  av_log(ctx, AV_LOG_ERROR, "Second input link %s parameters "
320  "(size %dx%d) do not match the corresponding "
321  "third input link %s parameters (%dx%d)\n",
322  ctx->input_pads[1].name, xlink->w, xlink->h,
323  ctx->input_pads[2].name, ylink->w, ylink->h);
324  return AVERROR(EINVAL);
325  }
326 
327  outlink->w = xlink->w;
328  outlink->h = xlink->h;
329  outlink->time_base = srclink->time_base;
330  outlink->sample_aspect_ratio = srclink->sample_aspect_ratio;
331  outlink->frame_rate = srclink->frame_rate;
332 
333  ret = ff_framesync_init(&s->fs, ctx, 3);
334  if (ret < 0)
335  return ret;
336 
337  in = s->fs.in;
338  in[0].time_base = srclink->time_base;
339  in[1].time_base = xlink->time_base;
340  in[2].time_base = ylink->time_base;
341  in[0].sync = 2;
342  in[0].before = EXT_STOP;
343  in[0].after = EXT_STOP;
344  in[1].sync = 1;
345  in[1].before = EXT_NULL;
346  in[1].after = EXT_INFINITY;
347  in[2].sync = 1;
348  in[2].before = EXT_NULL;
349  in[2].after = EXT_INFINITY;
350  s->fs.opaque = s;
352 
353  return ff_framesync_configure(&s->fs);
354 }
355 
356 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
357 {
358  RemapContext *s = inlink->dst->priv;
359  return ff_framesync_filter_frame(&s->fs, inlink, buf);
360 }
361 
362 static int request_frame(AVFilterLink *outlink)
363 {
364  RemapContext *s = outlink->src->priv;
365  return ff_framesync_request_frame(&s->fs, outlink);
366 }
367 
369 {
370  RemapContext *s = ctx->priv;
371 
372  ff_framesync_uninit(&s->fs);
373 }
374 
375 static const AVFilterPad remap_inputs[] = {
376  {
377  .name = "source",
378  .type = AVMEDIA_TYPE_VIDEO,
379  .filter_frame = filter_frame,
380  .config_props = config_input,
381  },
382  {
383  .name = "xmap",
384  .type = AVMEDIA_TYPE_VIDEO,
385  .filter_frame = filter_frame,
386  },
387  {
388  .name = "ymap",
389  .type = AVMEDIA_TYPE_VIDEO,
390  .filter_frame = filter_frame,
391  },
392  { NULL }
393 };
394 
395 static const AVFilterPad remap_outputs[] = {
396  {
397  .name = "default",
398  .type = AVMEDIA_TYPE_VIDEO,
399  .config_props = config_output,
400  .request_frame = request_frame,
401  },
402  { NULL }
403 };
404 
406  .name = "remap",
407  .description = NULL_IF_CONFIG_SMALL("Remap pixels"),
408  .priv_size = sizeof(RemapContext),
409  .uninit = uninit,
411  .inputs = remap_inputs,
412  .outputs = remap_outputs,
413  .priv_class = &remap_class,
415 };
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:2266
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
int nb_components
Definition: vf_remap.c:51
AVOption.
Definition: opt.h:245
void(* remap)(struct RemapContext *s, const AVFrame *in, const AVFrame *xin, const AVFrame *yin, AVFrame *out)
Definition: vf_remap.c:55
AVFilter ff_vf_remap
Definition: vf_remap.c:405
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:351
AVFILTER_DEFINE_CLASS(remap)
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:361
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:2306
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
const char * desc
Definition: nvenc.c:101
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:331
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
Definition: framesync.h:175
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:180
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:357
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:336
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:77
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:76
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:354
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
#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:59
static void remap_packed16(RemapContext *s, const AVFrame *in, const AVFrame *xin, const AVFrame *yin, AVFrame *out)
Definition: vf_remap.c:220
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:315
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1189
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:82
AVOptions.
void * parent
Definition: framesync.h:155
static int config_input(AVFilterLink *inlink)
Definition: vf_remap.c:251
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:268
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:121
FFFrameSyncIn * in
Pointer to array of inputs.
Definition: framesync.h:206
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:356
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:95
static int query_formats(AVFilterContext *ctx)
Definition: vf_remap.c:69
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:332
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:354
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:98
Input stream structure.
Definition: framesync.h:83
static int config_output(AVFilterLink *outlink)
Definition: vf_remap.c:308
#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
int ff_framesync_filter_frame(FFFrameSync *fs, AVFilterLink *inlink, AVFrame *in)
Accept a frame on a filter input.
Definition: framesync.c:300
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:314
int width
width and height of the video frame
Definition: frame.h:236
#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:266
Frame sync structure.
Definition: framesync.h:153
#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:176
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:96
void * priv
private data for use by the filter
Definition: avfilter.h:322
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:2231
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:379
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:362
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:327
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:103
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:344
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:93
#define fail()
Definition: checkasm.h:83
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:363
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:94
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: vf_remap.c:356
static int request_frame(AVFilterLink *outlink)
Definition: vf_remap.c:362
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:360
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:325
int ff_framesync_request_frame(FFFrameSync *fs, AVFilterLink *outlink)
Request a frame on the filter output.
Definition: framesync.c:314
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
int nb_planes
Definition: vf_remap.c:50
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_remap.c:368
AVFormatContext * ctx
Definition: movenc.c:48
AVRational time_base
Time base for the output events.
Definition: framesync.h:165
static int process_frame(FFFrameSync *fs)
Definition: vf_remap.c:278
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:65
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:376
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:386
#define src
Definition: vp9dsp.c:530
void * opaque
Opaque pointer, not used by the API.
Definition: framesync.h:180
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:340
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:359
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:480
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:376
static const AVOption remap_options[]
Definition: vf_remap.c:63
Extend the frame to infinity.
Definition: framesync.h:77
static const int remap[16]
Definition: msvideo1enc.c:63
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:215
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:49
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
const char * name
Filter name.
Definition: avfilter.h:148
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:319
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:189
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:358
static int flags
Definition: cpu.c:47
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:348
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
static void remap_planar16(RemapContext *s, const AVFrame *in, const AVFrame *xin, const AVFrame *yin, AVFrame *out)
Definition: vf_remap.c:152
static const AVFilterPad remap_outputs[]
Definition: vf_remap.c:395
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:229
static double c[64]
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:373
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:67
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:307
int height
Definition: frame.h:236
FILE * out
Definition: movenc.c:54
#define av_freep(p)
static const AVFilterPad remap_inputs[]
Definition: vf_remap.c:375
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:229
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:589
int * formats
list of media formats
Definition: formats.h:66