FFmpeg  2.1.1
vf_vidstabtransform.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Georg Martius <georg dot martius at web dot de>
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 #define DEFAULT_INPUT_NAME "transforms.trf"
22 
23 #include <vid.stab/libvidstab.h>
24 
25 #include "libavutil/common.h"
26 #include "libavutil/opt.h"
27 #include "libavutil/imgutils.h"
28 #include "avfilter.h"
29 #include "internal.h"
30 
31 #include "vidstabutils.h"
32 
33 typedef struct {
34  const AVClass *class;
35 
36  VSTransformData td;
37  VSTransformConfig conf;
38 
39  VSTransformations trans; // transformations
40  char *input; // name of transform file
41  int tripod;
43 
44 #define OFFSET(x) offsetof(TransformContext, x)
45 #define OFFSETC(x) (offsetof(TransformContext, conf)+offsetof(VSTransformConfig, x))
46 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
47 
49  {"input", "path to the file storing the transforms", OFFSET(input),
50  AV_OPT_TYPE_STRING, {.str = DEFAULT_INPUT_NAME}, .flags = FLAGS },
51  {"smoothing", "number of frames*2 + 1 used for lowpass filtering", OFFSETC(smoothing),
52  AV_OPT_TYPE_INT, {.i64 = 10}, 1, 1000, FLAGS},
53  {"maxshift", "maximal number of pixels to translate image", OFFSETC(maxShift),
54  AV_OPT_TYPE_INT, {.i64 = -1}, -1, 500, FLAGS},
55  {"maxangle", "maximal angle in rad to rotate image", OFFSETC(maxAngle),
56  AV_OPT_TYPE_DOUBLE, {.dbl = -1.0}, -1.0, 3.14, FLAGS},
57  {"crop", "set cropping mode", OFFSETC(crop),
58  AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS, "crop"},
59  { "keep", "keep border", 0,
60  AV_OPT_TYPE_CONST, {.i64 = VSKeepBorder }, 0, 0, FLAGS, "crop"},
61  { "black", "black border", 0,
62  AV_OPT_TYPE_CONST, {.i64 = VSCropBorder }, 0, 0, FLAGS, "crop"},
63  {"invert", "1: invert transforms", OFFSETC(invert),
64  AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS},
65  {"relative", "consider transforms as 0: absolute, 1: relative", OFFSETC(relative),
66  AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, FLAGS},
67  {"zoom", "percentage to zoom >0: zoom in, <0 zoom out", OFFSETC(zoom),
68  AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -100, 100, FLAGS},
69  {"optzoom", "0: nothing, 1: determine optimal zoom (added to 'zoom')", OFFSETC(optZoom),
70  AV_OPT_TYPE_INT, {.i64 = 1}, 0, 2, FLAGS},
71  {"interpol", "type of interpolation", OFFSETC(interpolType),
72  AV_OPT_TYPE_INT, {.i64 = 2}, 0, 3, FLAGS, "interpol"},
73  { "no", "no interpolation", 0,
74  AV_OPT_TYPE_CONST, {.i64 = VS_Zero }, 0, 0, FLAGS, "interpol"},
75  { "linear", "linear (horizontal)", 0,
76  AV_OPT_TYPE_CONST, {.i64 = VS_Linear }, 0, 0, FLAGS, "interpol"},
77  { "bilinear","bi-linear", 0,
78  AV_OPT_TYPE_CONST, {.i64 = VS_BiLinear},0, 0, FLAGS, "interpol"},
79  { "bicubic", "bi-cubic", 0,
80  AV_OPT_TYPE_CONST, {.i64 = VS_BiCubic },0, 0, FLAGS, "interpol"},
81  {"tripod", "if 1: virtual tripod mode (equiv. to relative=0:smoothing=0)", OFFSET(tripod),
82  AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS},
83  {NULL}
84 };
85 
86 AVFILTER_DEFINE_CLASS(vidstabtransform);
87 
88 static av_cold int init(AVFilterContext *ctx)
89 {
90  TransformContext *tc = ctx->priv;
92  tc->class = &vidstabtransform_class;
93  av_log(ctx, AV_LOG_VERBOSE, "vidstabtransform filter: init %s\n", LIBVIDSTAB_VERSION);
94  return 0;
95 }
96 
97 static av_cold void uninit(AVFilterContext *ctx)
98 {
99  TransformContext *tc = ctx->priv;
100 
101  vsTransformDataCleanup(&tc->td);
102  vsTransformationsCleanup(&tc->trans);
103 }
104 
106 {
107  // If you add something here also add it in vidstabutils.c
108  static const enum AVPixelFormat pix_fmts[] = {
114  };
115 
117  return 0;
118 }
119 
120 
121 static int config_input(AVFilterLink *inlink)
122 {
123  AVFilterContext *ctx = inlink->dst;
124  TransformContext *tc = ctx->priv;
125  FILE *f;
126 
127  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
128 
129  VSTransformData *td = &(tc->td);
130 
131  VSFrameInfo fi_src;
132  VSFrameInfo fi_dest;
133 
134  if (!vsFrameInfoInit(&fi_src, inlink->w, inlink->h,
135  av_2_vs_pixel_format(ctx, inlink->format)) ||
136  !vsFrameInfoInit(&fi_dest, inlink->w, inlink->h,
137  av_2_vs_pixel_format(ctx, inlink->format))) {
138  av_log(ctx, AV_LOG_ERROR, "unknown pixel format: %i (%s)",
139  inlink->format, desc->name);
140  return AVERROR(EINVAL);
141  }
142 
143  if (fi_src.bytesPerPixel != av_get_bits_per_pixel(desc)/8 ||
144  fi_src.log2ChromaW != desc->log2_chroma_w ||
145  fi_src.log2ChromaH != desc->log2_chroma_h) {
146  av_log(ctx, AV_LOG_ERROR, "pixel-format error: bpp %i<>%i ",
147  fi_src.bytesPerPixel, av_get_bits_per_pixel(desc)/8);
148  av_log(ctx, AV_LOG_ERROR, "chroma_subsampl: w: %i<>%i h: %i<>%i\n",
149  fi_src.log2ChromaW, desc->log2_chroma_w,
150  fi_src.log2ChromaH, desc->log2_chroma_h);
151  return AVERROR(EINVAL);
152  }
153 
154  // set values that are not initializes by the options
155  tc->conf.modName = "vidstabtransform";
156  tc->conf.verbose =1;
157  if (tc->tripod) {
158  av_log(ctx, AV_LOG_INFO, "Virtual tripod mode: relative=0, smoothing=0");
159  tc->conf.relative = 0;
160  tc->conf.smoothing = 0;
161  }
162 
163  if (vsTransformDataInit(td, &tc->conf, &fi_src, &fi_dest) != VS_OK) {
164  av_log(ctx, AV_LOG_ERROR, "initialization of vid.stab transform failed, please report a BUG\n");
165  return AVERROR(EINVAL);
166  }
167 
168  vsTransformGetConfig(&tc->conf, td);
169  av_log(ctx, AV_LOG_INFO, "Video transformation/stabilization settings (pass 2/2):\n");
170  av_log(ctx, AV_LOG_INFO, " input = %s\n", tc->input);
171  av_log(ctx, AV_LOG_INFO, " smoothing = %d\n", tc->conf.smoothing);
172  av_log(ctx, AV_LOG_INFO, " maxshift = %d\n", tc->conf.maxShift);
173  av_log(ctx, AV_LOG_INFO, " maxangle = %f\n", tc->conf.maxAngle);
174  av_log(ctx, AV_LOG_INFO, " crop = %s\n", tc->conf.crop ? "Black" : "Keep");
175  av_log(ctx, AV_LOG_INFO, " relative = %s\n", tc->conf.relative ? "True": "False");
176  av_log(ctx, AV_LOG_INFO, " invert = %s\n", tc->conf.invert ? "True" : "False");
177  av_log(ctx, AV_LOG_INFO, " zoom = %f\n", tc->conf.zoom);
178  av_log(ctx, AV_LOG_INFO, " optzoom = %s\n", tc->conf.optZoom ? "On" : "Off");
179  av_log(ctx, AV_LOG_INFO, " interpol = %s\n", getInterpolationTypeName(tc->conf.interpolType));
180 
181  f = fopen(tc->input, "r");
182  if (f == NULL) {
183  av_log(ctx, AV_LOG_ERROR, "cannot open input file %s\n", tc->input);
184  return AVERROR(errno);
185  } else {
186  VSManyLocalMotions mlms;
187  if (vsReadLocalMotionsFile(f, &mlms) == VS_OK) {
188  // calculate the actual transforms from the local motions
189  if (vsLocalmotions2TransformsSimple(td, &mlms, &tc->trans) != VS_OK) {
190  av_log(ctx, AV_LOG_ERROR, "calculating transformations failed\n");
191  return AVERROR(EINVAL);
192  }
193  } else { // try to read old format
194  if (!vsReadOldTransforms(td, f, &tc->trans)) { /* read input file */
195  av_log(ctx, AV_LOG_ERROR, "error parsing input file %s\n", tc->input);
196  return AVERROR(EINVAL);
197  }
198  }
199  }
200  fclose(f);
201 
202  if (vsPreprocessTransforms(td, &tc->trans) != VS_OK ) {
203  av_log(ctx, AV_LOG_ERROR, "error while preprocessing transforms\n");
204  return AVERROR(EINVAL);
205  }
206 
207  // TODO: add sharpening, so far the user needs to call the unsharp filter manually
208  return 0;
209 }
210 
211 
212 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
213 {
214  AVFilterContext *ctx = inlink->dst;
215  TransformContext *tc = ctx->priv;
216  VSTransformData* td = &(tc->td);
217 
218  AVFilterLink *outlink = inlink->dst->outputs[0];
219  int direct = 0;
220  AVFrame *out;
221  VSFrame inframe;
222  int plane;
223 
224  if (av_frame_is_writable(in)) {
225  direct = 1;
226  out = in;
227  } else {
228  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
229  if (!out) {
230  av_frame_free(&in);
231  return AVERROR(ENOMEM);
232  }
233  av_frame_copy_props(out, in);
234  }
235 
236  for (plane = 0; plane < vsTransformGetSrcFrameInfo(td)->planes; plane++) {
237  inframe.data[plane] = in->data[plane];
238  inframe.linesize[plane] = in->linesize[plane];
239  }
240  if (direct) {
241  vsTransformPrepare(td, &inframe, &inframe);
242  } else { // separate frames
243  VSFrame outframe;
244  for (plane = 0; plane < vsTransformGetDestFrameInfo(td)->planes; plane++) {
245  outframe.data[plane] = out->data[plane];
246  outframe.linesize[plane] = out->linesize[plane];
247  }
248  vsTransformPrepare(td, &inframe, &outframe);
249  }
250 
251  vsDoTransform(td, vsGetNextTransform(td, &tc->trans));
252 
253  vsTransformFinish(td);
254 
255  if (!direct)
256  av_frame_free(&in);
257 
258  return ff_filter_frame(outlink, out);
259 }
260 
262  {
263  .name = "default",
264  .type = AVMEDIA_TYPE_VIDEO,
265  .filter_frame = filter_frame,
266  .config_props = config_input,
267  },
268  { NULL }
269 };
270 
272  {
273  .name = "default",
274  .type = AVMEDIA_TYPE_VIDEO,
275  },
276  { NULL }
277 };
278 
280  .name = "vidstabtransform",
281  .description = NULL_IF_CONFIG_SMALL("Transform the frames, "
282  "pass 2 of 2 for stabilization "
283  "(see vidstabdetect for pass 1)."),
284  .priv_size = sizeof(TransformContext),
285  .init = init,
286  .uninit = uninit,
288  .inputs = avfilter_vf_vidstabtransform_inputs,
289  .outputs = avfilter_vf_vidstabtransform_outputs,
290  .priv_class = &vidstabtransform_class,
291 };
static const AVFilterPad avfilter_vf_vidstabtransform_outputs[]
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
AVOption.
Definition: opt.h:253
const char * name
Filter name.
Definition: avfilter.h:468
void * priv
private data for use by the filter
Definition: avfilter.h:648
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:111
const AVClass * class
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: avcodec.h:4536
planar YUV 4:2:2, 16bpp, (1 Cr &amp; Cb sample per 2x1 Y samples)
Definition: avcodec.h:4538
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
#define tc
Definition: regdef.h:69
#define OFFSETC(x)
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
Pixel format.
Definition: avcodec.h:4533
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:382
#define av_cold
Definition: avcodec.h:653
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:68
Y , 8bpp.
Definition: avcodec.h:4542
#define DEFAULT_INPUT_NAME
static const AVFilterPad avfilter_vf_vidstabtransform_inputs[]
#define FLAGS
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:294
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: avcodec.h:4537
const char * name
Pad name.
Definition: internal.h:66
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1118
const char * name
Definition: pixdesc.h:58
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only &quot;metadata&quot; fields from src to dst.
Definition: frame.c:446
VSPixelFormat av_2_vs_pixel_format(AVFilterContext *ctx, enum AVPixelFormat pf)
convert AV&#39;s pixelformat to vid.stab pixelformat
Definition: vidstabutils.c:24
VSTransformConfig conf
#define AV_LOG_VERBOSE
Detailed information.
Definition: avcodec.h:4163
static int query_formats(AVFilterContext *ctx)
planar YUV 4:2:0, 20bpp, (1 Cr &amp; Cb sample per 2x2 Y &amp; A samples)
Definition: avcodec.h:4571
void 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:531
void vs_set_mem_and_log_functions(void)
sets the memory allocation function and logging constants to av versions
Definition: vidstabutils.c:69
AVFilter avfilter_vf_vidstabtransform
A filter pad used for either input or output.
Definition: internal.h:60
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
#define td
Definition: regdef.h:70
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:77
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
static av_cold void uninit(AVFilterContext *ctx)
planar YUV 4:1:1, 12bpp, (1 Cr &amp; Cb sample per 4x1 Y samples)
Definition: avcodec.h:4541
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:123
static int config_input(AVFilterLink *inlink)
VSTransformData td
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:1891
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Main libavfilter public API header.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1938
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:642
planar YUV 4:2:0, 12bpp, (1 Cr &amp; Cb sample per 2x2 Y samples)
Definition: avcodec.h:4534
planar YUV 4:4:0 (1 Cr &amp; Cb sample per 1x2 Y samples)
Definition: avcodec.h:4569
#define AV_LOG_INFO
Standard information.
Definition: avcodec.h:4158
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:57
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:464
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:102
planar YUV 4:4:4, 24bpp, (1 Cr &amp; Cb sample per 1x1 Y samples)
Definition: avcodec.h:4539
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
VSTransformations trans
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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 AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:301
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: avcodec.h:4563
#define AVERROR(e)
An instance of a filter.
Definition: avfilter.h:627
static const AVOption vidstabtransform_options[]
static av_cold int init(AVFilterContext *ctx)
#define OFFSET(x)
internal API functions
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
planar YUV 4:1:0, 9bpp, (1 Cr &amp; Cb sample per 4x4 Y samples)
Definition: avcodec.h:4540