FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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;
55 
56  char *comp_expr_str[4];
57 
60  uint16_t *lut[4]; ///< lookup table for each component
61  int width[4], height[4];
62  int nb_planes;
64 
65  void (*lut2)(struct LUT2Context *s, AVFrame *dst, AVFrame *srcx, AVFrame *srcy);
66 
68 } LUT2Context;
69 
70 #define OFFSET(x) offsetof(LUT2Context, x)
71 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
72 
73 static const AVOption lut2_options[] = {
74  { "c0", "set component #0 expression", OFFSET(comp_expr_str[0]), AV_OPT_TYPE_STRING, { .str = "x" }, .flags = FLAGS },
75  { "c1", "set component #1 expression", OFFSET(comp_expr_str[1]), AV_OPT_TYPE_STRING, { .str = "x" }, .flags = FLAGS },
76  { "c2", "set component #2 expression", OFFSET(comp_expr_str[2]), AV_OPT_TYPE_STRING, { .str = "x" }, .flags = FLAGS },
77  { "c3", "set component #3 expression", OFFSET(comp_expr_str[3]), AV_OPT_TYPE_STRING, { .str = "x" }, .flags = FLAGS },
78  { NULL }
79 };
80 
82 {
83  LUT2Context *s = ctx->priv;
84  int i;
85 
86  for (i = 0; i < 4; i++) {
87  av_expr_free(s->comp_expr[i]);
88  s->comp_expr[i] = NULL;
89  av_freep(&s->comp_expr_str[i]);
90  av_freep(&s->lut[i]);
91  }
92 }
93 
95 {
96  static const enum AVPixelFormat pix_fmts[] = {
112  };
113 
114  return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
115 }
116 
117 static int config_inputx(AVFilterLink *inlink)
118 {
119  AVFilterContext *ctx = inlink->dst;
120  LUT2Context *s = ctx->priv;
122  int hsub = desc->log2_chroma_w;
123  int vsub = desc->log2_chroma_h;
124 
126  s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
127  s->height[0] = s->height[3] = inlink->h;
128  s->width[1] = s->width[2] = AV_CEIL_RSHIFT(inlink->w, hsub);
129  s->width[0] = s->width[3] = inlink->w;
130 
131  s->var_values[VAR_W] = inlink->w;
132  s->var_values[VAR_H] = inlink->h;
133  s->depthx = desc->comp[0].depth;
135 
136  return 0;
137 }
138 
139 static int config_inputy(AVFilterLink *inlink)
140 {
141  AVFilterContext *ctx = inlink->dst;
142  LUT2Context *s = ctx->priv;
144 
145  s->depthy = desc->comp[0].depth;
147 
148  return 0;
149 }
150 
151 static void lut2_8bit(struct LUT2Context *s, AVFrame *out, AVFrame *srcx, AVFrame *srcy)
152 {
153  int p, y, x;
154 
155  for (p = 0; p < s->nb_planes; p++) {
156  const uint16_t *lut = s->lut[p];
157  const uint8_t *srcxx, *srcyy;
158  uint8_t *dst;
159 
160  dst = out->data[p];
161  srcxx = srcx->data[p];
162  srcyy = srcy->data[p];
163 
164  for (y = 0; y < s->height[p]; y++) {
165  for (x = 0; x < s->width[p]; x++) {
166  dst[x] = lut[(srcyy[x] << s->depthx) | srcxx[x]];
167  }
168 
169  dst += out->linesize[p];
170  srcxx += srcx->linesize[p];
171  srcyy += srcy->linesize[p];
172  }
173  }
174 }
175 
176 static void lut2_16bit(struct LUT2Context *s, AVFrame *out, AVFrame *srcx, AVFrame *srcy)
177 {
178  int p, y, x;
179 
180  for (p = 0; p < s->nb_planes; p++) {
181  const uint16_t *lut = s->lut[p];
182  const uint16_t *srcxx, *srcyy;
183  uint16_t *dst;
184 
185  dst = (uint16_t *)out->data[p];
186  srcxx = (uint16_t *)srcx->data[p];
187  srcyy = (uint16_t *)srcy->data[p];
188 
189  for (y = 0; y < s->height[p]; y++) {
190  for (x = 0; x < s->width[p]; x++) {
191  dst[x] = lut[(srcyy[x] << s->depthx) | srcxx[x]];
192  }
193 
194  dst += out->linesize[p] / 2;
195  srcxx += srcx->linesize[p] / 2;
196  srcyy += srcy->linesize[p] / 2;
197  }
198  }
199 }
200 
202 {
203  AVFilterContext *ctx = fs->parent;
204  LUT2Context *s = fs->opaque;
205  AVFilterLink *outlink = ctx->outputs[0];
206  AVFrame *out, *srcx, *srcy;
207  int ret;
208 
209  if ((ret = ff_framesync_get_frame(&s->fs, 0, &srcx, 0)) < 0 ||
210  (ret = ff_framesync_get_frame(&s->fs, 1, &srcy, 0)) < 0)
211  return ret;
212 
213  if (ctx->is_disabled) {
214  out = av_frame_clone(srcx);
215  if (!out)
216  return AVERROR(ENOMEM);
217  } else {
218  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
219  if (!out)
220  return AVERROR(ENOMEM);
221  av_frame_copy_props(out, srcx);
222 
223  s->lut2(s, out, srcx, srcy);
224  }
225 
226  out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base);
227 
228  return ff_filter_frame(outlink, out);
229 }
230 
231 static int config_output(AVFilterLink *outlink)
232 {
233  AVFilterContext *ctx = outlink->src;
234  LUT2Context *s = ctx->priv;
235  AVFilterLink *srcx = ctx->inputs[0];
236  AVFilterLink *srcy = ctx->inputs[1];
237  FFFrameSyncIn *in;
238  int p, ret;
239 
240  s->depth = s->depthx + s->depthy;
241 
242  if (srcx->format != srcy->format) {
243  av_log(ctx, AV_LOG_ERROR, "inputs must be of same pixel format\n");
244  return AVERROR(EINVAL);
245  }
246  if (srcx->w != srcy->w ||
247  srcx->h != srcy->h ||
250  av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
251  "(size %dx%d, SAR %d:%d) do not match the corresponding "
252  "second input link %s parameters (%dx%d, SAR %d:%d)\n",
253  ctx->input_pads[0].name, srcx->w, srcx->h,
254  srcx->sample_aspect_ratio.num,
255  srcx->sample_aspect_ratio.den,
256  ctx->input_pads[1].name,
257  srcy->w, srcy->h,
258  srcy->sample_aspect_ratio.num,
259  srcy->sample_aspect_ratio.den);
260  return AVERROR(EINVAL);
261  }
262 
263  outlink->w = srcx->w;
264  outlink->h = srcx->h;
265  outlink->time_base = srcx->time_base;
266  outlink->sample_aspect_ratio = srcx->sample_aspect_ratio;
267  outlink->frame_rate = srcx->frame_rate;
268 
269  if ((ret = ff_framesync_init(&s->fs, ctx, 2)) < 0)
270  return ret;
271 
272  in = s->fs.in;
273  in[0].time_base = srcx->time_base;
274  in[1].time_base = srcy->time_base;
275  in[0].sync = 1;
276  in[0].before = EXT_STOP;
277  in[0].after = EXT_INFINITY;
278  in[1].sync = 1;
279  in[1].before = EXT_STOP;
280  in[1].after = EXT_INFINITY;
281  s->fs.opaque = s;
283 
284  s->lut2 = s->depth > 16 ? lut2_16bit : lut2_8bit;
285 
286  for (p = 0; p < s->nb_planes; p++) {
287  s->lut[p] = av_malloc_array(1 << s->depth, sizeof(uint16_t));
288  if (!s->lut[p])
289  return AVERROR(ENOMEM);
290  }
291 
292  for (p = 0; p < s->nb_planes; p++) {
293  double res;
294  int x, y;
295 
296  /* create the parsed expression */
297  av_expr_free(s->comp_expr[p]);
298  s->comp_expr[p] = NULL;
299  ret = av_expr_parse(&s->comp_expr[p], s->comp_expr_str[p],
300  var_names, NULL, NULL, NULL, NULL, 0, ctx);
301  if (ret < 0) {
302  av_log(ctx, AV_LOG_ERROR,
303  "Error when parsing the expression '%s' for the component %d.\n",
304  s->comp_expr_str[p], p);
305  return AVERROR(EINVAL);
306  }
307 
308  /* compute the lut */
309  for (y = 0; y < (1 << s->depthx); y++) {
310  s->var_values[VAR_Y] = y;
311  for (x = 0; x < (1 << s->depthx); x++) {
312  s->var_values[VAR_X] = x;
313  res = av_expr_eval(s->comp_expr[p], s->var_values, s);
314  if (isnan(res)) {
315  av_log(ctx, AV_LOG_ERROR,
316  "Error when evaluating the expression '%s' for the values %d and %d for the component %d.\n",
317  s->comp_expr_str[p], x, y, p);
318  return AVERROR(EINVAL);
319  }
320 
321  s->lut[p][(y << s->depthx) + x] = res;
322  }
323  }
324  }
325 
326  return ff_framesync_configure(&s->fs);
327 }
328 
329 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
330 {
331  LUT2Context *s = inlink->dst->priv;
332  return ff_framesync_filter_frame(&s->fs, inlink, buf);
333 }
334 
335 static int request_frame(AVFilterLink *outlink)
336 {
337  LUT2Context *s = outlink->src->priv;
338  return ff_framesync_request_frame(&s->fs, outlink);
339 }
340 
341 static const AVFilterPad inputs[] = {
342  {
343  .name = "srcx",
344  .type = AVMEDIA_TYPE_VIDEO,
345  .filter_frame = filter_frame,
346  .config_props = config_inputx,
347  },
348  {
349  .name = "srcy",
350  .type = AVMEDIA_TYPE_VIDEO,
351  .filter_frame = filter_frame,
352  .config_props = config_inputy,
353  },
354  { NULL }
355 };
356 
357 static const AVFilterPad outputs[] = {
358  {
359  .name = "default",
360  .type = AVMEDIA_TYPE_VIDEO,
361  .config_props = config_output,
362  .request_frame = request_frame,
363  },
364  { NULL }
365 };
366 
368 
370  .name = "lut2",
371  .description = NULL_IF_CONFIG_SMALL("Compute and apply a lookup table from two video inputs."),
372  .priv_size = sizeof(LUT2Context),
373  .priv_class = &lut2_class,
374  .uninit = uninit,
376  .inputs = inputs,
377  .outputs = outputs,
379 };
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
static int config_inputx(AVFilterLink *inlink)
Definition: vf_lut2.c:117
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:372
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
AVOption.
Definition: opt.h:245
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:374
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:375
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:2306
Main libavfilter public API header.
static int config_output(AVFilterLink *outlink)
Definition: vf_lut2.c:231
const char * desc
Definition: nvenc.c:101
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
int num
Numerator.
Definition: rational.h:59
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:357
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:345
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:77
int nb_planes
Definition: vf_lut2.c:62
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:658
int depth
Definition: vf_lut2.c:63
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
static void lut2_8bit(struct LUT2Context *s, AVFrame *out, AVFrame *srcx, AVFrame *srcy)
Definition: vf_lut2.c:151
static int request_frame(AVFilterLink *outlink)
Definition: vf_lut2.c:335
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:354
int64_t pts
Timestamp of the current event.
Definition: framesync.h:170
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:93
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:59
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:315
static int query_formats(AVFilterContext *ctx)
Definition: vf_lut2.c:94
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1189
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:102
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
FFFrameSync fs
Definition: vf_lut2.c:67
#define av_cold
Definition: attributes.h:82
AVOptions.
void * parent
Definition: framesync.h:155
Definition: vf_lut2.c:47
double var_values[VAR_VARS_NB]
Definition: vf_lut2.c:59
#define FLAGS
Definition: vf_lut2.c:71
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:268
Definition: eval.c:149
FFFrameSyncIn * in
Pointer to array of inputs.
Definition: framesync.h:206
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:371
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:356
static int process_frame(FFFrameSync *fs)
Definition: vf_lut2.c:201
Definition: vf_lut2.c:45
static const AVFilterPad outputs[]
Definition: vf_lut2.c:357
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:101
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
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:98
Input stream structure.
Definition: framesync.h:83
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:346
int depthy
Definition: vf_lut2.c:63
#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
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:188
#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
int width[4]
Definition: vf_lut2.c:61
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
void * priv
private data for use by the filter
Definition: avfilter.h:322
int depthx
Definition: vf_lut2.c:63
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:362
uint16_t * lut[4]
lookup table for each component
Definition: vf_lut2.c:60
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:103
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:344
AVFilter ff_vf_lut2
Definition: vf_lut2.c:369
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:339
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:74
int ff_framesync_request_frame(FFFrameSync *fs, AVFilterLink *outlink)
Request a frame on the filter output.
Definition: framesync.c:314
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
Definition: vf_lut2.c:44
AVFormatContext * ctx
Definition: movenc.c:48
AVRational time_base
Time base for the output events.
Definition: framesync.h:165
int height[4]
Definition: vf_lut2.c:61
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:376
void * opaque
Opaque pointer, not used by the API.
Definition: framesync.h:180
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:340
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:480
static int config_inputy(AVFilterLink *inlink)
Definition: vf_lut2.c:139
Extend the frame to infinity.
Definition: framesync.h:77
misc drawing utilities
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:318
static const AVFilterPad inputs[]
Definition: vf_lut2.c:341
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
AVFILTER_DEFINE_CLASS(lut2)
static const AVOption lut2_options[]
Definition: vf_lut2.c:73
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
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:341
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:68
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events...
Definition: framesync.h:146
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
#define isnan(x)
Definition: libm.h:340
void(* lut2)(struct LUT2Context *s, AVFrame *dst, AVFrame *srcx, AVFrame *srcy)
Definition: vf_lut2.c:65
const char * name
Filter name.
Definition: avfilter.h:148
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:347
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:338
#define OFFSET(x)
Definition: vf_lut2.c:70
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:133
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:319
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
static void lut2_16bit(struct LUT2Context *s, AVFrame *out, AVFrame *srcx, AVFrame *srcy)
Definition: vf_lut2.c:176
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:358
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:342
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
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:81
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:229
#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
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:69
int den
Denominator.
Definition: rational.h:60
Completely stop all streams with this one.
Definition: framesync.h:67
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: vf_lut2.c:329
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:713
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:272
AVExpr * comp_expr[4]
Definition: vf_lut2.c:58
An instance of a filter.
Definition: avfilter.h:307
char * comp_expr_str[4]
Definition: vf_lut2.c:56
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:100
#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:229
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
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:589
simple arithmetic expression evaluator
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58