Libav
vf_scale.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Bobby Bingham
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
26 #include <stdio.h>
27 #include <string.h>
28 
29 #include "avfilter.h"
30 #include "formats.h"
31 #include "internal.h"
32 #include "video.h"
33 #include "libavutil/avstring.h"
34 #include "libavutil/eval.h"
35 #include "libavutil/internal.h"
36 #include "libavutil/mathematics.h"
37 #include "libavutil/opt.h"
38 #include "libavutil/pixdesc.h"
39 #include "libswscale/swscale.h"
40 
41 static const char *const var_names[] = {
42  "PI",
43  "PHI",
44  "E",
45  "in_w", "iw",
46  "in_h", "ih",
47  "out_w", "ow",
48  "out_h", "oh",
49  "a", "dar",
50  "sar",
51  "hsub",
52  "vsub",
53  NULL
54 };
55 
56 enum var_name {
69 };
70 
71 typedef struct ScaleContext {
72  const AVClass *class;
73  struct SwsContext *sws;
74 
80  int w, h;
81  unsigned int flags;
82 
83  int hsub, vsub;
84  int slice_y;
86 
87  char *w_expr;
88  char *h_expr;
89  char *flags_str;
90 } ScaleContext;
91 
92 static av_cold int init(AVFilterContext *ctx)
93 {
94  ScaleContext *scale = ctx->priv;
95 
96  if (scale->flags_str) {
97  const AVClass *class = sws_get_class();
98  const AVOption *o = av_opt_find(&class, "sws_flags", NULL, 0,
100  int ret = av_opt_eval_flags(&class, o, scale->flags_str, &scale->flags);
101 
102  if (ret < 0)
103  return ret;
104  }
105 
106  return 0;
107 }
108 
109 static av_cold void uninit(AVFilterContext *ctx)
110 {
111  ScaleContext *scale = ctx->priv;
112  sws_freeContext(scale->sws);
113  scale->sws = NULL;
114 }
115 
117 {
119  enum AVPixelFormat pix_fmt;
120  int ret;
121 
122  if (ctx->inputs[0]) {
123  const AVPixFmtDescriptor *desc = NULL;
124  formats = NULL;
125  while ((desc = av_pix_fmt_desc_next(desc))) {
126  pix_fmt = av_pix_fmt_desc_get_id(desc);
127  if ((sws_isSupportedInput(pix_fmt) ||
129  && (ret = ff_add_format(&formats, pix_fmt)) < 0) {
130  ff_formats_unref(&formats);
131  return ret;
132  }
133  }
134  ff_formats_ref(formats, &ctx->inputs[0]->out_formats);
135  }
136  if (ctx->outputs[0]) {
137  const AVPixFmtDescriptor *desc = NULL;
138  formats = NULL;
139  while ((desc = av_pix_fmt_desc_next(desc))) {
140  pix_fmt = av_pix_fmt_desc_get_id(desc);
141  if ((sws_isSupportedOutput(pix_fmt) ||
143  && (ret = ff_add_format(&formats, pix_fmt)) < 0) {
144  ff_formats_unref(&formats);
145  return ret;
146  }
147  }
148  ff_formats_ref(formats, &ctx->outputs[0]->in_formats);
149  }
150 
151  return 0;
152 }
153 
154 static int config_props(AVFilterLink *outlink)
155 {
156  AVFilterContext *ctx = outlink->src;
157  AVFilterLink *inlink = outlink->src->inputs[0];
158  ScaleContext *scale = ctx->priv;
159  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
160  int64_t w, h;
161  double var_values[VARS_NB], res;
162  char *expr;
163  int ret;
164 
165  var_values[VAR_PI] = M_PI;
166  var_values[VAR_PHI] = M_PHI;
167  var_values[VAR_E] = M_E;
168  var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
169  var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
170  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
171  var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
172  var_values[VAR_A] = (double) inlink->w / inlink->h;
173  var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
174  (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
175  var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
176  var_values[VAR_HSUB] = 1 << desc->log2_chroma_w;
177  var_values[VAR_VSUB] = 1 << desc->log2_chroma_h;
178 
179  /* evaluate width and height */
180  av_expr_parse_and_eval(&res, (expr = scale->w_expr),
181  var_names, var_values,
182  NULL, NULL, NULL, NULL, NULL, 0, ctx);
183  scale->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
184  if ((ret = av_expr_parse_and_eval(&res, (expr = scale->h_expr),
185  var_names, var_values,
186  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
187  goto fail;
188  scale->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
189  /* evaluate again the width, as it may depend on the output height */
190  if ((ret = av_expr_parse_and_eval(&res, (expr = scale->w_expr),
191  var_names, var_values,
192  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
193  goto fail;
194  scale->w = res;
195 
196  w = scale->w;
197  h = scale->h;
198 
199  /* sanity check params */
200  if (w < -1 || h < -1) {
201  av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n");
202  return AVERROR(EINVAL);
203  }
204  if (w == -1 && h == -1)
205  scale->w = scale->h = 0;
206 
207  if (!(w = scale->w))
208  w = inlink->w;
209  if (!(h = scale->h))
210  h = inlink->h;
211  if (w == -1)
212  w = av_rescale(h, inlink->w, inlink->h);
213  if (h == -1)
214  h = av_rescale(w, inlink->h, inlink->w);
215 
216  if (w > INT_MAX || h > INT_MAX ||
217  (h * inlink->w) > INT_MAX ||
218  (w * inlink->h) > INT_MAX)
219  av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
220 
221  outlink->w = w;
222  outlink->h = h;
223 
224  /* TODO: make algorithm configurable */
225  av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s -> w:%d h:%d fmt:%s flags:0x%0x\n",
226  inlink ->w, inlink ->h, av_get_pix_fmt_name(inlink->format),
227  outlink->w, outlink->h, av_get_pix_fmt_name(outlink->format),
228  scale->flags);
229 
230  scale->input_is_pal = desc->flags & AV_PIX_FMT_FLAG_PAL ||
232 
233  if (scale->sws)
234  sws_freeContext(scale->sws);
235  if (inlink->w == outlink->w && inlink->h == outlink->h &&
236  inlink->format == outlink->format)
237  scale->sws = NULL;
238  else {
239  scale->sws = sws_getContext(inlink ->w, inlink ->h, inlink ->format,
240  outlink->w, outlink->h, outlink->format,
241  scale->flags, NULL, NULL, NULL);
242  if (!scale->sws)
243  return AVERROR(EINVAL);
244  }
245 
246 
247  if (inlink->sample_aspect_ratio.num)
248  outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h*inlink->w,
249  outlink->w*inlink->h},
250  inlink->sample_aspect_ratio);
251  else
252  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
253 
254  return 0;
255 
256 fail:
258  "Error when evaluating the expression '%s'\n", expr);
259  return ret;
260 }
261 
262 static int filter_frame(AVFilterLink *link, AVFrame *in)
263 {
264  ScaleContext *scale = link->dst->priv;
265  AVFilterLink *outlink = link->dst->outputs[0];
266  AVFrame *out;
267  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
268 
269  if (!scale->sws)
270  return ff_filter_frame(outlink, in);
271 
272  scale->hsub = desc->log2_chroma_w;
273  scale->vsub = desc->log2_chroma_h;
274 
275  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
276  if (!out) {
277  av_frame_free(&in);
278  return AVERROR(ENOMEM);
279  }
280 
281  av_frame_copy_props(out, in);
282  out->width = outlink->w;
283  out->height = outlink->h;
284 
286  (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
287  (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
288  INT_MAX);
289 
290  sws_scale(scale->sws, in->data, in->linesize, 0, in->height,
291  out->data, out->linesize);
292 
293  av_frame_free(&in);
294  return ff_filter_frame(outlink, out);
295 }
296 
297 #define OFFSET(x) offsetof(ScaleContext, x)
298 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
299 static const AVOption options[] = {
300  { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str = "iw" }, .flags = FLAGS },
301  { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str = "ih" }, .flags = FLAGS },
302  { "flags", "Flags to pass to libswscale", OFFSET(flags_str), AV_OPT_TYPE_STRING, { .str = "bilinear" }, .flags = FLAGS },
303  { NULL },
304 };
305 
306 static const AVClass scale_class = {
307  .class_name = "scale",
308  .item_name = av_default_item_name,
309  .option = options,
310  .version = LIBAVUTIL_VERSION_INT,
311 };
312 
314  {
315  .name = "default",
316  .type = AVMEDIA_TYPE_VIDEO,
317  .filter_frame = filter_frame,
318  },
319  { NULL }
320 };
321 
323  {
324  .name = "default",
325  .type = AVMEDIA_TYPE_VIDEO,
326  .config_props = config_props,
327  },
328  { NULL }
329 };
330 
332  .name = "scale",
333  .description = NULL_IF_CONFIG_SMALL("Scale the input video to width:height size and/or convert the image format."),
334 
335  .init = init,
336  .uninit = uninit,
337 
338  .query_formats = query_formats,
339 
340  .priv_size = sizeof(ScaleContext),
341  .priv_class = &scale_class,
342 
345 };
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:112
#define FLAGS
Definition: vf_scale.c:298
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1599
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
AVOption.
Definition: opt.h:234
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:232
Main libavfilter public API header.
Definition: vf_scale.c:59
int num
numerator
Definition: rational.h:44
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_dlog(ac->avr,"%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
int hsub
sws flags
Definition: vf_scale.c:83
int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt)
Definition: utils.c:199
static enum AVSampleFormat formats[]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104
static const AVOption options[]
Definition: vf_scale.c:299
const AVClass * sws_get_class(void)
Get the AVClass for swsContext.
Definition: options.c:71
int vsub
chroma subsampling
Definition: vf_scale.c:83
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:38
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:571
char * w_expr
width expression string
Definition: vf_scale.c:87
static int query_formats(AVFilterContext *ctx)
Definition: vf_scale.c:116
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:733
#define av_cold
Definition: attributes.h:66
char * h_expr
height expression string
Definition: vf_scale.c:88
AVOptions.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:79
struct SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Allocate and return an SwsContext.
Definition: utils.c:1321
static const AVClass scale_class
Definition: vf_scale.c:306
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:139
external api for the swscale stuff
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
Definition: eval.c:551
int width
width and height of the video frame
Definition: frame.h:174
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
#define AVERROR(e)
Definition: error.h:43
int av_opt_eval_flags(void *obj, const AVOption *o, const char *val, int *flags_out)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:69
#define sws_isSupportedOutput(x)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:150
void * priv
private data for use by the filter
Definition: avfilter.h:584
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
int w
New dimensions.
Definition: vf_scale.c:80
static int config_props(AVFilterLink *outlink)
Definition: vf_scale.c:154
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:700
common internal API header
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
Definition: pixdesc.c:1615
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_scale.c:109
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:116
static const AVFilterPad avfilter_vf_scale_outputs[]
Definition: vf_scale.c:322
#define M_E
Definition: ratecontrol.c:39
#define AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is "pseudo-paletted".
Definition: pixdesc.h:134
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
Definition: utils.c:1666
#define sws_isSupportedInput(x)
enum AVPixelFormat pix_fmt
Definition: movenc.c:843
char * flags_str
Definition: vf_scale.c:89
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
NULL
Definition: eval.c:55
#define OFFSET(x)
Definition: vf_scale.c:297
void ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:266
AVFilter ff_vf_scale
Definition: vf_scale.c:331
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
struct SwsContext * sws
software scaler context
Definition: vf_scale.c:73
av_default_item_name
Definition: dnxhdenc.c:52
uint8_t flags
Definition: pixdesc.h:90
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
static const AVFilterPad avfilter_vf_scale_inputs[]
Definition: vf_scale.c:313
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:206
int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Scale the image slice in srcSlice and put the resulting scaled slice in the image in dst...
Describe the class of an AVClass context structure.
Definition: log.h:33
Filter definition.
Definition: avfilter.h:421
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:221
rational number numerator/denominator
Definition: rational.h:43
static av_cold int init(AVFilterContext *ctx)
Definition: vf_scale.c:92
#define M_PHI
Definition: mathematics.h:34
void ff_formats_unref(AVFilterFormats **ref)
If *ref is non-NULL, remove *ref as a reference to the format list it currently points to...
Definition: formats.c:302
const char * name
Filter name.
Definition: avfilter.h:425
int input_is_pal
set to 1 if the input format is paletted
Definition: vf_scale.c:85
static const char *const var_names[]
Definition: vf_scale.c:41
unsigned int flags
Definition: vf_scale.c:81
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:578
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
static int filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_scale.c:262
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_dlog(ac->avr,"%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
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poi...
Definition: opt.h:392
int den
denominator
Definition: rational.h:45
struct AVFilterPad AVFilterPad
Definition: avfilter.h:67
int slice_y
top of current output slice
Definition: vf_scale.c:84
Definition: vf_scale.c:64
int ff_add_format(AVFilterFormats **avff, int fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:199
#define NAN
Definition: math.h:28
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:563
int height
Definition: frame.h:174
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:1540
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:367
var_name
Definition: setpts.c:60
simple arithmetic expression evaluator
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
Definition: pixdesc.c:1606