FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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;
42  int debug;
44 
45 #define OFFSET(x) offsetof(TransformContext, x)
46 #define OFFSETC(x) (offsetof(TransformContext, conf)+offsetof(VSTransformConfig, x))
47 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
48 
50  {"input", "set path to the file storing the transforms", OFFSET(input),
51  AV_OPT_TYPE_STRING, {.str = DEFAULT_INPUT_NAME}, .flags = FLAGS },
52  {"smoothing", "set number of frames*2 + 1 used for lowpass filtering", OFFSETC(smoothing),
53  AV_OPT_TYPE_INT, {.i64 = 15}, 0, 1000, FLAGS},
54 
55  {"optalgo", "set camera path optimization algo", OFFSETC(camPathAlgo),
56  AV_OPT_TYPE_INT, {.i64 = VSOptimalL1}, VSOptimalL1, VSAvg, FLAGS, "optalgo"},
57  { "opt", "global optimization", 0, // from version 1.0 on
58  AV_OPT_TYPE_CONST, {.i64 = VSOptimalL1 }, 0, 0, FLAGS, "optalgo"},
59  { "gauss", "gaussian kernel", 0,
60  AV_OPT_TYPE_CONST, {.i64 = VSGaussian }, 0, 0, FLAGS, "optalgo"},
61  { "avg", "simple averaging on motion", 0,
62  AV_OPT_TYPE_CONST, {.i64 = VSAvg }, 0, 0, FLAGS, "optalgo"},
63 
64  {"maxshift", "set maximal number of pixels to translate image", OFFSETC(maxShift),
65  AV_OPT_TYPE_INT, {.i64 = -1}, -1, 500, FLAGS},
66  {"maxangle", "set maximal angle in rad to rotate image", OFFSETC(maxAngle),
67  AV_OPT_TYPE_DOUBLE, {.dbl = -1.0}, -1.0, 3.14, FLAGS},
68 
69  {"crop", "set cropping mode", OFFSETC(crop),
70  AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS, "crop"},
71  { "keep", "keep border", 0,
72  AV_OPT_TYPE_CONST, {.i64 = VSKeepBorder }, 0, 0, FLAGS, "crop"},
73  { "black", "black border", 0,
74  AV_OPT_TYPE_CONST, {.i64 = VSCropBorder }, 0, 0, FLAGS, "crop"},
75 
76  {"invert", "invert transforms", OFFSETC(invert),
77  AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS},
78  {"relative", "consider transforms as relative", OFFSETC(relative),
79  AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, FLAGS},
80  {"zoom", "set percentage to zoom (>0: zoom in, <0: zoom out", OFFSETC(zoom),
81  AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -100, 100, FLAGS},
82  {"optzoom", "set optimal zoom (0: nothing, 1: optimal static zoom, 2: optimal dynamic zoom)", OFFSETC(optZoom),
83  AV_OPT_TYPE_INT, {.i64 = 1}, 0, 2, FLAGS},
84  {"zoomspeed", "for adative zoom: percent to zoom maximally each frame", OFFSETC(zoomSpeed),
85  AV_OPT_TYPE_DOUBLE, {.dbl = 0.25}, 0, 5, FLAGS},
86 
87  {"interpol", "set type of interpolation", OFFSETC(interpolType),
88  AV_OPT_TYPE_INT, {.i64 = 2}, 0, 3, FLAGS, "interpol"},
89  { "no", "no interpolation", 0,
90  AV_OPT_TYPE_CONST, {.i64 = VS_Zero }, 0, 0, FLAGS, "interpol"},
91  { "linear", "linear (horizontal)", 0,
92  AV_OPT_TYPE_CONST, {.i64 = VS_Linear }, 0, 0, FLAGS, "interpol"},
93  { "bilinear","bi-linear", 0,
94  AV_OPT_TYPE_CONST, {.i64 = VS_BiLinear},0, 0, FLAGS, "interpol"},
95  { "bicubic", "bi-cubic", 0,
96  AV_OPT_TYPE_CONST, {.i64 = VS_BiCubic },0, 0, FLAGS, "interpol"},
97 
98  {"tripod", "enable virtual tripod mode (same as relative=0:smoothing=0)", OFFSET(tripod),
99  AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS},
100  {"debug", "enable debug mode and writer global motions information to file", OFFSET(debug),
101  AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS},
102  {NULL}
103 };
104 
105 AVFILTER_DEFINE_CLASS(vidstabtransform);
106 
107 static av_cold int init(AVFilterContext *ctx)
108 {
109  TransformContext *tc = ctx->priv;
110  ff_vs_init();
111  tc->class = &vidstabtransform_class;
112  av_log(ctx, AV_LOG_VERBOSE, "vidstabtransform filter: init %s\n", LIBVIDSTAB_VERSION);
113  return 0;
114 }
115 
116 static av_cold void uninit(AVFilterContext *ctx)
117 {
118  TransformContext *tc = ctx->priv;
119 
120  vsTransformDataCleanup(&tc->td);
121  vsTransformationsCleanup(&tc->trans);
122 }
123 
125 {
126  // If you add something here also add it in vidstabutils.c
127  static const enum AVPixelFormat pix_fmts[] = {
133  };
134 
135  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
136  if (!fmts_list)
137  return AVERROR(ENOMEM);
138  return ff_set_common_formats(ctx, fmts_list);
139 }
140 
141 
142 static int config_input(AVFilterLink *inlink)
143 {
144  AVFilterContext *ctx = inlink->dst;
145  TransformContext *tc = ctx->priv;
146  FILE *f;
147 
148  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
149 
150  VSTransformData *td = &(tc->td);
151 
152  VSFrameInfo fi_src;
153  VSFrameInfo fi_dest;
154 
155  if (!vsFrameInfoInit(&fi_src, inlink->w, inlink->h,
156  ff_av2vs_pixfmt(ctx, inlink->format)) ||
157  !vsFrameInfoInit(&fi_dest, inlink->w, inlink->h,
158  ff_av2vs_pixfmt(ctx, inlink->format))) {
159  av_log(ctx, AV_LOG_ERROR, "unknown pixel format: %i (%s)",
160  inlink->format, desc->name);
161  return AVERROR(EINVAL);
162  }
163 
164  if (fi_src.bytesPerPixel != av_get_bits_per_pixel(desc)/8 ||
165  fi_src.log2ChromaW != desc->log2_chroma_w ||
166  fi_src.log2ChromaH != desc->log2_chroma_h) {
167  av_log(ctx, AV_LOG_ERROR, "pixel-format error: bpp %i<>%i ",
168  fi_src.bytesPerPixel, av_get_bits_per_pixel(desc)/8);
169  av_log(ctx, AV_LOG_ERROR, "chroma_subsampl: w: %i<>%i h: %i<>%i\n",
170  fi_src.log2ChromaW, desc->log2_chroma_w,
171  fi_src.log2ChromaH, desc->log2_chroma_h);
172  return AVERROR(EINVAL);
173  }
174 
175  // set values that are not initializes by the options
176  tc->conf.modName = "vidstabtransform";
177  tc->conf.verbose = 1 + tc->debug;
178  if (tc->tripod) {
179  av_log(ctx, AV_LOG_INFO, "Virtual tripod mode: relative=0, smoothing=0\n");
180  tc->conf.relative = 0;
181  tc->conf.smoothing = 0;
182  }
183  tc->conf.simpleMotionCalculation = 0;
184  tc->conf.storeTransforms = tc->debug;
185  tc->conf.smoothZoom = 0;
186 
187  if (vsTransformDataInit(td, &tc->conf, &fi_src, &fi_dest) != VS_OK) {
188  av_log(ctx, AV_LOG_ERROR, "initialization of vid.stab transform failed, please report a BUG\n");
189  return AVERROR(EINVAL);
190  }
191 
192  vsTransformGetConfig(&tc->conf, td);
193  av_log(ctx, AV_LOG_INFO, "Video transformation/stabilization settings (pass 2/2):\n");
194  av_log(ctx, AV_LOG_INFO, " input = %s\n", tc->input);
195  av_log(ctx, AV_LOG_INFO, " smoothing = %d\n", tc->conf.smoothing);
196  av_log(ctx, AV_LOG_INFO, " optalgo = %s\n",
197  tc->conf.camPathAlgo == VSOptimalL1 ? "opt" :
198  (tc->conf.camPathAlgo == VSGaussian ? "gauss" : "avg"));
199  av_log(ctx, AV_LOG_INFO, " maxshift = %d\n", tc->conf.maxShift);
200  av_log(ctx, AV_LOG_INFO, " maxangle = %f\n", tc->conf.maxAngle);
201  av_log(ctx, AV_LOG_INFO, " crop = %s\n", tc->conf.crop ? "Black" : "Keep");
202  av_log(ctx, AV_LOG_INFO, " relative = %s\n", tc->conf.relative ? "True": "False");
203  av_log(ctx, AV_LOG_INFO, " invert = %s\n", tc->conf.invert ? "True" : "False");
204  av_log(ctx, AV_LOG_INFO, " zoom = %f\n", tc->conf.zoom);
205  av_log(ctx, AV_LOG_INFO, " optzoom = %s\n",
206  tc->conf.optZoom == 1 ? "Static (1)" : (tc->conf.optZoom == 2 ? "Dynamic (2)" : "Off (0)"));
207  if (tc->conf.optZoom == 2)
208  av_log(ctx, AV_LOG_INFO, " zoomspeed = %g\n", tc->conf.zoomSpeed);
209  av_log(ctx, AV_LOG_INFO, " interpol = %s\n", getInterpolationTypeName(tc->conf.interpolType));
210 
211  f = fopen(tc->input, "r");
212  if (!f) {
213  int ret = AVERROR(errno);
214  av_log(ctx, AV_LOG_ERROR, "cannot open input file %s\n", tc->input);
215  return ret;
216  } else {
217  VSManyLocalMotions mlms;
218  if (vsReadLocalMotionsFile(f, &mlms) == VS_OK) {
219  // calculate the actual transforms from the local motions
220  if (vsLocalmotions2Transforms(td, &mlms, &tc->trans) != VS_OK) {
221  av_log(ctx, AV_LOG_ERROR, "calculating transformations failed\n");
222  return AVERROR(EINVAL);
223  }
224  } else { // try to read old format
225  if (!vsReadOldTransforms(td, f, &tc->trans)) { /* read input file */
226  av_log(ctx, AV_LOG_ERROR, "error parsing input file %s\n", tc->input);
227  return AVERROR(EINVAL);
228  }
229  }
230  }
231  fclose(f);
232 
233  if (vsPreprocessTransforms(td, &tc->trans) != VS_OK) {
234  av_log(ctx, AV_LOG_ERROR, "error while preprocessing transforms\n");
235  return AVERROR(EINVAL);
236  }
237 
238  // TODO: add sharpening, so far the user needs to call the unsharp filter manually
239  return 0;
240 }
241 
242 
243 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
244 {
245  AVFilterContext *ctx = inlink->dst;
246  TransformContext *tc = ctx->priv;
247  VSTransformData* td = &(tc->td);
248 
249  AVFilterLink *outlink = inlink->dst->outputs[0];
250  int direct = 0;
251  AVFrame *out;
252  VSFrame inframe;
253  int plane;
254 
255  if (av_frame_is_writable(in)) {
256  direct = 1;
257  out = in;
258  } else {
259  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
260  if (!out) {
261  av_frame_free(&in);
262  return AVERROR(ENOMEM);
263  }
264  av_frame_copy_props(out, in);
265  }
266 
267  for (plane = 0; plane < vsTransformGetSrcFrameInfo(td)->planes; plane++) {
268  inframe.data[plane] = in->data[plane];
269  inframe.linesize[plane] = in->linesize[plane];
270  }
271  if (direct) {
272  vsTransformPrepare(td, &inframe, &inframe);
273  } else { // separate frames
274  VSFrame outframe;
275  for (plane = 0; plane < vsTransformGetDestFrameInfo(td)->planes; plane++) {
276  outframe.data[plane] = out->data[plane];
277  outframe.linesize[plane] = out->linesize[plane];
278  }
279  vsTransformPrepare(td, &inframe, &outframe);
280  }
281 
282  vsDoTransform(td, vsGetNextTransform(td, &tc->trans));
283 
284  vsTransformFinish(td);
285 
286  if (!direct)
287  av_frame_free(&in);
288 
289  return ff_filter_frame(outlink, out);
290 }
291 
293  {
294  .name = "default",
295  .type = AVMEDIA_TYPE_VIDEO,
296  .filter_frame = filter_frame,
297  .config_props = config_input,
298  },
299  { NULL }
300 };
301 
303  {
304  .name = "default",
305  .type = AVMEDIA_TYPE_VIDEO,
306  },
307  { NULL }
308 };
309 
311  .name = "vidstabtransform",
312  .description = NULL_IF_CONFIG_SMALL("Transform the frames, "
313  "pass 2 of 2 for stabilization "
314  "(see vidstabdetect for pass 1)."),
315  .priv_size = sizeof(TransformContext),
316  .init = init,
317  .uninit = uninit,
319  .inputs = avfilter_vf_vidstabtransform_inputs,
320  .outputs = avfilter_vf_vidstabtransform_outputs,
321  .priv_class = &vidstabtransform_class,
322 };
int plane
Definition: avisynth_c.h:291
#define NULL
Definition: coverity.c:32
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2090
static const AVFilterPad avfilter_vf_vidstabtransform_outputs[]
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
AVOption.
Definition: opt.h:255
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:68
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:65
const AVClass * class
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:2042
#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
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
#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:283
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
#define av_cold
Definition: attributes.h:74
AVFILTER_DEFINE_CLASS(vidstabtransform)
AVOptions.
VSTransformConfig conf
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
static int query_formats(AVFilterContext *ctx)
AVFilter ff_vf_vidstabtransform
#define av_log(a,...)
const char * name
Definition: pixdesc.h:70
A filter pad used for either input or output.
Definition: internal.h:61
#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
#define td
Definition: regdef.h:70
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
#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 av_cold void uninit(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
VSTransformData td
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:95
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
ret
Definition: avfilter.c:974
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:66
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:488
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
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
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
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
VSPixelFormat ff_av2vs_pixfmt(AVFilterContext *ctx, enum AVPixelFormat pf)
convert AV's pixelformat to vid.stab pixelformat
Definition: vidstabutils.c:24
common internal and external API header
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:70
VSTransformations trans
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
An instance of a filter.
Definition: avfilter.h:633
static const AVOption vidstabtransform_options[]
void ff_vs_init(void)
sets the memory allocation function and logging constants to av versions
Definition: vidstabutils.c:69
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:101
static av_cold int init(AVFilterContext *ctx)
#define OFFSET(x)
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:548