FFmpeg  4.0
vf_lut2.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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/attributes.h"
22 #include "libavutil/common.h"
23 #include "libavutil/eval.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/pixdesc.h"
26 #include "avfilter.h"
27 #include "drawutils.h"
28 #include "formats.h"
29 #include "internal.h"
30 #include "video.h"
31 #include "framesync.h"
32 
33 static const char *const var_names[] = {
34  "w", ///< width of the input video
35  "h", ///< height of the input video
36  "x", ///< input value for the pixel from input #1
37  "y", ///< input value for the pixel from input #2
38  "bdx", ///< input #1 video bitdepth
39  "bdy", ///< input #2 video bitdepth
40  NULL
41 };
42 
43 enum var_name {
51 };
52 
53 typedef struct LUT2Context {
54  const AVClass *class;
56 
57  char *comp_expr_str[4];
58 
61  uint16_t *lut[4]; ///< lookup table for each component
62  int width[4], height[4];
63  int nb_planes;
65  int tlut2;
66  AVFrame *prev_frame; /* only used with tlut2 */
67 
68  void (*lut2)(struct LUT2Context *s, AVFrame *dst, AVFrame *srcx, AVFrame *srcy);
69 
70 } LUT2Context;
71 
72 #define OFFSET(x) offsetof(LUT2Context, x)
73 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
74 
75 static const AVOption options[] = {
76  { "c0", "set component #0 expression", OFFSET(comp_expr_str[0]), AV_OPT_TYPE_STRING, { .str = "x" }, .flags = FLAGS },
77  { "c1", "set component #1 expression", OFFSET(comp_expr_str[1]), AV_OPT_TYPE_STRING, { .str = "x" }, .flags = FLAGS },
78  { "c2", "set component #2 expression", OFFSET(comp_expr_str[2]), AV_OPT_TYPE_STRING, { .str = "x" }, .flags = FLAGS },
79  { "c3", "set component #3 expression", OFFSET(comp_expr_str[3]), AV_OPT_TYPE_STRING, { .str = "x" }, .flags = FLAGS },
80  { NULL }
81 };
82 
84 {
85  LUT2Context *s = ctx->priv;
86  int i;
87 
90 
91  for (i = 0; i < 4; i++) {
92  av_expr_free(s->comp_expr[i]);
93  s->comp_expr[i] = NULL;
94  av_freep(&s->comp_expr_str[i]);
95  av_freep(&s->lut[i]);
96  }
97 }
98 
100 {
101  static const enum AVPixelFormat pix_fmts[] = {
117  };
118 
119  return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
120 }
121 
122 static int config_inputx(AVFilterLink *inlink)
123 {
124  AVFilterContext *ctx = inlink->dst;
125  LUT2Context *s = ctx->priv;
127  int hsub = desc->log2_chroma_w;
128  int vsub = desc->log2_chroma_h;
129 
131  s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
132  s->height[0] = s->height[3] = inlink->h;
133  s->width[1] = s->width[2] = AV_CEIL_RSHIFT(inlink->w, hsub);
134  s->width[0] = s->width[3] = inlink->w;
135 
136  s->var_values[VAR_W] = inlink->w;
137  s->var_values[VAR_H] = inlink->h;
138  s->depthx = desc->comp[0].depth;
140 
141  if (s->tlut2) {
142  s->depthy = desc->comp[0].depth;
144  }
145 
146  return 0;
147 }
148 
149 static int config_inputy(AVFilterLink *inlink)
150 {
151  AVFilterContext *ctx = inlink->dst;
152  LUT2Context *s = ctx->priv;
154 
155  s->depthy = desc->comp[0].depth;
157 
158  return 0;
159 }
160 
161 static void lut2_8bit(struct LUT2Context *s, AVFrame *out, AVFrame *srcx, AVFrame *srcy)
162 {
163  int p, y, x;
164 
165  for (p = 0; p < s->nb_planes; p++) {
166  const uint16_t *lut = s->lut[p];
167  const uint8_t *srcxx, *srcyy;
168  uint8_t *dst;
169 
170  dst = out->data[p];
171  srcxx = srcx->data[p];
172  srcyy = srcy->data[p];
173 
174  for (y = 0; y < s->height[p]; y++) {
175  for (x = 0; x < s->width[p]; x++) {
176  dst[x] = lut[(srcyy[x] << s->depthx) | srcxx[x]];
177  }
178 
179  dst += out->linesize[p];
180  srcxx += srcx->linesize[p];
181  srcyy += srcy->linesize[p];
182  }
183  }
184 }
185 
186 static void lut2_16bit(struct LUT2Context *s, AVFrame *out, AVFrame *srcx, AVFrame *srcy)
187 {
188  int p, y, x;
189 
190  for (p = 0; p < s->nb_planes; p++) {
191  const uint16_t *lut = s->lut[p];
192  const uint16_t *srcxx, *srcyy;
193  uint16_t *dst;
194 
195  dst = (uint16_t *)out->data[p];
196  srcxx = (uint16_t *)srcx->data[p];
197  srcyy = (uint16_t *)srcy->data[p];
198 
199  for (y = 0; y < s->height[p]; y++) {
200  for (x = 0; x < s->width[p]; x++) {
201  dst[x] = lut[(srcyy[x] << s->depthx) | srcxx[x]];
202  }
203 
204  dst += out->linesize[p] / 2;
205  srcxx += srcx->linesize[p] / 2;
206  srcyy += srcy->linesize[p] / 2;
207  }
208  }
209 }
210 
212 {
213  AVFilterContext *ctx = fs->parent;
214  LUT2Context *s = fs->opaque;
215  AVFilterLink *outlink = ctx->outputs[0];
216  AVFrame *out, *srcx = NULL, *srcy = NULL;
217  int ret;
218 
219  if ((ret = ff_framesync_get_frame(&s->fs, 0, &srcx, 0)) < 0 ||
220  (ret = ff_framesync_get_frame(&s->fs, 1, &srcy, 0)) < 0)
221  return ret;
222 
223  if (ctx->is_disabled || !srcy) {
224  out = av_frame_clone(srcx);
225  if (!out)
226  return AVERROR(ENOMEM);
227  } else {
228  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
229  if (!out)
230  return AVERROR(ENOMEM);
231  av_frame_copy_props(out, srcx);
232 
233  s->lut2(s, out, srcx, srcy);
234  }
235 
236  out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base);
237 
238  return ff_filter_frame(outlink, out);
239 }
240 
241 static int config_output(AVFilterLink *outlink)
242 {
243  AVFilterContext *ctx = outlink->src;
244  LUT2Context *s = ctx->priv;
245  int p, ret;
246 
247  s->depth = s->depthx + s->depthy;
248 
249  s->lut2 = s->depth > 16 ? lut2_16bit : lut2_8bit;
250 
251  for (p = 0; p < s->nb_planes; p++) {
252  s->lut[p] = av_malloc_array(1 << s->depth, sizeof(uint16_t));
253  if (!s->lut[p])
254  return AVERROR(ENOMEM);
255  }
256 
257  for (p = 0; p < s->nb_planes; p++) {
258  double res;
259  int x, y;
260 
261  /* create the parsed expression */
262  av_expr_free(s->comp_expr[p]);
263  s->comp_expr[p] = NULL;
264  ret = av_expr_parse(&s->comp_expr[p], s->comp_expr_str[p],
265  var_names, NULL, NULL, NULL, NULL, 0, ctx);
266  if (ret < 0) {
267  av_log(ctx, AV_LOG_ERROR,
268  "Error when parsing the expression '%s' for the component %d.\n",
269  s->comp_expr_str[p], p);
270  return AVERROR(EINVAL);
271  }
272 
273  /* compute the lut */
274  for (y = 0; y < (1 << s->depthx); y++) {
275  s->var_values[VAR_Y] = y;
276  for (x = 0; x < (1 << s->depthx); x++) {
277  s->var_values[VAR_X] = x;
278  res = av_expr_eval(s->comp_expr[p], s->var_values, s);
279  if (isnan(res)) {
280  av_log(ctx, AV_LOG_ERROR,
281  "Error when evaluating the expression '%s' for the values %d and %d for the component %d.\n",
282  s->comp_expr_str[p], x, y, p);
283  return AVERROR(EINVAL);
284  }
285 
286  s->lut[p][(y << s->depthx) + x] = res;
287  }
288  }
289  }
290 
291  return 0;
292 }
293 
294 static int lut2_config_output(AVFilterLink *outlink)
295 {
296  AVFilterContext *ctx = outlink->src;
297  LUT2Context *s = ctx->priv;
298  AVFilterLink *srcx = ctx->inputs[0];
299  AVFilterLink *srcy = ctx->inputs[1];
300  FFFrameSyncIn *in;
301  int ret;
302 
303  if (srcx->format != srcy->format) {
304  av_log(ctx, AV_LOG_ERROR, "inputs must be of same pixel format\n");
305  return AVERROR(EINVAL);
306  }
307  if (srcx->w != srcy->w || srcx->h != srcy->h) {
308  av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
309  "(size %dx%d) do not match the corresponding "
310  "second input link %s parameters (size %dx%d)\n",
311  ctx->input_pads[0].name, srcx->w, srcx->h,
312  ctx->input_pads[1].name,
313  srcy->w, srcy->h);
314  return AVERROR(EINVAL);
315  }
316 
317  outlink->w = srcx->w;
318  outlink->h = srcx->h;
319  outlink->time_base = srcx->time_base;
320  outlink->sample_aspect_ratio = srcx->sample_aspect_ratio;
321  outlink->frame_rate = srcx->frame_rate;
322 
323  if ((ret = ff_framesync_init(&s->fs, ctx, 2)) < 0)
324  return ret;
325 
326  in = s->fs.in;
327  in[0].time_base = srcx->time_base;
328  in[1].time_base = srcy->time_base;
329  in[0].sync = 2;
330  in[0].before = EXT_STOP;
331  in[0].after = EXT_INFINITY;
332  in[1].sync = 1;
333  in[1].before = EXT_STOP;
334  in[1].after = EXT_INFINITY;
335  s->fs.opaque = s;
337 
338  if ((ret = config_output(outlink)) < 0)
339  return ret;
340 
341  return ff_framesync_configure(&s->fs);
342 }
343 
345 {
346  LUT2Context *s = ctx->priv;
347  return ff_framesync_activate(&s->fs);
348 }
349 
350 static const AVFilterPad inputs[] = {
351  {
352  .name = "srcx",
353  .type = AVMEDIA_TYPE_VIDEO,
354  .config_props = config_inputx,
355  },
356  {
357  .name = "srcy",
358  .type = AVMEDIA_TYPE_VIDEO,
359  .config_props = config_inputy,
360  },
361  { NULL }
362 };
363 
364 static const AVFilterPad outputs[] = {
365  {
366  .name = "default",
367  .type = AVMEDIA_TYPE_VIDEO,
368  .config_props = lut2_config_output,
369  },
370  { NULL }
371 };
372 
373 #define lut2_options options
374 
376 
378  .name = "lut2",
379  .description = NULL_IF_CONFIG_SMALL("Compute and apply a lookup table from two video inputs."),
380  .preinit = lut2_framesync_preinit,
381  .priv_size = sizeof(LUT2Context),
382  .priv_class = &lut2_class,
383  .uninit = uninit,
385  .activate = activate,
386  .inputs = inputs,
387  .outputs = outputs,
389 };
390 
391 #if CONFIG_TLUT2_FILTER
392 
393 static av_cold int init(AVFilterContext *ctx)
394 {
395  LUT2Context *s = ctx->priv;
396 
397  s->tlut2 = !strcmp(ctx->filter->name, "tlut2");
398 
399  return 0;
400 }
401 
402 static int tlut2_filter_frame(AVFilterLink *inlink, AVFrame *frame)
403 {
404  LUT2Context *s = inlink->dst->priv;
405  AVFilterLink *outlink = inlink->dst->outputs[0];
406 
407  if (s->prev_frame) {
408  AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
409  if (!out) {
411  s->prev_frame = frame;
412  return AVERROR(ENOMEM);
413  }
414  av_frame_copy_props(out, frame);
415  s->lut2(s, out, frame, s->prev_frame);
417  s->prev_frame = frame;
418  return ff_filter_frame(outlink, out);
419  }
420  s->prev_frame = frame;
421  return 0;
422 }
423 
424 #define tlut2_options options
425 
427 
428 static const AVFilterPad tlut2_inputs[] = {
429  {
430  .name = "default",
431  .type = AVMEDIA_TYPE_VIDEO,
432  .filter_frame = tlut2_filter_frame,
433  .config_props = config_inputx,
434  },
435  { NULL }
436 };
437 
438 static const AVFilterPad tlut2_outputs[] = {
439  {
440  .name = "default",
441  .type = AVMEDIA_TYPE_VIDEO,
442  .config_props = config_output,
443  },
444  { NULL }
445 };
446 
448  .name = "tlut2",
449  .description = NULL_IF_CONFIG_SMALL("Compute and apply a lookup table from two successive frames."),
450  .priv_size = sizeof(LUT2Context),
451  .priv_class = &tlut2_class,
453  .init = init,
454  .uninit = uninit,
455  .inputs = tlut2_inputs,
456  .outputs = tlut2_outputs,
457 };
458 
459 #endif
#define NULL
Definition: coverity.c:32
AVFilter ff_vf_tlut2
const char * s
Definition: avisynth_c.h:768
static int config_inputx(AVFilterLink *inlink)
Definition: vf_lut2.c:122
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:401
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
AVOption.
Definition: opt.h:246
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:403
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:388
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:404
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2403
Main libavfilter public API header.
static int config_output(AVFilterLink *outlink)
Definition: vf_lut2.c:241
const char * desc
Definition: nvenc.c:65
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:164
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:384
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:349
FRAMESYNC_DEFINE_CLASS(lut2, LUT2Context, fs)
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:372
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:117
int nb_planes
Definition: vf_lut2.c:63
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:679
int depth
Definition: vf_lut2.c:64
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
static void lut2_8bit(struct LUT2Context *s, AVFrame *out, AVFrame *srcx, AVFrame *srcy)
Definition: vf_lut2.c:161
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
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
Macro definitions for various function/variable attributes.
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
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
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
static int query_formats(AVFilterContext *ctx)
Definition: vf_lut2.c:99
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:97
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
FFFrameSync fs
Definition: vf_lut2.c:55
#define av_cold
Definition: attributes.h:82
AVOptions.
void(* lut2)(struct LUT2Context *s, AVFrame *dst, AVFrame *srcx, AVFrame *srcy)
Definition: vf_lut2.c:68
Definition: vf_lut2.c:47
double var_values[VAR_VARS_NB]
Definition: vf_lut2.c:60
#define FLAGS
Definition: vf_lut2.c:73
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:311
Definition: eval.c:157
FFFrameSyncIn * in
Pointer to array of inputs.
Definition: framesync.h:203
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:400
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:383
static int process_frame(FFFrameSync *fs)
Definition: vf_lut2.c:211
static AVFrame * frame
Definition: vf_lut2.c:45
static const AVFilterPad outputs[]
Definition: vf_lut2.c:364
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:96
static int flags
Definition: log.c:55
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:75
Definition: vf_lut2.c:46
AVFrame * prev_frame
Definition: vf_lut2.c:66
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:91
Input stream structure.
Definition: framesync.h:81
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:373
int depthy
Definition: vf_lut2.c:64
#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
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:172
#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
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:293
int width[4]
Definition: vf_lut2.c:62
Frame sync structure.
Definition: framesync.h:146
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
void * priv
private data for use by the filter
Definition: avfilter.h:353
int depthx
Definition: vf_lut2.c:64
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:389
uint16_t * lut[4]
lookup table for each component
Definition: vf_lut2.c:61
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
AVFilter ff_vf_lut2
Definition: vf_lut2.c:377
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
var_name
Definition: aeval.c:46
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:366
static int activate(AVFilterContext *ctx)
Definition: vf_lut2.c:344
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:74
Definition: vf_lut2.c:44
AVFormatContext * ctx
Definition: movenc.c:48
AVRational time_base
Time base for the output events.
Definition: framesync.h:162
int height[4]
Definition: vf_lut2.c:62
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:405
void * opaque
Opaque pointer, not used by the API.
Definition: framesync.h:177
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:367
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:538
static int lut2_config_output(AVFilterLink *outlink)
Definition: vf_lut2.c:294
static int config_inputy(AVFilterLink *inlink)
Definition: vf_lut2.c:149
Extend the frame to infinity.
Definition: framesync.h:75
misc drawing utilities
typedef void(RENAME(mix_any_func_type))
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:334
static const AVFilterPad inputs[]
Definition: vf_lut2.c:350
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
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:368
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:139
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
#define isnan(x)
Definition: libm.h:340
const char * name
Filter name.
Definition: avfilter.h:148
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:374
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:365
#define OFFSET(x)
Definition: vf_lut2.c:72
#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
static const AVOption options[]
Definition: vf_lut2.c:75
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
static void lut2_16bit(struct LUT2Context *s, AVFrame *out, AVFrame *srcx, AVFrame *srcy)
Definition: vf_lut2.c:186
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:385
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:369
#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
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
Y , 8bpp.
Definition: pixfmt.h:70
common internal and external API header
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_lut2.c:83
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:211
#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
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:69
Completely stop all streams with this one.
Definition: framesync.h:65
int tlut2
Definition: vf_lut2.c:65
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:734
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:334
static const char *const var_names[]
Definition: vf_lut2.c:33
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:254
AVExpr * comp_expr[4]
Definition: vf_lut2.c:59
An instance of a filter.
Definition: avfilter.h:338
char * comp_expr_str[4]
Definition: vf_lut2.c:57
FILE * out
Definition: movenc.c:54
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:95
#define av_malloc_array(a, b)
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
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:341
for(j=16;j >0;--j)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:652
simple arithmetic expression evaluator
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58