FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_phase.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004 Ville Saari
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 General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * 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/avassert.h"
22 #include "libavutil/imgutils.h"
23 #include "libavutil/pixdesc.h"
24 #include "libavutil/opt.h"
25 #include "avfilter.h"
26 #include "formats.h"
27 #include "internal.h"
28 #include "video.h"
29 
30 enum PhaseMode {
40 };
41 
42 typedef struct PhaseContext {
43  const AVClass *class;
44  int mode; ///<PhaseMode
45  AVFrame *frame; /* previous frame */
46  int nb_planes;
47  int planeheight[4];
48  int linesize[4];
49 } PhaseContext;
50 
51 #define OFFSET(x) offsetof(PhaseContext, x)
52 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
53 #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, 0, 0, FLAGS, unit }
54 
55 static const AVOption phase_options[] = {
56  { "mode", "set phase mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=AUTO_ANALYZE}, PROGRESSIVE, AUTO_ANALYZE, FLAGS, "mode" },
57  CONST("p", "progressive", PROGRESSIVE, "mode"),
58  CONST("t", "top first", TOP_FIRST, "mode"),
59  CONST("b", "bottom first", BOTTOM_FIRST, "mode"),
60  CONST("T", "top first analyze", TOP_FIRST_ANALYZE, "mode"),
61  CONST("B", "bottom first analyze", BOTTOM_FIRST_ANALYZE, "mode"),
62  CONST("u", "analyze", ANALYZE, "mode"),
63  CONST("U", "full analyze", FULL_ANALYZE, "mode"),
64  CONST("a", "auto", AUTO, "mode"),
65  CONST("A", "auto analyze", AUTO_ANALYZE, "mode"),
66  { NULL }
67 };
68 
70 
72 {
73  static const enum AVPixelFormat pix_fmts[] = {
78  };
79 
80  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
81  if (!fmts_list)
82  return AVERROR(ENOMEM);
83  return ff_set_common_formats(ctx, fmts_list);
84 }
85 
86 static int config_input(AVFilterLink *inlink)
87 {
88  PhaseContext *s = inlink->dst->priv;
89  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
90  int ret;
91 
92  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
93  return ret;
94 
95  s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
96  s->planeheight[0] = s->planeheight[3] = inlink->h;
97 
99 
100  return 0;
101 }
102 
103 /*
104  * This macro interpolates the value of both fields at a point halfway
105  * between lines and takes the squared difference. In field resolution
106  * the point is a quarter pixel below a line in one field and a quarter
107  * pixel above a line in other.
108  *
109  * (The result is actually multiplied by 25)
110  */
111 #define DIFF(a, as, b, bs) ((t) = ((*(a) - (b)[bs]) << 2) + (a)[(as) << 1] - (b)[-(bs)], (t) * (t))
112 
113 /*
114  * Find which field combination has the smallest average squared difference
115  * between the fields.
116  */
117 static enum PhaseMode analyze_plane(void *ctx, enum PhaseMode mode, AVFrame *old, AVFrame *new)
118 {
119  double bdiff, tdiff, pdiff, scale;
120  const int ns = new->linesize[0];
121  const int os = old->linesize[0];
122  const uint8_t *nptr = new->data[0];
123  const uint8_t *optr = old->data[0];
124  const int h = new->height;
125  const int w = new->width;
126  int bdif, tdif, pdif;
127 
128  if (mode == AUTO) {
129  mode = new->interlaced_frame ? new->top_field_first ?
131  } else if (mode == AUTO_ANALYZE) {
132  mode = new->interlaced_frame ? new->top_field_first ?
134  }
135 
136  if (mode <= BOTTOM_FIRST) {
137  bdiff = pdiff = tdiff = 65536.0;
138  } else {
139  int top = 0, t;
140  const uint8_t *rend, *end = nptr + (h - 2) * ns;
141 
142  bdiff = pdiff = tdiff = 0.0;
143 
144  nptr += ns;
145  optr += os;
146  while (nptr < end) {
147  pdif = tdif = bdif = 0;
148 
149  switch (mode) {
150  case TOP_FIRST_ANALYZE:
151  if (top) {
152  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
153  pdif += DIFF(nptr, ns, nptr, ns);
154  tdif += DIFF(nptr, ns, optr, os);
155  }
156  } else {
157  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
158  pdif += DIFF(nptr, ns, nptr, ns);
159  tdif += DIFF(optr, os, nptr, ns);
160  }
161  }
162  break;
164  if (top) {
165  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
166  pdif += DIFF(nptr, ns, nptr, ns);
167  bdif += DIFF(optr, os, nptr, ns);
168  }
169  } else {
170  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
171  pdif += DIFF(nptr, ns, nptr, ns);
172  bdif += DIFF(nptr, ns, optr, os);
173  }
174  }
175  break;
176  case ANALYZE:
177  if (top) {
178  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
179  tdif += DIFF(nptr, ns, optr, os);
180  bdif += DIFF(optr, os, nptr, ns);
181  }
182  } else {
183  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
184  bdif += DIFF(nptr, ns, optr, os);
185  tdif += DIFF(optr, os, nptr, ns);
186  }
187  }
188  break;
189  case FULL_ANALYZE:
190  if (top) {
191  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
192  pdif += DIFF(nptr, ns, nptr, ns);
193  tdif += DIFF(nptr, ns, optr, os);
194  bdif += DIFF(optr, os, nptr, ns);
195  }
196  } else {
197  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
198  pdif += DIFF(nptr, ns, nptr, ns);
199  bdif += DIFF(nptr, ns, optr, os);
200  tdif += DIFF(optr, os, nptr, ns);
201  }
202  }
203  break;
204  default:
205  av_assert0(0);
206  }
207 
208  pdiff += (double)pdif;
209  tdiff += (double)tdif;
210  bdiff += (double)bdif;
211  nptr += ns - w;
212  optr += os - w;
213  top ^= 1;
214  }
215 
216  scale = 1.0 / (w * (h - 3)) / 25.0;
217  pdiff *= scale;
218  tdiff *= scale;
219  bdiff *= scale;
220 
221  if (mode == TOP_FIRST_ANALYZE) {
222  bdiff = 65536.0;
223  } else if (mode == BOTTOM_FIRST_ANALYZE) {
224  tdiff = 65536.0;
225  } else if (mode == ANALYZE) {
226  pdiff = 65536.0;
227  }
228 
229  if (bdiff < pdiff && bdiff < tdiff) {
230  mode = BOTTOM_FIRST;
231  } else if (tdiff < pdiff && tdiff < bdiff) {
232  mode = TOP_FIRST;
233  } else {
234  mode = PROGRESSIVE;
235  }
236  }
237 
238  av_log(ctx, AV_LOG_DEBUG, "mode=%c tdiff=%f bdiff=%f pdiff=%f\n",
239  mode == BOTTOM_FIRST ? 'b' : mode == TOP_FIRST ? 't' : 'p',
240  tdiff, bdiff, pdiff);
241  return mode;
242 }
243 
244 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
245 {
246  AVFilterContext *ctx = inlink->dst;
247  AVFilterLink *outlink = ctx->outputs[0];
248  PhaseContext *s = ctx->priv;
249  enum PhaseMode mode;
250  int plane, top, y;
251  AVFrame *out;
252 
253  if (ctx->is_disabled) {
254  av_frame_free(&s->frame);
255  /* we keep a reference to the previous frame so the filter can start
256  * being useful as soon as it's not disabled, avoiding the 1-frame
257  * delay. */
258  s->frame = av_frame_clone(in);
259  return ff_filter_frame(outlink, in);
260  }
261 
262  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
263  if (!out) {
264  av_frame_free(&in);
265  return AVERROR(ENOMEM);
266  }
267  av_frame_copy_props(out, in);
268 
269  if (!s->frame) {
270  s->frame = in;
271  mode = PROGRESSIVE;
272  } else {
273  mode = analyze_plane(ctx, s->mode, s->frame, in);
274  }
275 
276  for (plane = 0; plane < s->nb_planes; plane++) {
277  const uint8_t *buf = s->frame->data[plane];
278  const uint8_t *from = in->data[plane];
279  uint8_t *to = out->data[plane];
280 
281  for (y = 0, top = 1; y < s->planeheight[plane]; y++, top ^= 1) {
282  memcpy(to, mode == (top ? BOTTOM_FIRST : TOP_FIRST) ? buf : from, s->linesize[plane]);
283 
284  buf += s->frame->linesize[plane];
285  from += in->linesize[plane];
286  to += out->linesize[plane];
287  }
288  }
289 
290  if (in != s->frame)
291  av_frame_free(&s->frame);
292  s->frame = in;
293  return ff_filter_frame(outlink, out);
294 }
295 
296 static av_cold void uninit(AVFilterContext *ctx)
297 {
298  PhaseContext *s = ctx->priv;
299 
300  av_frame_free(&s->frame);
301 }
302 
303 static const AVFilterPad phase_inputs[] = {
304  {
305  .name = "default",
306  .type = AVMEDIA_TYPE_VIDEO,
307  .filter_frame = filter_frame,
308  .config_props = config_input,
309  },
310  { NULL }
311 };
312 
313 static const AVFilterPad phase_outputs[] = {
314  {
315  .name = "default",
316  .type = AVMEDIA_TYPE_VIDEO,
317  },
318  { NULL }
319 };
320 
322  .name = "phase",
323  .description = NULL_IF_CONFIG_SMALL("Phase shift fields."),
324  .priv_size = sizeof(PhaseContext),
325  .priv_class = &phase_class,
326  .uninit = uninit,
328  .inputs = phase_inputs,
329  .outputs = phase_outputs,
331 };
int plane
Definition: avisynth_c.h:291
#define NULL
Definition: coverity.c:32
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
static const AVOption phase_options[]
Definition: vf_phase.c:55
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
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2130
Main libavfilter public API header.
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:176
static int query_formats(AVFilterContext *ctx)
Definition: vf_phase.c:71
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
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:686
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
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static const AVFilterPad phase_inputs[]
Definition: vf_phase.c:303
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
mode
Definition: f_perms.c:27
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
static const AVFilterPad phase_outputs[]
Definition: vf_phase.c:313
AVFilter ff_vf_phase
Definition: vf_phase.c:321
const char * from
Definition: jacosubdec.c:65
#define OFFSET(x)
Definition: vf_phase.c:51
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
#define av_log(a,...)
const char * to
Definition: webvttdec.c:34
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
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
static int config_input(AVFilterLink *inlink)
Definition: vf_phase.c:86
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
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
Definition: vf_phase.c:38
simple assert() macros that are a bit more flexible than ISO C assert().
#define FLAGS
Definition: vf_phase.c:52
PhaseMode
Definition: vf_phase.c:30
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
AVFILTER_DEFINE_CLASS(phase)
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
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:449
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
int linesize[4]
Definition: vf_phase.c:48
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:268
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_phase.c:244
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AVFrame * frame
Definition: vf_phase.c:45
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
#define CONST(name, help, val, unit)
Definition: vf_phase.c:53
void * buf
Definition: avisynth_c.h:553
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
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:88
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
int mode
PhaseMode.
Definition: vf_phase.c:44
#define DIFF(a, as, b, bs)
Definition: vf_phase.c:111
const char * name
Filter name.
Definition: avfilter.h:474
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:459
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
int nb_planes
Definition: vf_phase.c:46
int planeheight[4]
Definition: vf_phase.c:47
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 GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:287
static enum PhaseMode analyze_plane(void *ctx, enum PhaseMode mode, AVFrame *old, AVFrame *new)
Definition: vf_phase.c:117
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
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
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_phase.c:296
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
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:548