FFmpeg  4.3
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/colorspace.h"
40 #include "libavutil/imgutils.h"
41 #include "libavutil/pixdesc.h"
42 #include "libavutil/opt.h"
43 #include "avfilter.h"
44 #include "drawutils.h"
45 #include "formats.h"
46 #include "framesync.h"
47 #include "internal.h"
48 #include "video.h"
49 
50 typedef struct RemapContext {
51  const AVClass *class;
52  int format;
53 
54  int nb_planes;
56  int step;
58  int fill_color[4];
59 
61 
62  int (*remap_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
63 } RemapContext;
64 
65 #define OFFSET(x) offsetof(RemapContext, x)
66 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
67 
68 static const AVOption remap_options[] = {
69  { "format", "set output format", OFFSET(format), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "format" },
70  { "color", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, .flags = FLAGS, .unit = "format" },
71  { "gray", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, .flags = FLAGS, .unit = "format" },
72  { "fill", "set the color of the unmapped pixels", OFFSET(fill_rgba), AV_OPT_TYPE_COLOR, {.str="black"}, .flags = FLAGS },
73  { NULL }
74 };
75 
77 
78 typedef struct ThreadData {
79  AVFrame *in, *xin, *yin, *out;
80  int nb_planes;
82  int step;
83 } ThreadData;
84 
86 {
87  RemapContext *s = ctx->priv;
88  static const enum AVPixelFormat pix_fmts[] = {
104  };
105  static const enum AVPixelFormat gray_pix_fmts[] = {
109  AV_PIX_FMT_NONE
110  };
111  static const enum AVPixelFormat map_fmts[] = {
113  AV_PIX_FMT_NONE
114  };
115  AVFilterFormats *pix_formats = NULL, *map_formats = NULL;
116  int ret;
117 
118  if (!(pix_formats = ff_make_format_list(s->format ? gray_pix_fmts : pix_fmts)) ||
119  !(map_formats = ff_make_format_list(map_fmts))) {
120  ret = AVERROR(ENOMEM);
121  goto fail;
122  }
123  if ((ret = ff_formats_ref(pix_formats, &ctx->inputs[0]->out_formats)) < 0 ||
124  (ret = ff_formats_ref(map_formats, &ctx->inputs[1]->out_formats)) < 0 ||
125  (ret = ff_formats_ref(map_formats, &ctx->inputs[2]->out_formats)) < 0 ||
126  (ret = ff_formats_ref(pix_formats, &ctx->outputs[0]->in_formats)) < 0)
127  goto fail;
128  return 0;
129 fail:
130  if (pix_formats)
131  av_freep(&pix_formats->formats);
132  av_freep(&pix_formats);
133  if (map_formats)
134  av_freep(&map_formats->formats);
135  av_freep(&map_formats);
136  return ret;
137 }
138 
139 /**
140  * remap_planar algorithm expects planes of same size
141  * pixels are copied from source to target using :
142  * Target_frame[y][x] = Source_frame[ ymap[y][x] ][ [xmap[y][x] ];
143  */
144 #define DEFINE_REMAP_PLANAR_FUNC(name, bits, div) \
145 static int remap_planar##bits##_##name##_slice(AVFilterContext *ctx, void *arg, \
146  int jobnr, int nb_jobs) \
147 { \
148  RemapContext *s = ctx->priv; \
149  const ThreadData *td = arg; \
150  const AVFrame *in = td->in; \
151  const AVFrame *xin = td->xin; \
152  const AVFrame *yin = td->yin; \
153  const AVFrame *out = td->out; \
154  const int slice_start = (out->height * jobnr ) / nb_jobs; \
155  const int slice_end = (out->height * (jobnr+1)) / nb_jobs; \
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 < td->nb_planes ; plane++) { \
161  const int dlinesize = out->linesize[plane] / div; \
162  const uint##bits##_t *src = (const uint##bits##_t *)in->data[plane]; \
163  uint##bits##_t *dst = (uint##bits##_t *)out->data[plane] + slice_start * dlinesize; \
164  const int slinesize = in->linesize[plane] / div; \
165  const uint16_t *xmap = (const uint16_t *)xin->data[0] + slice_start * xlinesize; \
166  const uint16_t *ymap = (const uint16_t *)yin->data[0] + slice_start * ylinesize; \
167  const int color = s->fill_color[plane]; \
168  \
169  for (y = slice_start; y < slice_end; y++) { \
170  for (x = 0; x < out->width; x++) { \
171  if (ymap[x] < in->height && xmap[x] < in->width) { \
172  dst[x] = src[ymap[x] * slinesize + xmap[x]]; \
173  } else { \
174  dst[x] = color; \
175  } \
176  } \
177  dst += dlinesize; \
178  xmap += xlinesize; \
179  ymap += ylinesize; \
180  } \
181  } \
182  \
183  return 0; \
184 }
185 
186 DEFINE_REMAP_PLANAR_FUNC(nearest, 8, 1)
187 DEFINE_REMAP_PLANAR_FUNC(nearest, 16, 2)
188 
189 /**
190  * remap_packed algorithm expects pixels with both padded bits (step) and
191  * number of components correctly set.
192  * pixels are copied from source to target using :
193  * Target_frame[y][x] = Source_frame[ ymap[y][x] ][ [xmap[y][x] ];
194  */
195 #define DEFINE_REMAP_PACKED_FUNC(name, bits, div) \
196 static int remap_packed##bits##_##name##_slice(AVFilterContext *ctx, void *arg, \
197  int jobnr, int nb_jobs) \
198 { \
199  RemapContext *s = ctx->priv; \
200  const ThreadData *td = arg; \
201  const AVFrame *in = td->in; \
202  const AVFrame *xin = td->xin; \
203  const AVFrame *yin = td->yin; \
204  const AVFrame *out = td->out; \
205  const int slice_start = (out->height * jobnr ) / nb_jobs; \
206  const int slice_end = (out->height * (jobnr+1)) / nb_jobs; \
207  const int dlinesize = out->linesize[0] / div; \
208  const int slinesize = in->linesize[0] / div; \
209  const int xlinesize = xin->linesize[0] / 2; \
210  const int ylinesize = yin->linesize[0] / 2; \
211  const uint##bits##_t *src = (const uint##bits##_t *)in->data[0]; \
212  uint##bits##_t *dst = (uint##bits##_t *)out->data[0] + slice_start * dlinesize; \
213  const uint16_t *xmap = (const uint16_t *)xin->data[0] + slice_start * xlinesize; \
214  const uint16_t *ymap = (const uint16_t *)yin->data[0] + slice_start * ylinesize; \
215  const int step = td->step / div; \
216  int c, x, y; \
217  \
218  for (y = slice_start; y < slice_end; y++) { \
219  for (x = 0; x < out->width; x++) { \
220  for (c = 0; c < td->nb_components; c++) { \
221  if (ymap[x] < in->height && xmap[x] < in->width) { \
222  dst[x * step + c] = src[ymap[x] * slinesize + xmap[x] * step + c]; \
223  } else { \
224  dst[x * step + c] = s->fill_color[c]; \
225  } \
226  } \
227  } \
228  dst += dlinesize; \
229  xmap += xlinesize; \
230  ymap += ylinesize; \
231  } \
232  \
233  return 0; \
234 }
235 
236 DEFINE_REMAP_PACKED_FUNC(nearest, 8, 1)
237 DEFINE_REMAP_PACKED_FUNC(nearest, 16, 2)
238 
239 static int config_input(AVFilterLink *inlink)
240 {
241  AVFilterContext *ctx = inlink->dst;
242  RemapContext *s = ctx->priv;
243  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
244  int depth = desc->comp[0].depth;
245  int is_rgb = !!(desc->flags & AV_PIX_FMT_FLAG_RGB);
246  int factor = 1 << (depth - 8);
247  uint8_t rgba_map[4];
248 
249  ff_fill_rgba_map(rgba_map, inlink->format);
250  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
251  s->nb_components = desc->nb_components;
252 
253  if (is_rgb) {
254  s->fill_color[rgba_map[0]] = s->fill_rgba[0] * factor;
255  s->fill_color[rgba_map[1]] = s->fill_rgba[1] * factor;
256  s->fill_color[rgba_map[2]] = s->fill_rgba[2] * factor;
257  s->fill_color[rgba_map[3]] = s->fill_rgba[3] * factor;
258  } else {
259  s->fill_color[0] = RGB_TO_Y_BT709(s->fill_rgba[0], s->fill_rgba[1], s->fill_rgba[2]) * factor;
260  s->fill_color[1] = RGB_TO_U_BT709(s->fill_rgba[0], s->fill_rgba[1], s->fill_rgba[2], 0) * factor;
261  s->fill_color[2] = RGB_TO_V_BT709(s->fill_rgba[0], s->fill_rgba[1], s->fill_rgba[2], 0) * factor;
262  s->fill_color[3] = s->fill_rgba[3] * factor;
263  }
264 
265  if (depth == 8) {
266  if (s->nb_planes > 1 || s->nb_components == 1) {
267  s->remap_slice = remap_planar8_nearest_slice;
268  } else {
269  s->remap_slice = remap_packed8_nearest_slice;
270  }
271  } else {
272  if (s->nb_planes > 1 || s->nb_components == 1) {
273  s->remap_slice = remap_planar16_nearest_slice;
274  } else {
275  s->remap_slice = remap_packed16_nearest_slice;
276  }
277  }
278 
279  s->step = av_get_padded_bits_per_pixel(desc) >> 3;
280  return 0;
281 }
282 
284 {
285  AVFilterContext *ctx = fs->parent;
286  RemapContext *s = fs->opaque;
287  AVFilterLink *outlink = ctx->outputs[0];
288  AVFrame *out, *in, *xpic, *ypic;
289  int ret;
290 
291  if ((ret = ff_framesync_get_frame(&s->fs, 0, &in, 0)) < 0 ||
292  (ret = ff_framesync_get_frame(&s->fs, 1, &xpic, 0)) < 0 ||
293  (ret = ff_framesync_get_frame(&s->fs, 2, &ypic, 0)) < 0)
294  return ret;
295 
296  if (ctx->is_disabled) {
297  out = av_frame_clone(in);
298  if (!out)
299  return AVERROR(ENOMEM);
300  } else {
301  ThreadData td;
302 
303  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
304  if (!out)
305  return AVERROR(ENOMEM);
306  av_frame_copy_props(out, in);
307 
308  td.in = in;
309  td.xin = xpic;
310  td.yin = ypic;
311  td.out = out;
312  td.nb_planes = s->nb_planes;
314  td.step = s->step;
315  ctx->internal->execute(ctx, s->remap_slice, &td, NULL, FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
316  }
317  out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base);
318 
319  return ff_filter_frame(outlink, out);
320 }
321 
322 static int config_output(AVFilterLink *outlink)
323 {
324  AVFilterContext *ctx = outlink->src;
325  RemapContext *s = ctx->priv;
326  AVFilterLink *srclink = ctx->inputs[0];
327  AVFilterLink *xlink = ctx->inputs[1];
328  AVFilterLink *ylink = ctx->inputs[2];
329  FFFrameSyncIn *in;
330  int ret;
331 
332  if (xlink->w != ylink->w || xlink->h != ylink->h) {
333  av_log(ctx, AV_LOG_ERROR, "Second input link %s parameters "
334  "(size %dx%d) do not match the corresponding "
335  "third input link %s parameters (%dx%d)\n",
336  ctx->input_pads[1].name, xlink->w, xlink->h,
337  ctx->input_pads[2].name, ylink->w, ylink->h);
338  return AVERROR(EINVAL);
339  }
340 
341  outlink->w = xlink->w;
342  outlink->h = xlink->h;
343  outlink->sample_aspect_ratio = srclink->sample_aspect_ratio;
344  outlink->frame_rate = srclink->frame_rate;
345 
346  ret = ff_framesync_init(&s->fs, ctx, 3);
347  if (ret < 0)
348  return ret;
349 
350  in = s->fs.in;
351  in[0].time_base = srclink->time_base;
352  in[1].time_base = xlink->time_base;
353  in[2].time_base = ylink->time_base;
354  in[0].sync = 2;
355  in[0].before = EXT_STOP;
356  in[0].after = EXT_STOP;
357  in[1].sync = 1;
358  in[1].before = EXT_NULL;
359  in[1].after = EXT_INFINITY;
360  in[2].sync = 1;
361  in[2].before = EXT_NULL;
362  in[2].after = EXT_INFINITY;
363  s->fs.opaque = s;
365 
366  ret = ff_framesync_configure(&s->fs);
367  outlink->time_base = s->fs.time_base;
368 
369  return ret;
370 }
371 
373 {
374  RemapContext *s = ctx->priv;
375  return ff_framesync_activate(&s->fs);
376 }
377 
379 {
380  RemapContext *s = ctx->priv;
381 
382  ff_framesync_uninit(&s->fs);
383 }
384 
385 static const AVFilterPad remap_inputs[] = {
386  {
387  .name = "source",
388  .type = AVMEDIA_TYPE_VIDEO,
389  .config_props = config_input,
390  },
391  {
392  .name = "xmap",
393  .type = AVMEDIA_TYPE_VIDEO,
394  },
395  {
396  .name = "ymap",
397  .type = AVMEDIA_TYPE_VIDEO,
398  },
399  { NULL }
400 };
401 
402 static const AVFilterPad remap_outputs[] = {
403  {
404  .name = "default",
405  .type = AVMEDIA_TYPE_VIDEO,
406  .config_props = config_output,
407  },
408  { NULL }
409 };
410 
412  .name = "remap",
413  .description = NULL_IF_CONFIG_SMALL("Remap pixels."),
414  .priv_size = sizeof(RemapContext),
415  .uninit = uninit,
417  .activate = activate,
418  .inputs = remap_inputs,
419  .outputs = remap_outputs,
420  .priv_class = &remap_class,
422 };
#define NULL
Definition: coverity.c:32
AVFrame * out
Definition: af_adeclick.c:494
#define RGB_TO_Y_BT709(r, g, b)
Definition: colorspace.h:126
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2549
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
int nb_components
Definition: vf_remap.c:55
#define DEFINE_REMAP_PACKED_FUNC(name, bits, div)
remap_packed algorithm expects pixels with both padded bits (step) and number of components correctly...
Definition: vf_remap.c:195
AVOption.
Definition: opt.h:246
AVFilter ff_vf_remap
Definition: vf_remap.c:411
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:407
AVFILTER_DEFINE_CLASS(remap)
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:417
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
misc image utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2589
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
const char * desc
Definition: nvenc.c:79
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:387
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:413
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:392
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:377
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
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:385
int64_t pts
Timestamp of the current event.
Definition: framesync.h:167
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:378
#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
int nb_planes
Definition: vf_remap.c:80
int fill_color[4]
Definition: vf_remap.c:58
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:379
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
int(* remap_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_remap.c:62
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1075
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:88
AVOptions.
static int config_input(AVFilterLink *inlink)
Definition: vf_remap.c:239
AVFrame * yin
Definition: vf_remap.c:79
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:393
#define RGB_TO_V_BT709(r1, g1, b1, shift)
Definition: colorspace.h:134
FFFrameSyncIn * in
Pointer to array of inputs.
Definition: framesync.h:203
#define FLAGS
Definition: vf_remap.c:66
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:412
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
#define OFFSET(x)
Definition: vf_remap.c:65
static int activate(AVFilterContext *ctx)
Definition: vf_remap.c:372
static int query_formats(AVFilterContext *ctx)
Definition: vf_remap.c:85
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:388
AVFrame * xin
Definition: vf_remap.c:79
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:410
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:322
#define av_log(a,...)
#define RGB_TO_U_BT709(r1, g1, b1, shift)
Definition: colorspace.h:130
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
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define td
Definition: regdef.h:70
Various defines for YUV<->RGB conversion.
int step
Definition: vf_remap.c:82
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:283
Frame sync structure.
Definition: framesync.h:146
#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
static enum AVPixelFormat gray_pix_fmts[]
Definition: jpeg2000dec.c:253
#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:95
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:2514
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:116
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:441
const char * arg
Definition: jacosubdec.c:66
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:418
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:383
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:334
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:400
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:92
#define fail()
Definition: checkasm.h:123
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:419
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
FFFrameSync fs
Definition: vf_remap.c:60
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:416
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:784
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:381
#define FFMIN(a, b)
Definition: common.h:96
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:438
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:470
int nb_planes
Definition: vf_remap.c:54
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_remap.c:378
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:283
#define s(width, name)
Definition: cbs_vp9.c:257
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:436
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:396
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:415
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:541
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:35
#define DEFINE_REMAP_PLANAR_FUNC(name, bits, div)
remap_planar algorithm expects planes of same size pixels are copied from source to target using : Ta...
Definition: vf_remap.c:144
static const AVOption remap_options[]
Definition: vf_remap.c:68
Extend the frame to infinity.
Definition: framesync.h:75
misc drawing utilities
static const int remap[16]
Definition: msvideo1enc.c:63
Used for passing data between threads.
Definition: dsddec.c:67
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:177
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:380
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
uint8_t fill_rgba[4]
Definition: vf_remap.c:57
Ignore this stream and continue processing the other ones.
Definition: framesync.h:70
static const int factor[16]
Definition: vf_pp7.c:75
const char * name
Filter name.
Definition: avfilter.h:148
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:414
#define flags(name, subs,...)
Definition: cbs_av1.c:564
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:378
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:404
int
static const AVFilterPad remap_outputs[]
Definition: vf_remap.c:402
Y , 8bpp.
Definition: pixfmt.h:74
int format
Definition: vf_remap.c:52
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:433
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
avfilter_execute_func * execute
Definition: internal.h:144
int nb_components
Definition: vf_remap.c:81
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
FILE * out
Definition: movenc.c:54
#define av_freep(p)
static const AVFilterPad remap_inputs[]
Definition: vf_remap.c:385
AVFrame * in
Definition: af_afftdn.c:1083
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:246
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:659
int * formats
list of media formats
Definition: formats.h:66