FFmpeg  2.6.9
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules 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;
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 
81  return 0;
82 }
83 
84 static int config_input(AVFilterLink *inlink)
85 {
86  PhaseContext *s = inlink->dst->priv;
87  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
88  int ret;
89 
90  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
91  return ret;
92 
93  s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
94  s->planeheight[0] = s->planeheight[3] = inlink->h;
95 
97 
98  return 0;
99 }
100 
101 /*
102  * This macro interpolates the value of both fields at a point halfway
103  * between lines and takes the squared difference. In field resolution
104  * the point is a quarter pixel below a line in one field and a quarter
105  * pixel above a line in other.
106  *
107  * (The result is actually multiplied by 25)
108  */
109 #define DIFF(a, as, b, bs) ((t) = ((*(a) - (b)[bs]) << 2) + (a)[(as) << 1] - (b)[-(bs)], (t) * (t))
110 
111 /*
112  * Find which field combination has the smallest average squared difference
113  * between the fields.
114  */
115 static enum PhaseMode analyze_plane(void *ctx, enum PhaseMode mode, AVFrame *old, AVFrame *new)
116 {
117  double bdiff, tdiff, pdiff, scale;
118  const int ns = new->linesize[0];
119  const int os = old->linesize[0];
120  const uint8_t *nptr = new->data[0];
121  const uint8_t *optr = old->data[0];
122  const int h = new->height;
123  const int w = new->width;
124  int bdif, tdif, pdif;
125 
126  if (mode == AUTO) {
127  mode = new->interlaced_frame ? new->top_field_first ?
129  } else if (mode == AUTO_ANALYZE) {
130  mode = new->interlaced_frame ? new->top_field_first ?
132  }
133 
134  if (mode <= BOTTOM_FIRST) {
135  bdiff = pdiff = tdiff = 65536.0;
136  } else {
137  int top = 0, t;
138  const uint8_t *rend, *end = nptr + (h - 2) * ns;
139 
140  bdiff = pdiff = tdiff = 0.0;
141 
142  nptr += ns;
143  optr += os;
144  while (nptr < end) {
145  pdif = tdif = bdif = 0;
146 
147  switch (mode) {
148  case TOP_FIRST_ANALYZE:
149  if (top) {
150  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
151  pdif += DIFF(nptr, ns, nptr, ns);
152  tdif += DIFF(nptr, ns, optr, os);
153  }
154  } else {
155  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
156  pdif += DIFF(nptr, ns, nptr, ns);
157  tdif += DIFF(optr, os, nptr, ns);
158  }
159  }
160  break;
162  if (top) {
163  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
164  pdif += DIFF(nptr, ns, nptr, ns);
165  bdif += DIFF(optr, os, nptr, ns);
166  }
167  } else {
168  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
169  pdif += DIFF(nptr, ns, nptr, ns);
170  bdif += DIFF(nptr, ns, optr, os);
171  }
172  }
173  break;
174  case ANALYZE:
175  if (top) {
176  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
177  tdif += DIFF(nptr, ns, optr, os);
178  bdif += DIFF(optr, os, nptr, ns);
179  }
180  } else {
181  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
182  bdif += DIFF(nptr, ns, optr, os);
183  tdif += DIFF(optr, os, nptr, ns);
184  }
185  }
186  break;
187  case FULL_ANALYZE:
188  if (top) {
189  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
190  pdif += DIFF(nptr, ns, nptr, ns);
191  tdif += DIFF(nptr, ns, optr, os);
192  bdif += DIFF(optr, os, nptr, ns);
193  }
194  } else {
195  for (rend = nptr + w; nptr < rend; nptr++, optr++) {
196  pdif += DIFF(nptr, ns, nptr, ns);
197  bdif += DIFF(nptr, ns, optr, os);
198  tdif += DIFF(optr, os, nptr, ns);
199  }
200  }
201  break;
202  default:
203  av_assert0(0);
204  }
205 
206  pdiff += (double)pdif;
207  tdiff += (double)tdif;
208  bdiff += (double)bdif;
209  nptr += ns - w;
210  optr += os - w;
211  top ^= 1;
212  }
213 
214  scale = 1.0 / (w * (h - 3)) / 25.0;
215  pdiff *= scale;
216  tdiff *= scale;
217  bdiff *= scale;
218 
219  if (mode == TOP_FIRST_ANALYZE) {
220  bdiff = 65536.0;
221  } else if (mode == BOTTOM_FIRST_ANALYZE) {
222  tdiff = 65536.0;
223  } else if (mode == ANALYZE) {
224  pdiff = 65536.0;
225  }
226 
227  if (bdiff < pdiff && bdiff < tdiff) {
228  mode = BOTTOM_FIRST;
229  } else if (tdiff < pdiff && tdiff < bdiff) {
230  mode = TOP_FIRST;
231  } else {
232  mode = PROGRESSIVE;
233  }
234  }
235 
236  av_log(ctx, AV_LOG_DEBUG, "mode=%c tdiff=%f bdiff=%f pdiff=%f\n",
237  mode == BOTTOM_FIRST ? 'b' : mode == TOP_FIRST ? 't' : 'p',
238  tdiff, bdiff, pdiff);
239  return mode;
240 }
241 
242 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
243 {
244  AVFilterContext *ctx = inlink->dst;
245  AVFilterLink *outlink = ctx->outputs[0];
246  PhaseContext *s = ctx->priv;
247  enum PhaseMode mode;
248  int plane, top, y;
249  AVFrame *out;
250 
251  if (ctx->is_disabled) {
252  av_frame_free(&s->frame);
253  /* we keep a reference to the previous frame so the filter can start
254  * being useful as soon as it's not disabled, avoiding the 1-frame
255  * delay. */
256  s->frame = av_frame_clone(in);
257  return ff_filter_frame(outlink, in);
258  }
259 
260  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
261  if (!out) {
262  av_frame_free(&in);
263  return AVERROR(ENOMEM);
264  }
265  av_frame_copy_props(out, in);
266 
267  if (!s->frame) {
268  s->frame = in;
269  mode = PROGRESSIVE;
270  } else {
271  mode = analyze_plane(ctx, s->mode, s->frame, in);
272  }
273 
274  for (plane = 0; plane < s->nb_planes; plane++) {
275  const uint8_t *buf = s->frame->data[plane];
276  const uint8_t *from = in->data[plane];
277  uint8_t *to = out->data[plane];
278 
279  for (y = 0, top = 1; y < s->planeheight[plane]; y++, top ^= 1) {
280  memcpy(to, mode == (top ? BOTTOM_FIRST : TOP_FIRST) ? buf : from, s->linesize[plane]);
281 
282  buf += s->frame->linesize[plane];
283  from += in->linesize[plane];
284  to += out->linesize[plane];
285  }
286  }
287 
288  if (in != s->frame)
289  av_frame_free(&s->frame);
290  s->frame = in;
291  return ff_filter_frame(outlink, out);
292 }
293 
294 static av_cold void uninit(AVFilterContext *ctx)
295 {
296  PhaseContext *s = ctx->priv;
297 
298  av_frame_free(&s->frame);
299 }
300 
301 static const AVFilterPad phase_inputs[] = {
302  {
303  .name = "default",
304  .type = AVMEDIA_TYPE_VIDEO,
305  .filter_frame = filter_frame,
306  .config_props = config_input,
307  },
308  { NULL }
309 };
310 
311 static const AVFilterPad phase_outputs[] = {
312  {
313  .name = "default",
314  .type = AVMEDIA_TYPE_VIDEO,
315  },
316  { NULL }
317 };
318 
320  .name = "phase",
321  .description = NULL_IF_CONFIG_SMALL("Phase shift fields."),
322  .priv_size = sizeof(PhaseContext),
323  .priv_class = &phase_class,
324  .uninit = uninit,
326  .inputs = phase_inputs,
327  .outputs = phase_outputs,
329 };
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:669
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2029
This structure describes decoded (raw) audio or video data.
Definition: frame.h:163
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:73
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:246
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2069
Main libavfilter public API header.
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:181
static int query_formats(AVFilterContext *ctx)
Definition: vf_phase.c:71
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
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:294
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:301
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:108
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:311
AVFilter ff_vf_phase
Definition: vf_phase.c:319
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 PIX_FMT_YUV440P and setting color_range ...
Definition: pixfmt.h:107
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: pixfmt.h:81
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:539
#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:267
static int config_input(AVFilterLink *inlink)
Definition: vf_phase.c:84
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:180
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:196
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:72
AVFILTER_DEFINE_CLASS(phase)
float y
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: pixfmt.h:80
ret
Definition: avfilter.c:974
enum PhaseMode mode
Definition: vf_phase.c:44
#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:364
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:191
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:266
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_phase.c:242
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
#define CONST(name, help, val, unit)
Definition: vf_phase.c:53
void * buf
Definition: avisynth_c.h:595
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:74
Describe the class of an AVClass context structure.
Definition: log.h:66
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:237
#define DIFF(a, as, b, bs)
Definition: vf_phase.c:109
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:174
int nb_planes
Definition: vf_phase.c:46
int planeheight[4]
Definition: vf_phase.c:47
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
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:68
Y , 8bpp.
Definition: pixfmt.h:76
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:285
static enum PhaseMode analyze_plane(void *ctx, enum PhaseMode mode, AVFrame *old, AVFrame *new)
Definition: vf_phase.c:115
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: pixfmt.h:82
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:75
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:288
An instance of a filter.
Definition: avfilter.h:633
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_phase.c:294
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:463