FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_geq.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
3  * Copyright (C) 2012 Clément Bœsch <u pkh me>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 /**
23  * @file
24  * Generic equation change filter
25  * Originally written by Michael Niedermayer for the MPlayer project, and
26  * ported by Clément Bœsch for FFmpeg.
27  */
28 
29 #include "libavutil/avstring.h"
30 #include "libavutil/eval.h"
31 #include "libavutil/opt.h"
32 #include "libavutil/pixdesc.h"
33 #include "internal.h"
34 
35 typedef struct {
36  const AVClass *class;
37  AVExpr *e[4]; ///< expressions for each plane
38  char *expr_str[4+3]; ///< expression strings for each plane
39  AVFrame *picref; ///< current input buffer
40  int hsub, vsub; ///< chroma subsampling
41  int planes; ///< number of planes
42  int is_rgb;
43 } GEQContext;
44 
45 enum { Y = 0, U, V, A, G, B, R };
46 
47 #define OFFSET(x) offsetof(GEQContext, x)
48 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
49 
50 static const AVOption geq_options[] = {
51  { "lum_expr", "set luminance expression", OFFSET(expr_str[Y]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
52  { "lum", "set luminance expression", OFFSET(expr_str[Y]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
53  { "cb_expr", "set chroma blue expression", OFFSET(expr_str[U]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
54  { "cb", "set chroma blue expression", OFFSET(expr_str[U]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
55  { "cr_expr", "set chroma red expression", OFFSET(expr_str[V]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
56  { "cr", "set chroma red expression", OFFSET(expr_str[V]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
57  { "alpha_expr", "set alpha expression", OFFSET(expr_str[A]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
58  { "a", "set alpha expression", OFFSET(expr_str[A]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
59  { "red_expr", "set red expression", OFFSET(expr_str[R]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
60  { "r", "set red expression", OFFSET(expr_str[R]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
61  { "green_expr", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
62  { "g", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
63  { "blue_expr", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
64  { "b", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
65  {NULL},
66 };
67 
69 
70 static inline double getpix(void *priv, double x, double y, int plane)
71 {
72  int xi, yi;
73  GEQContext *geq = priv;
74  AVFrame *picref = geq->picref;
75  const uint8_t *src = picref->data[plane];
76  const int linesize = picref->linesize[plane];
77  const int w = (plane == 1 || plane == 2) ? FF_CEIL_RSHIFT(picref->width, geq->hsub) : picref->width;
78  const int h = (plane == 1 || plane == 2) ? FF_CEIL_RSHIFT(picref->height, geq->vsub) : picref->height;
79 
80  if (!src)
81  return 0;
82 
83  xi = x = av_clipf(x, 0, w - 2);
84  yi = y = av_clipf(y, 0, h - 2);
85 
86  x -= xi;
87  y -= yi;
88 
89  return (1-y)*((1-x)*src[xi + yi * linesize] + x*src[xi + 1 + yi * linesize])
90  + y *((1-x)*src[xi + (yi+1) * linesize] + x*src[xi + 1 + (yi+1) * linesize]);
91 }
92 
93 //TODO: cubic interpolate
94 //TODO: keep the last few frames
95 static double lum(void *priv, double x, double y) { return getpix(priv, x, y, 0); }
96 static double cb(void *priv, double x, double y) { return getpix(priv, x, y, 1); }
97 static double cr(void *priv, double x, double y) { return getpix(priv, x, y, 2); }
98 static double alpha(void *priv, double x, double y) { return getpix(priv, x, y, 3); }
99 
100 static const char *const var_names[] = { "X", "Y", "W", "H", "N", "SW", "SH", "T", NULL };
102 
104 {
105  GEQContext *geq = ctx->priv;
106  int plane, ret = 0;
107 
108  if (!geq->expr_str[Y] && !geq->expr_str[G] && !geq->expr_str[B] && !geq->expr_str[R]) {
109  av_log(ctx, AV_LOG_ERROR, "A luminance or RGB expression is mandatory\n");
110  ret = AVERROR(EINVAL);
111  goto end;
112  }
113  geq->is_rgb = !geq->expr_str[Y];
114 
115  if ((geq->expr_str[Y] || geq->expr_str[U] || geq->expr_str[V]) && (geq->expr_str[G] || geq->expr_str[B] || geq->expr_str[R])) {
116  av_log(ctx, AV_LOG_ERROR, "Either YCbCr or RGB but not both must be specified\n");
117  ret = AVERROR(EINVAL);
118  goto end;
119  }
120 
121  if (!geq->expr_str[U] && !geq->expr_str[V]) {
122  /* No chroma at all: fallback on luma */
123  geq->expr_str[U] = av_strdup(geq->expr_str[Y]);
124  geq->expr_str[V] = av_strdup(geq->expr_str[Y]);
125  } else {
126  /* One chroma unspecified, fallback on the other */
127  if (!geq->expr_str[U]) geq->expr_str[U] = av_strdup(geq->expr_str[V]);
128  if (!geq->expr_str[V]) geq->expr_str[V] = av_strdup(geq->expr_str[U]);
129  }
130 
131  if (!geq->expr_str[A])
132  geq->expr_str[A] = av_strdup("255");
133  if (!geq->expr_str[G])
134  geq->expr_str[G] = av_strdup("g(X,Y)");
135  if (!geq->expr_str[B])
136  geq->expr_str[B] = av_strdup("b(X,Y)");
137  if (!geq->expr_str[R])
138  geq->expr_str[R] = av_strdup("r(X,Y)");
139 
140  if (geq->is_rgb ?
141  (!geq->expr_str[G] || !geq->expr_str[B] || !geq->expr_str[R])
142  :
143  (!geq->expr_str[U] || !geq->expr_str[V] || !geq->expr_str[A])) {
144  ret = AVERROR(ENOMEM);
145  goto end;
146  }
147 
148  for (plane = 0; plane < 4; plane++) {
149  static double (*p[])(void *, double, double) = { lum, cb, cr, alpha };
150  static const char *const func2_yuv_names[] = { "lum", "cb", "cr", "alpha", "p", NULL };
151  static const char *const func2_rgb_names[] = { "g", "b", "r", "alpha", "p", NULL };
152  const char *const *func2_names = geq->is_rgb ? func2_rgb_names : func2_yuv_names;
153  double (*func2[])(void *, double, double) = { lum, cb, cr, alpha, p[plane], NULL };
154 
155  ret = av_expr_parse(&geq->e[plane], geq->expr_str[plane < 3 && geq->is_rgb ? plane+4 : plane], var_names,
156  NULL, NULL, func2_names, func2, 0, ctx);
157  if (ret < 0)
158  break;
159  }
160 
161 end:
162  return ret;
163 }
164 
166 {
167  GEQContext *geq = ctx->priv;
168  static const enum AVPixelFormat yuv_pix_fmts[] = {
174  };
175  static const enum AVPixelFormat rgb_pix_fmts[] = {
178  };
179  AVFilterFormats *fmts_list;
180 
181  if (geq->is_rgb) {
182  fmts_list = ff_make_format_list(rgb_pix_fmts);
183  } else
184  fmts_list = ff_make_format_list(yuv_pix_fmts);
185  if (!fmts_list)
186  return AVERROR(ENOMEM);
187  return ff_set_common_formats(ctx, fmts_list);
188 }
189 
190 static int geq_config_props(AVFilterLink *inlink)
191 {
192  GEQContext *geq = inlink->dst->priv;
193  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
194 
195  geq->hsub = desc->log2_chroma_w;
196  geq->vsub = desc->log2_chroma_h;
197  geq->planes = desc->nb_components;
198  return 0;
199 }
200 
202 {
203  int plane;
204  GEQContext *geq = inlink->dst->priv;
205  AVFilterLink *outlink = inlink->dst->outputs[0];
206  AVFrame *out;
207  double values[VAR_VARS_NB] = {
208  [VAR_N] = inlink->frame_count,
209  [VAR_T] = in->pts == AV_NOPTS_VALUE ? NAN : in->pts * av_q2d(inlink->time_base),
210  };
211 
212  geq->picref = in;
213  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
214  if (!out) {
215  av_frame_free(&in);
216  return AVERROR(ENOMEM);
217  }
218  av_frame_copy_props(out, in);
219 
220  for (plane = 0; plane < geq->planes && out->data[plane]; plane++) {
221  int x, y;
222  uint8_t *dst = out->data[plane];
223  const int linesize = out->linesize[plane];
224  const int w = (plane == 1 || plane == 2) ? FF_CEIL_RSHIFT(inlink->w, geq->hsub) : inlink->w;
225  const int h = (plane == 1 || plane == 2) ? FF_CEIL_RSHIFT(inlink->h, geq->vsub) : inlink->h;
226 
227  values[VAR_W] = w;
228  values[VAR_H] = h;
229  values[VAR_SW] = w / (double)inlink->w;
230  values[VAR_SH] = h / (double)inlink->h;
231 
232  for (y = 0; y < h; y++) {
233  values[VAR_Y] = y;
234  for (x = 0; x < w; x++) {
235  values[VAR_X] = x;
236  dst[x] = av_expr_eval(geq->e[plane], values, geq);
237  }
238  dst += linesize;
239  }
240  }
241 
242  av_frame_free(&geq->picref);
243  return ff_filter_frame(outlink, out);
244 }
245 
247 {
248  int i;
249  GEQContext *geq = ctx->priv;
250 
251  for (i = 0; i < FF_ARRAY_ELEMS(geq->e); i++)
252  av_expr_free(geq->e[i]);
253 }
254 
255 static const AVFilterPad geq_inputs[] = {
256  {
257  .name = "default",
258  .type = AVMEDIA_TYPE_VIDEO,
259  .config_props = geq_config_props,
260  .filter_frame = geq_filter_frame,
261  },
262  { NULL }
263 };
264 
265 static const AVFilterPad geq_outputs[] = {
266  {
267  .name = "default",
268  .type = AVMEDIA_TYPE_VIDEO,
269  },
270  { NULL }
271 };
272 
274  .name = "geq",
275  .description = NULL_IF_CONFIG_SMALL("Apply generic equation to each pixel."),
276  .priv_size = sizeof(GEQContext),
277  .init = geq_init,
278  .uninit = geq_uninit,
280  .inputs = geq_inputs,
281  .outputs = geq_outputs,
282  .priv_class = &geq_class,
284 };
int plane
Definition: avisynth_c.h:291
#define NULL
Definition: coverity.c:32
static const AVFilterPad geq_inputs[]
Definition: vf_geq.c:255
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2090
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
AVOption.
Definition: opt.h:255
Definition: vf_geq.c:45
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:68
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static av_cold void geq_uninit(AVFilterContext *ctx)
Definition: vf_geq.c:246
static double getpix(void *priv, double x, double y, int plane)
Definition: vf_geq.c:70
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:176
static const char *const var_names[]
Definition: vf_geq.c:100
static const AVFilterPad geq_outputs[]
Definition: vf_geq.c:265
#define FF_ARRAY_ELEMS(a)
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:652
Definition: vf_geq.c:45
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
Definition: vf_geq.c:101
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
static enum AVPixelFormat rgb_pix_fmts[]
Definition: jpeg2000dec.c:218
AVFrame * picref
current input buffer
Definition: vf_geq.c:39
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:451
const char * name
Pad name.
Definition: internal.h:67
static int geq_query_formats(AVFilterContext *ctx)
Definition: vf_geq.c:165
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:96
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1145
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:103
uint8_t
#define av_cold
Definition: attributes.h:74
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:337
AVOptions.
AVFilter ff_vf_geq
Definition: vf_geq.c:273
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:257
Definition: eval.c:143
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:80
Definition: vf_geq.c:101
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:61
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:269
static double alpha(void *priv, double x, double y)
Definition: vf_geq.c:98
int width
width and height of the video frame
Definition: frame.h:220
#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:542
int planes
number of planes
Definition: vf_geq.c:41
AVExpr * e[4]
expressions for each plane
Definition: vf_geq.c:37
static int geq_config_props(AVFilterLink *inlink)
Definition: vf_geq.c:190
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
#define OFFSET(x)
Definition: vf_geq.c:47
#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:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
void * priv
private data for use by the filter
Definition: avfilter.h:654
static const AVOption geq_options[]
Definition: vf_geq.c:50
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
float y
ret
Definition: avfilter.c:974
Definition: vf_geq.c:101
#define FF_CEIL_RSHIFT(a, b)
Definition: common.h:57
Definition: vf_geq.c:45
Definition: vf_geq.c:101
Definition: vf_geq.c:45
Definition: vf_geq.c:101
AVS_Value src
Definition: avisynth_c.h:482
static enum AVPixelFormat yuv_pix_fmts[]
Definition: jpeg2000dec.c:220
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:312
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:265
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:268
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
char * expr_str[4+3]
expression strings for each plane
Definition: vf_geq.c:38
int hsub
Definition: vf_geq.c:40
#define FLAGS
Definition: vf_geq.c:48
static av_cold int geq_init(AVFilterContext *ctx)
Definition: vf_geq.c:103
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
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:69
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
const char * name
Filter name.
Definition: avfilter.h:474
Definition: vf_geq.c:45
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
static int flags
Definition: cpu.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
static double lum(void *priv, double x, double y)
Definition: vf_geq.c:95
Definition: vf_geq.c:101
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
Y , 8bpp.
Definition: pixfmt.h:71
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:287
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:70
Definition: vf_geq.c:45
Definition: vf_geq.c:101
#define NAN
Definition: math.h:28
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:707
int is_rgb
Definition: vf_geq.c:42
static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_geq.c:201
A list of supported formats for one end of a filter link.
Definition: formats.h:64
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-> out
Definition: vf_geq.c:101
An instance of a filter.
Definition: avfilter.h:633
int height
Definition: frame.h:220
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:101
internal API functions
static double cr(void *priv, double x, double y)
Definition: vf_geq.c:97
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
Definition: vf_geq.c:45
int vsub
chroma subsampling
Definition: vf_geq.c:40
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:548
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:241
simple arithmetic expression evaluator
AVFILTER_DEFINE_CLASS(geq)