FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_zoompan.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 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/eval.h"
22 #include "libavutil/opt.h"
23 #include "libavutil/pixdesc.h"
24 #include "avfilter.h"
25 #include "formats.h"
26 #include "internal.h"
27 #include "video.h"
28 #include "libswscale/swscale.h"
29 
30 static const char *const var_names[] = {
31  "in_w", "iw",
32  "in_h", "ih",
33  "out_w", "ow",
34  "out_h", "oh",
35  "in",
36  "on",
37  "duration",
38  "pduration",
39  "time",
40  "frame",
41  "zoom",
42  "pzoom",
43  "x", "px",
44  "y", "py",
45  "a",
46  "sar",
47  "dar",
48  "hsub",
49  "vsub",
50  NULL
51 };
52 
53 enum var_name {
74 };
75 
76 typedef struct ZPcontext {
77  const AVClass *class;
79  char *x_expr_str;
80  char *y_expr_str;
82  int w, h;
83  double x, y;
84  double prev_zoom;
86  struct SwsContext *sws;
87  int64_t frame_count;
88 } ZPContext;
89 
90 #define OFFSET(x) offsetof(ZPContext, x)
91 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
92 static const AVOption zoompan_options[] = {
93  { "zoom", "set the zoom expression", OFFSET(zoom_expr_str), AV_OPT_TYPE_STRING, {.str = "1" }, .flags = FLAGS },
94  { "z", "set the zoom expression", OFFSET(zoom_expr_str), AV_OPT_TYPE_STRING, {.str = "1" }, .flags = FLAGS },
95  { "x", "set the x expression", OFFSET(x_expr_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags = FLAGS },
96  { "y", "set the y expression", OFFSET(y_expr_str), AV_OPT_TYPE_STRING, {.str="0"}, .flags = FLAGS },
97  { "d", "set the duration expression", OFFSET(duration_expr_str), AV_OPT_TYPE_STRING, {.str="90"}, .flags = FLAGS },
98  { "s", "set the output image size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="hd720"}, .flags = FLAGS },
99  { NULL }
100 };
101 
102 AVFILTER_DEFINE_CLASS(zoompan);
103 
104 static av_cold int init(AVFilterContext *ctx)
105 {
106  ZPContext *s = ctx->priv;
107 
108  s->prev_zoom = 1;
109  return 0;
110 }
111 
112 static int config_output(AVFilterLink *outlink)
113 {
114  AVFilterContext *ctx = outlink->src;
115  ZPContext *s = ctx->priv;
116 
117  outlink->w = s->w;
118  outlink->h = s->h;
119 
120  return 0;
121 }
122 
123 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
124 {
125  AVFilterContext *ctx = inlink->dst;
126  AVFilterLink *outlink = ctx->outputs[0];
127  ZPContext *s = ctx->priv;
128  double var_values[VARS_NB], nb_frames, zoom, dx, dy;
129  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(in->format);
130  AVFrame *out = NULL;
131  int i, k, x, y, w, h, ret = 0;
132 
133  var_values[VAR_IN_W] = var_values[VAR_IW] = in->width;
134  var_values[VAR_IN_H] = var_values[VAR_IH] = in->height;
135  var_values[VAR_OUT_W] = var_values[VAR_OW] = s->w;
136  var_values[VAR_OUT_H] = var_values[VAR_OH] = s->h;
137  var_values[VAR_IN] = inlink->frame_count + 1;
138  var_values[VAR_ON] = outlink->frame_count + 1;
139  var_values[VAR_PX] = s->x;
140  var_values[VAR_PY] = s->y;
141  var_values[VAR_X] = 0;
142  var_values[VAR_Y] = 0;
143  var_values[VAR_PZOOM] = s->prev_zoom;
144  var_values[VAR_ZOOM] = 1;
145  var_values[VAR_PDURATION] = s->prev_nb_frames;
146  var_values[VAR_A] = (double) in->width / in->height;
147  var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
148  (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
149  var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
150  var_values[VAR_HSUB] = 1 << desc->log2_chroma_w;
151  var_values[VAR_VSUB] = 1 << desc->log2_chroma_h;
152 
153  if ((ret = av_expr_parse_and_eval(&nb_frames, s->duration_expr_str,
154  var_names, var_values,
155  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
156  goto fail;
157 
158  var_values[VAR_DURATION] = nb_frames;
159  for (i = 0; i < nb_frames; i++) {
160  int px[4];
161  int py[4];
162  uint8_t *input[4];
163  int64_t pts = av_rescale_q(in->pts, inlink->time_base,
164  outlink->time_base) + s->frame_count;
165 
166  var_values[VAR_TIME] = pts * av_q2d(outlink->time_base);
167  var_values[VAR_FRAME] = i;
168  var_values[VAR_ON] = outlink->frame_count + 1;
169  if ((ret = av_expr_parse_and_eval(&zoom, s->zoom_expr_str,
170  var_names, var_values,
171  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
172  goto fail;
173 
174  zoom = av_clipd(zoom, 1, 10);
175  var_values[VAR_ZOOM] = zoom;
176  w = in->width * (1.0 / zoom);
177  h = in->height * (1.0 / zoom);
178 
179  if ((ret = av_expr_parse_and_eval(&dx, s->x_expr_str,
180  var_names, var_values,
181  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
182  goto fail;
183  x = dx = av_clipd(dx, 0, FFMAX(in->width - w, 0));
184  var_values[VAR_X] = dx;
185  x &= ~((1 << desc->log2_chroma_w) - 1);
186 
187  if ((ret = av_expr_parse_and_eval(&dy, s->y_expr_str,
188  var_names, var_values,
189  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
190  goto fail;
191  y = dy = av_clipd(dy, 0, FFMAX(in->height - h, 0));
192  var_values[VAR_Y] = dy;
193  y &= ~((1 << desc->log2_chroma_h) - 1);
194 
195  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
196  if (!out) {
197  ret = AVERROR(ENOMEM);
198  goto fail;
199  }
200 
201  px[1] = px[2] = FF_CEIL_RSHIFT(x, desc->log2_chroma_w);
202  px[0] = px[3] = x;
203 
204  py[1] = py[2] = FF_CEIL_RSHIFT(y, desc->log2_chroma_h);
205  py[0] = py[3] = y;
206 
207  s->sws = sws_alloc_context();
208  if (!s->sws) {
209  ret = AVERROR(ENOMEM);
210  goto fail;
211  }
212 
213  for (k = 0; in->data[k]; k++)
214  input[k] = in->data[k] + py[k] * in->linesize[k] + px[k];
215 
216  av_opt_set_int(s->sws, "srcw", w, 0);
217  av_opt_set_int(s->sws, "srch", h, 0);
218  av_opt_set_int(s->sws, "src_format", in->format, 0);
219  av_opt_set_int(s->sws, "dstw", outlink->w, 0);
220  av_opt_set_int(s->sws, "dsth", outlink->h, 0);
221  av_opt_set_int(s->sws, "dst_format", outlink->format, 0);
222  av_opt_set_int(s->sws, "sws_flags", SWS_BICUBIC, 0);
223 
224  if ((ret = sws_init_context(s->sws, NULL, NULL)) < 0)
225  goto fail;
226 
227  sws_scale(s->sws, (const uint8_t *const *)&input, in->linesize, 0, h, out->data, out->linesize);
228 
229  out->pts = pts;
230  s->frame_count++;
231 
232  ret = ff_filter_frame(outlink, out);
233  if (ret < 0)
234  break;
235  out = NULL;
236 
237  sws_freeContext(s->sws);
238  s->sws = NULL;
239  }
240 
241  s->x = dx;
242  s->y = dy;
243  s->prev_zoom = zoom;
244  s->prev_nb_frames = nb_frames;
245 
246 fail:
247  sws_freeContext(s->sws);
248  s->sws = NULL;
249  av_frame_free(&out);
250  av_frame_free(&in);
251  return ret;
252 }
253 
255 {
256  static const enum AVPixelFormat pix_fmts[] = {
267  };
268 
269  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
270  if (!fmts_list)
271  return AVERROR(ENOMEM);
272  return ff_set_common_formats(ctx, fmts_list);
273 }
274 
275 static av_cold void uninit(AVFilterContext *ctx)
276 {
277  ZPContext *s = ctx->priv;
278 
279  sws_freeContext(s->sws);
280  s->sws = NULL;
281 }
282 
283 static const AVFilterPad inputs[] = {
284  {
285  .name = "default",
286  .type = AVMEDIA_TYPE_VIDEO,
287  .filter_frame = filter_frame,
288  },
289  { NULL }
290 };
291 
292 static const AVFilterPad outputs[] = {
293  {
294  .name = "default",
295  .type = AVMEDIA_TYPE_VIDEO,
296  .config_props = config_output,
297  },
298  { NULL }
299 };
300 
302  .name = "zoompan",
303  .description = NULL_IF_CONFIG_SMALL("Apply Zoom & Pan effect."),
304  .priv_size = sizeof(ZPContext),
305  .priv_class = &zoompan_class,
306  .init = init,
307  .uninit = uninit,
309  .inputs = inputs,
310  .outputs = outputs,
312 };
#define NULL
Definition: coverity.c:32
struct SwsContext * sws
Definition: vf_zoompan.c:86
const char * s
Definition: avisynth_c.h:631
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
#define SWS_BICUBIC
Definition: swscale.h:58
AVOption.
Definition: opt.h:255
int prev_nb_frames
Definition: vf_zoompan.c:85
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:68
char * zoom_expr_str
Definition: vf_zoompan.c:78
Main libavfilter public API header.
static int query_formats(AVFilterContext *ctx)
Definition: vf_zoompan.c:254
int num
numerator
Definition: rational.h:44
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
static const AVFilterPad inputs[]
Definition: vf_zoompan.c:283
double y
Definition: vf_zoompan.c:83
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
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
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
AVOptions.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:257
#define FLAGS
Definition: vf_zoompan.c:91
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:80
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:102
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:76
int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
Definition: utils.c:981
external API header
A filter pad used for either input or output.
Definition: internal.h:61
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:140
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:717
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:269
int width
width and height of the video frame
Definition: frame.h:220
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
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
static const char *const var_names[]
Definition: vf_zoompan.c:30
#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
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:491
double x
Definition: vf_zoompan.c:83
static const AVOption zoompan_options[]
Definition: vf_zoompan.c:92
static int config_output(AVFilterLink *outlink)
Definition: vf_zoompan.c:112
#define FFMAX(a, b)
Definition: common.h:64
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
var_name
Definition: aeval.c:46
float y
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:75
ret
Definition: avfilter.c:974
#define FF_CEIL_RSHIFT(a, b)
Definition: common.h:57
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
Definition: utils.c:1984
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_zoompan.c:275
char * y_expr_str
Definition: vf_zoompan.c:80
#define OFFSET(x)
Definition: vf_zoompan.c:90
char * duration_expr_str
Definition: vf_zoompan.c:81
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:232
AVFilter ff_vf_zoompan
Definition: vf_zoompan.c:301
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
int attribute_align_arg sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale wrapper, so we don't need to export the SwsContext.
Definition: swscale.c:912
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 outputs[]
Definition: vf_zoompan.c:292
const char * name
Filter name.
Definition: avfilter.h:474
int64_t frame_count
Definition: vf_zoompan.c:87
offset must point to two consecutive integers
Definition: opt.h:232
struct SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext.
Definition: utils.c:953
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
static int64_t pts
Global timestamp for the audio frames.
static int flags
Definition: cpu.c:47
static av_cold int init(AVFilterContext *ctx)
Definition: vf_zoompan.c:104
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
Y , 8bpp.
Definition: pixfmt.h:71
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:77
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:70
int den
denominator
Definition: rational.h:45
A list of supported formats for one end of a filter link.
Definition: formats.h:64
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:290
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
An instance of a filter.
Definition: avfilter.h:633
int height
Definition: frame.h:220
char * x_expr_str
Definition: vf_zoompan.c:79
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:101
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_zoompan.c:123
AVFILTER_DEFINE_CLASS(zoompan)
simple arithmetic expression evaluator
double prev_zoom
Definition: vf_zoompan.c:84