FFmpeg
vf_bilateral.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Ming Yang
3  * Copyright (c) 2019 Paul B Mahol
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #include "libavutil/imgutils.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 #include "formats.h"
29 #include "internal.h"
30 #include "video.h"
31 
32 typedef struct BilateralContext {
33  const AVClass *class;
34 
35  float sigmaS;
36  float sigmaR;
37  int planes;
38 
39  int nb_planes;
40  int depth;
41  int planewidth[4];
42  int planeheight[4];
43 
44  float alpha;
45  float range_table[65536];
46 
47  float *img_out_f;
48  float *img_temp;
49  float *map_factor_a;
50  float *map_factor_b;
53  float *line_factor_a;
54  float *line_factor_b;
56 
57 #define OFFSET(x) offsetof(BilateralContext, x)
58 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
59 
60 static const AVOption bilateral_options[] = {
61  { "sigmaS", "set spatial sigma", OFFSET(sigmaS), AV_OPT_TYPE_FLOAT, {.dbl=0.1}, 0.0, 512, FLAGS },
62  { "sigmaR", "set range sigma", OFFSET(sigmaR), AV_OPT_TYPE_FLOAT, {.dbl=0.1}, 0.0, 1, FLAGS },
63  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=1}, 0, 0xF, FLAGS },
64  { NULL }
65 };
66 
67 AVFILTER_DEFINE_CLASS(bilateral);
68 
70 {
71  static const enum AVPixelFormat pix_fmts[] = {
90  };
91 
92  return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
93 }
94 
96 {
97  BilateralContext *s = ctx->priv;
98  float inv_sigma_range;
99 
100  inv_sigma_range = 1.0f / (s->sigmaR * ((1 << s->depth) - 1));
101  s->alpha = expf(-sqrtf(2.f) / s->sigmaS);
102 
103  //compute a lookup table
104  for (int i = 0; i < (1 << s->depth); i++)
105  s->range_table[i] = s->alpha * expf(-i * inv_sigma_range);
106 
107  return 0;
108 }
109 
111 {
112  AVFilterContext *ctx = inlink->dst;
113  BilateralContext *s = ctx->priv;
115 
116  s->depth = desc->comp[0].depth;
117 
118  config_params(ctx);
119 
120  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
121  s->planewidth[0] = s->planewidth[3] = inlink->w;
122  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
123  s->planeheight[0] = s->planeheight[3] = inlink->h;
124 
126 
127  s->img_out_f = av_calloc(inlink->w * inlink->h, sizeof(float));
128  s->img_temp = av_calloc(inlink->w * inlink->h, sizeof(float));
129  s->map_factor_a = av_calloc(inlink->w * inlink->h, sizeof(float));
130  s->map_factor_b = av_calloc(inlink->w * inlink->h, sizeof(float));
131  s->slice_factor_a = av_calloc(inlink->w, sizeof(float));
132  s->slice_factor_b = av_calloc(inlink->w, sizeof(float));
133  s->line_factor_a = av_calloc(inlink->w, sizeof(float));
134  s->line_factor_b = av_calloc(inlink->w, sizeof(float));
135 
136  if (!s->img_out_f ||
137  !s->img_temp ||
138  !s->map_factor_a ||
139  !s->map_factor_b ||
140  !s->slice_factor_a ||
141  !s->slice_factor_a ||
142  !s->line_factor_a ||
143  !s->line_factor_a)
144  return AVERROR(ENOMEM);
145 
146  return 0;
147 }
148 
149 #define BILATERAL(type, name) \
150 static void bilateral_##name(BilateralContext *s, const uint8_t *ssrc, uint8_t *ddst, \
151  float sigma_spatial, float sigma_range, \
152  int width, int height, int src_linesize, int dst_linesize) \
153 { \
154  type *dst = (type *)ddst; \
155  const type *src = (const type *)ssrc; \
156  float *img_out_f = s->img_out_f, *img_temp = s->img_temp; \
157  float *map_factor_a = s->map_factor_a, *map_factor_b = s->map_factor_b; \
158  float *slice_factor_a = s->slice_factor_a, *slice_factor_b = s->slice_factor_b; \
159  float *line_factor_a = s->line_factor_a, *line_factor_b = s->line_factor_b; \
160  const float *range_table = s->range_table; \
161  const float alpha = s->alpha; \
162  float ypr, ycr, *ycy, *ypy, *xcy, fp, fc; \
163  const float inv_alpha_ = 1.f - alpha; \
164  float *ycf, *ypf, *xcf, *in_factor; \
165  const type *tcy, *tpy; \
166  int h1; \
167  \
168  for (int y = 0; y < height; y++) { \
169  float *temp_factor_x, *temp_x = &img_temp[y * width]; \
170  const type *in_x = &src[y * src_linesize]; \
171  const type *texture_x = &src[y * src_linesize]; \
172  type tpr; \
173  \
174  *temp_x++ = ypr = *in_x++; \
175  tpr = *texture_x++; \
176  \
177  temp_factor_x = &map_factor_a[y * width]; \
178  *temp_factor_x++ = fp = 1; \
179  \
180  for (int x = 1; x < width; x++) { \
181  float alpha_; \
182  int range_dist; \
183  type tcr = *texture_x++; \
184  type dr = abs(tcr - tpr); \
185  \
186  range_dist = dr; \
187  alpha_ = range_table[range_dist]; \
188  *temp_x++ = ycr = inv_alpha_*(*in_x++) + alpha_*ypr; \
189  tpr = tcr; \
190  ypr = ycr; \
191  *temp_factor_x++ = fc = inv_alpha_ + alpha_ * fp; \
192  fp = fc; \
193  } \
194  --temp_x; *temp_x = 0.5f*((*temp_x) + (*--in_x)); \
195  tpr = *--texture_x; \
196  ypr = *in_x; \
197  \
198  --temp_factor_x; *temp_factor_x = 0.5f*((*temp_factor_x) + 1); \
199  fp = 1; \
200  \
201  for (int x = width - 2; x >= 0; x--) { \
202  type tcr = *--texture_x; \
203  type dr = abs(tcr - tpr); \
204  int range_dist = dr; \
205  float alpha_ = range_table[range_dist]; \
206  \
207  ycr = inv_alpha_ * (*--in_x) + alpha_ * ypr; \
208  --temp_x; *temp_x = 0.5f*((*temp_x) + ycr); \
209  tpr = tcr; \
210  ypr = ycr; \
211  \
212  fc = inv_alpha_ + alpha_*fp; \
213  --temp_factor_x; \
214  *temp_factor_x = 0.5f*((*temp_factor_x) + fc); \
215  fp = fc; \
216  } \
217  } \
218  memcpy(img_out_f, img_temp, sizeof(float) * width); \
219  \
220  in_factor = map_factor_a; \
221  memcpy(map_factor_b, in_factor, sizeof(float) * width); \
222  for (int y = 1; y < height; y++) { \
223  tpy = &src[(y - 1) * src_linesize]; \
224  tcy = &src[y * src_linesize]; \
225  xcy = &img_temp[y * width]; \
226  ypy = &img_out_f[(y - 1) * width]; \
227  ycy = &img_out_f[y * width]; \
228  \
229  xcf = &in_factor[y * width]; \
230  ypf = &map_factor_b[(y - 1) * width]; \
231  ycf = &map_factor_b[y * width]; \
232  for (int x = 0; x < width; x++) { \
233  type dr = abs((*tcy++) - (*tpy++)); \
234  int range_dist = dr; \
235  float alpha_ = range_table[range_dist]; \
236  \
237  *ycy++ = inv_alpha_*(*xcy++) + alpha_*(*ypy++); \
238  *ycf++ = inv_alpha_*(*xcf++) + alpha_*(*ypf++); \
239  } \
240  } \
241  h1 = height - 1; \
242  ycf = line_factor_a; \
243  ypf = line_factor_b; \
244  memcpy(ypf, &in_factor[h1 * width], sizeof(float) * width); \
245  for (int x = 0; x < width; x++) \
246  map_factor_b[h1 * width + x] = 0.5f*(map_factor_b[h1 * width + x] + ypf[x]); \
247  \
248  ycy = slice_factor_a; \
249  ypy = slice_factor_b; \
250  memcpy(ypy, &img_temp[h1 * width], sizeof(float) * width); \
251  for (int x = 0, k = 0; x < width; x++) { \
252  int idx = h1 * width + x; \
253  img_out_f[idx] = 0.5f*(img_out_f[idx] + ypy[k++]) / map_factor_b[h1 * width + x]; \
254  } \
255  \
256  for (int y = h1 - 1; y >= 0; y--) { \
257  float *ycf_, *ypf_, *factor_; \
258  float *ycy_, *ypy_, *out_; \
259  \
260  tpy = &src[(y + 1) * src_linesize]; \
261  tcy = &src[y * src_linesize]; \
262  xcy = &img_temp[y * width]; \
263  ycy_ = ycy; \
264  ypy_ = ypy; \
265  out_ = &img_out_f[y * width]; \
266  \
267  xcf = &in_factor[y * width]; \
268  ycf_ = ycf; \
269  ypf_ = ypf; \
270  factor_ = &map_factor_b[y * width]; \
271  for (int x = 0; x < width; x++) { \
272  type dr = abs((*tcy++) - (*tpy++)); \
273  int range_dist = dr; \
274  float alpha_ = range_table[range_dist]; \
275  float ycc, fcc = inv_alpha_*(*xcf++) + alpha_*(*ypf_++); \
276  \
277  *ycf_++ = fcc; \
278  *factor_ = 0.5f * (*factor_ + fcc); \
279  \
280  ycc = inv_alpha_*(*xcy++) + alpha_*(*ypy_++); \
281  *ycy_++ = ycc; \
282  *out_ = 0.5f * (*out_ + ycc) / (*factor_); \
283  out_++; \
284  factor_++; \
285  } \
286  \
287  ypy = ycy; \
288  ypf = ycf; \
289  } \
290  \
291  for (int i = 0; i < height; i++) \
292  for (int j = 0; j < width; j++) \
293  dst[j + i * dst_linesize] = img_out_f[i * width + j]; \
294 }
295 
297 BILATERAL(uint16_t, word)
298 
300 {
301  AVFilterContext *ctx = inlink->dst;
302  BilateralContext *s = ctx->priv;
303  AVFilterLink *outlink = ctx->outputs[0];
304  AVFrame *out;
305 
306  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
307  if (!out) {
308  av_frame_free(&in);
309  return AVERROR(ENOMEM);
310  }
311  av_frame_copy_props(out, in);
312 
313  for (int plane = 0; plane < s->nb_planes; plane++) {
314  if (!(s->planes & (1 << plane))) {
315  av_image_copy_plane(out->data[plane], out->linesize[plane],
316  in->data[plane], in->linesize[plane],
317  s->planewidth[plane] * ((s->depth + 7) / 8), s->planeheight[plane]);
318  continue;
319  }
320 
321  if (s->depth <= 8)
322  bilateral_byte(s, in->data[plane], out->data[plane], s->sigmaS, s->sigmaR,
323  s->planewidth[plane], s->planeheight[plane],
324  in->linesize[plane], out->linesize[plane]);
325  else
326  bilateral_word(s, in->data[plane], out->data[plane], s->sigmaS, s->sigmaR,
327  s->planewidth[plane], s->planeheight[plane],
328  in->linesize[plane] / 2, out->linesize[plane] / 2);
329  }
330 
331  av_frame_free(&in);
332  return ff_filter_frame(outlink, out);
333 }
334 
336 {
337  BilateralContext *s = ctx->priv;
338 
339  av_freep(&s->img_out_f);
340  av_freep(&s->img_temp);
341  av_freep(&s->map_factor_a);
342  av_freep(&s->map_factor_b);
345  av_freep(&s->line_factor_a);
346  av_freep(&s->line_factor_b);
347 }
348 
350  const char *cmd,
351  const char *arg,
352  char *res,
353  int res_len,
354  int flags)
355 {
356  int ret = ff_filter_process_command(ctx, cmd, arg, res, res_len, flags);
357 
358  if (ret < 0)
359  return ret;
360 
361  return config_params(ctx);
362 }
363 
364 static const AVFilterPad bilateral_inputs[] = {
365  {
366  .name = "default",
367  .type = AVMEDIA_TYPE_VIDEO,
368  .config_props = config_input,
369  .filter_frame = filter_frame,
370  },
371  { NULL }
372 };
373 
374 static const AVFilterPad bilateral_outputs[] = {
375  {
376  .name = "default",
377  .type = AVMEDIA_TYPE_VIDEO,
378  },
379  { NULL }
380 };
381 
383  .name = "bilateral",
384  .description = NULL_IF_CONFIG_SMALL("Apply Bilateral filter."),
385  .priv_size = sizeof(BilateralContext),
386  .priv_class = &bilateral_class,
387  .uninit = uninit,
389  .inputs = bilateral_inputs,
390  .outputs = bilateral_outputs,
393 };
#define NULL
Definition: coverity.c:32
#define FLAGS
Definition: vf_bilateral.c:58
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:442
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:434
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
This structure describes decoded (raw) audio or video data.
Definition: frame.h:314
AVOption.
Definition: opt.h:248
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:436
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:409
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:419
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:437
const char * desc
Definition: libsvtav1.c:79
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
misc image utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2613
Main libavfilter public API header.
static int config_params(AVFilterContext *ctx)
Definition: vf_bilateral.c:95
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
float * map_factor_a
Definition: vf_bilateral.c:49
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:415
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:379
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:403
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
float * map_factor_b
Definition: vf_bilateral.c:50
float * slice_factor_b
Definition: vf_bilateral.c:52
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
float range_table[65536]
Definition: vf_bilateral.c:45
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:287
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:380
#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:126
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_bilateral.c:335
const char * name
Pad name.
Definition: internal.h:60
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:381
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1093
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:88
AVOptions.
#define f(width, name)
Definition: cbs_vp9.c:255
static const AVOption bilateral_options[]
Definition: vf_bilateral.c:60
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:433
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:414
#define OFFSET(x)
Definition: vf_bilateral.c:57
static int config_input(AVFilterLink *inlink)
Definition: vf_bilateral.c:110
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:100
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:412
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:404
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:441
A filter pad used for either input or output.
Definition: internal.h:54
#define expf(x)
Definition: libm.h:283
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.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:588
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:115
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options...
Definition: avfilter.c:881
void * priv
private data for use by the filter
Definition: avfilter.h:356
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:443
const char * arg
Definition: jacosubdec.c:66
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:420
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
float * slice_factor_a
Definition: vf_bilateral.c:51
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:421
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
#define BILATERAL(type, name)
Definition: vf_bilateral.c:149
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:397
static const AVFilterPad bilateral_inputs[]
Definition: vf_bilateral.c:364
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_bilateral.c:299
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:418
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:383
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
AVFormatContext * ctx
Definition: movenc.c:48
#define s(width, name)
Definition: cbs_vp9.c:257
AVFILTER_DEFINE_CLASS(bilateral)
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:438
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:417
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:410
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:407
static int process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Definition: vf_bilateral.c:349
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL byte
Definition: bytestream.h:91
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:345
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:382
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;}return ac;}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;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:405
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:396
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:353
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:303
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:408
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:416
#define flags(name, subs,...)
Definition: cbs_av1.c:561
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:328
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
float * line_factor_a
Definition: vf_bilateral.c:53
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
Y , 8bpp.
Definition: pixfmt.h:74
static const AVFilterPad bilateral_outputs[]
Definition: vf_bilateral.c:374
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:435
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
float * line_factor_b
Definition: vf_bilateral.c:54
AVFilter ff_vf_bilateral
Definition: vf_bilateral.c:382
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:258
An instance of a filter.
Definition: avfilter.h:341
static int query_formats(AVFilterContext *ctx)
Definition: vf_bilateral.c:69
FILE * out
Definition: movenc.c:54
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:373
internal API functions
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:411
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
int i
Definition: input.c:407
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58