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 range_table[65536];
45 
46  float *img_out_f;
47  float *img_temp;
48  float *map_factor_a;
49  float *map_factor_b;
52  float *line_factor_a;
53  float *line_factor_b;
55 
56 #define OFFSET(x) offsetof(BilateralContext, x)
57 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
58 
59 static const AVOption bilateral_options[] = {
60  { "sigmaS", "set spatial sigma", OFFSET(sigmaS), AV_OPT_TYPE_FLOAT, {.dbl=0.1}, 0.0, 10, FLAGS },
61  { "sigmaR", "set range sigma", OFFSET(sigmaR), AV_OPT_TYPE_FLOAT, {.dbl=0.1}, 0.0, 1, FLAGS },
62  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=1}, 0, 0xF, FLAGS },
63  { NULL }
64 };
65 
66 AVFILTER_DEFINE_CLASS(bilateral);
67 
69 {
70  static const enum AVPixelFormat pix_fmts[] = {
89  };
90 
92 }
93 
95 {
96  BilateralContext *s = inlink->dst->priv;
98  float inv_sigma_range;
99 
100  s->depth = desc->comp[0].depth;
101  inv_sigma_range = 1.0f / (s->sigmaR * ((1 << s->depth) - 1));
102 
103  //compute a lookup table
104  for (int i = 0; i < (1 << s->depth); i++)
105  s->range_table[i] = expf(-i * inv_sigma_range);
106 
107  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
108  s->planewidth[0] = s->planewidth[3] = inlink->w;
109  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
110  s->planeheight[0] = s->planeheight[3] = inlink->h;
111 
112  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
113 
114  s->img_out_f = av_calloc(inlink->w * inlink->h, sizeof(float));
115  s->img_temp = av_calloc(inlink->w * inlink->h, sizeof(float));
116  s->map_factor_a = av_calloc(inlink->w * inlink->h, sizeof(float));
117  s->map_factor_b = av_calloc(inlink->w * inlink->h, sizeof(float));
118  s->slice_factor_a = av_calloc(inlink->w, sizeof(float));
119  s->slice_factor_b = av_calloc(inlink->w, sizeof(float));
120  s->line_factor_a = av_calloc(inlink->w, sizeof(float));
121  s->line_factor_b = av_calloc(inlink->w, sizeof(float));
122 
123  if (!s->img_out_f ||
124  !s->img_temp ||
125  !s->map_factor_a ||
126  !s->map_factor_b ||
127  !s->slice_factor_a ||
128  !s->slice_factor_a ||
129  !s->line_factor_a ||
130  !s->line_factor_a)
131  return AVERROR(ENOMEM);
132 
133  return 0;
134 }
135 
136 #define BILATERAL(type, name) \
137 static void bilateral_##name(BilateralContext *s, const uint8_t *ssrc, uint8_t *ddst, \
138  float sigma_spatial, float sigma_range, \
139  int width, int height, int src_linesize, int dst_linesize) \
140 { \
141  type *dst = (type *)ddst; \
142  const type *src = (const type *)ssrc; \
143  float *img_out_f = s->img_out_f, *img_temp = s->img_temp; \
144  float *map_factor_a = s->map_factor_a, *map_factor_b = s->map_factor_b; \
145  float *slice_factor_a = s->slice_factor_a, *slice_factor_b = s->slice_factor_b; \
146  float *line_factor_a = s->line_factor_a, *line_factor_b = s->line_factor_b; \
147  float *range_table = s->range_table; \
148  float alpha = expf(-sqrtf(2.f) / (sigma_spatial * width)); \
149  float ypr, ycr, *ycy, *ypy, *xcy, fp, fc; \
150  float inv_alpha_ = 1 - alpha; \
151  float *ycf, *ypf, *xcf, *in_factor; \
152  const type *tcy, *tpy; \
153  int h1; \
154  \
155  for (int y = 0; y < height; y++) { \
156  float *temp_factor_x, *temp_x = &img_temp[y * width]; \
157  const type *in_x = &src[y * src_linesize]; \
158  const type *texture_x = &src[y * src_linesize]; \
159  type tpr; \
160  \
161  *temp_x++ = ypr = *in_x++; \
162  tpr = *texture_x++; \
163  \
164  temp_factor_x = &map_factor_a[y * width]; \
165  *temp_factor_x++ = fp = 1; \
166  \
167  for (int x = 1; x < width; x++) { \
168  float weight, alpha_; \
169  int range_dist; \
170  type tcr = *texture_x++; \
171  type dr = abs(tcr - tpr); \
172  \
173  range_dist = dr; \
174  weight = range_table[range_dist]; \
175  alpha_ = weight*alpha; \
176  *temp_x++ = ycr = inv_alpha_*(*in_x++) + alpha_*ypr; \
177  tpr = tcr; \
178  ypr = ycr; \
179  *temp_factor_x++ = fc = inv_alpha_ + alpha_ * fp; \
180  fp = fc; \
181  } \
182  --temp_x; *temp_x = 0.5f*((*temp_x) + (*--in_x)); \
183  tpr = *--texture_x; \
184  ypr = *in_x; \
185  \
186  --temp_factor_x; *temp_factor_x = 0.5f*((*temp_factor_x) + 1); \
187  fp = 1; \
188  \
189  for (int x = width - 2; x >= 0; x--) { \
190  type tcr = *--texture_x; \
191  type dr = abs(tcr - tpr); \
192  int range_dist = dr; \
193  float weight = range_table[range_dist]; \
194  float alpha_ = weight * alpha; \
195  \
196  ycr = inv_alpha_ * (*--in_x) + alpha_ * ypr; \
197  --temp_x; *temp_x = 0.5f*((*temp_x) + ycr); \
198  tpr = tcr; \
199  ypr = ycr; \
200  \
201  fc = inv_alpha_ + alpha_*fp; \
202  --temp_factor_x; \
203  *temp_factor_x = 0.5f*((*temp_factor_x) + fc); \
204  fp = fc; \
205  } \
206  } \
207  memcpy(img_out_f, img_temp, sizeof(float) * width); \
208  \
209  alpha = expf(-sqrtf(2.f) / (sigma_spatial * height)); \
210  inv_alpha_ = 1 - alpha; \
211  in_factor = map_factor_a; \
212  memcpy(map_factor_b, in_factor, sizeof(float) * width); \
213  for (int y = 1; y < height; y++) { \
214  tpy = &src[(y - 1) * src_linesize]; \
215  tcy = &src[y * src_linesize]; \
216  xcy = &img_temp[y * width]; \
217  ypy = &img_out_f[(y - 1) * width]; \
218  ycy = &img_out_f[y * width]; \
219  \
220  xcf = &in_factor[y * width]; \
221  ypf = &map_factor_b[(y - 1) * width]; \
222  ycf = &map_factor_b[y * width]; \
223  for (int x = 0; x < width; x++) { \
224  type dr = abs((*tcy++) - (*tpy++)); \
225  int range_dist = dr; \
226  float weight = range_table[range_dist]; \
227  float alpha_ = weight*alpha; \
228  \
229  *ycy++ = inv_alpha_*(*xcy++) + alpha_*(*ypy++); \
230  *ycf++ = inv_alpha_*(*xcf++) + alpha_*(*ypf++); \
231  } \
232  } \
233  h1 = height - 1; \
234  ycf = line_factor_a; \
235  ypf = line_factor_b; \
236  memcpy(ypf, &in_factor[h1 * width], sizeof(float) * width); \
237  for (int x = 0; x < width; x++) \
238  map_factor_b[h1 * width + x] = 0.5f*(map_factor_b[h1 * width + x] + ypf[x]); \
239  \
240  ycy = slice_factor_a; \
241  ypy = slice_factor_b; \
242  memcpy(ypy, &img_temp[h1 * width], sizeof(float) * width); \
243  for (int x = 0, k = 0; x < width; x++) { \
244  int idx = h1 * width + x; \
245  img_out_f[idx] = 0.5f*(img_out_f[idx] + ypy[k++]) / map_factor_b[h1 * width + x]; \
246  } \
247  \
248  for (int y = h1 - 1; y >= 0; y--) { \
249  float *ycf_, *ypf_, *factor_; \
250  float *ycy_, *ypy_, *out_; \
251  \
252  tpy = &src[(y + 1) * src_linesize]; \
253  tcy = &src[y * src_linesize]; \
254  xcy = &img_temp[y * width]; \
255  ycy_ = ycy; \
256  ypy_ = ypy; \
257  out_ = &img_out_f[y * width]; \
258  \
259  xcf = &in_factor[y * width]; \
260  ycf_ = ycf; \
261  ypf_ = ypf; \
262  factor_ = &map_factor_b[y * width]; \
263  for (int x = 0; x < width; x++) { \
264  type dr = abs((*tcy++) - (*tpy++)); \
265  int range_dist = dr; \
266  float weight = range_table[range_dist]; \
267  float alpha_ = weight*alpha; \
268  float ycc, fcc = inv_alpha_*(*xcf++) + alpha_*(*ypf_++); \
269  \
270  *ycf_++ = fcc; \
271  *factor_ = 0.5f * (*factor_ + fcc); \
272  \
273  ycc = inv_alpha_*(*xcy++) + alpha_*(*ypy_++); \
274  *ycy_++ = ycc; \
275  *out_ = 0.5f * (*out_ + ycc) / (*factor_); \
276  out_++; \
277  factor_++; \
278  } \
279  \
280  memcpy(ypy, ycy, sizeof(float) * width); \
281  memcpy(ypf, ycf, sizeof(float) * width); \
282  } \
283  \
284  for (int i = 0; i < height; i++) \
285  for (int j = 0; j < width; j++) \
286  dst[j + i * dst_linesize] = img_out_f[i * width + j]; \
287 }
288 
289 BILATERAL(uint8_t, byte)
290 BILATERAL(uint16_t, word)
291 
293 {
294  AVFilterContext *ctx = inlink->dst;
295  BilateralContext *s = ctx->priv;
296  AVFilterLink *outlink = ctx->outputs[0];
297  AVFrame *out;
298 
299  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
300  if (!out) {
301  av_frame_free(&in);
302  return AVERROR(ENOMEM);
303  }
305 
306  for (int plane = 0; plane < s->nb_planes; plane++) {
307  if (!(s->planes & (1 << plane))) {
308  av_image_copy_plane(out->data[plane], out->linesize[plane],
309  in->data[plane], in->linesize[plane],
310  s->planewidth[plane] * ((s->depth + 7) / 8), s->planeheight[plane]);
311  continue;
312  }
313 
314  if (s->depth <= 8)
315  bilateral_byte(s, in->data[plane], out->data[plane], s->sigmaS, s->sigmaR,
316  s->planewidth[plane], s->planeheight[plane],
317  in->linesize[plane], out->linesize[plane]);
318  else
319  bilateral_word(s, in->data[plane], out->data[plane], s->sigmaS, s->sigmaR,
320  s->planewidth[plane], s->planeheight[plane],
321  in->linesize[plane] / 2, out->linesize[plane] / 2);
322  }
323 
324  av_frame_free(&in);
325  return ff_filter_frame(outlink, out);
326 }
327 
329 {
330  BilateralContext *s = ctx->priv;
331 
332  av_freep(&s->img_out_f);
333  av_freep(&s->img_temp);
334  av_freep(&s->map_factor_a);
335  av_freep(&s->map_factor_b);
336  av_freep(&s->slice_factor_a);
337  av_freep(&s->slice_factor_b);
338  av_freep(&s->line_factor_a);
339  av_freep(&s->line_factor_b);
340 }
341 
342 static const AVFilterPad bilateral_inputs[] = {
343  {
344  .name = "default",
345  .type = AVMEDIA_TYPE_VIDEO,
346  .config_props = config_input,
347  .filter_frame = filter_frame,
348  },
349  { NULL }
350 };
351 
352 static const AVFilterPad bilateral_outputs[] = {
353  {
354  .name = "default",
355  .type = AVMEDIA_TYPE_VIDEO,
356  },
357  { NULL }
358 };
359 
361  .name = "bilateral",
362  .description = NULL_IF_CONFIG_SMALL("Apply Bilateral filter."),
363  .priv_size = sizeof(BilateralContext),
364  .priv_class = &bilateral_class,
365  .uninit = uninit,
370 };
ff_get_video_buffer
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
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:440
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:419
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AVERROR
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
opt.h
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:300
out
FILE * out
Definition: movenc.c:54
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1075
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2549
inlink
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
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
BilateralContext::sigmaR
float sigmaR
Definition: vf_bilateral.c:36
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:432
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
pixdesc.h
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:439
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:434
AVOption
AVOption.
Definition: opt.h:246
BilateralContext::img_temp
float * img_temp
Definition: vf_bilateral.c:47
BilateralContext::planewidth
int planewidth[4]
Definition: vf_bilateral.c:41
expf
#define expf(x)
Definition: libm.h:283
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:397
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
BilateralContext::map_factor_a
float * map_factor_a
Definition: vf_bilateral.c:48
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
FLAGS
#define FLAGS
Definition: vf_bilateral.c:57
video.h
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:435
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:377
BilateralContext::slice_factor_b
float * slice_factor_b
Definition: vf_bilateral.c:51
av_image_copy_plane
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:338
formats.h
BilateralContext::map_factor_b
float * map_factor_b
Definition: vf_bilateral.c:49
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2589
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:431
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:415
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:413
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:441
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:395
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_bilateral.c:328
BilateralContext::range_table
float range_table[65536]
Definition: vf_bilateral.c:44
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:381
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:400
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:258
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:409
ff_set_common_formats
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:605
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:417
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_bilateral.c:292
s
#define s(width, name)
Definition: cbs_vp9.c:257
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_bilateral.c:94
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:418
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:410
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
BilateralContext::nb_planes
int nb_planes
Definition: vf_bilateral.c:39
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:394
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:408
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:380
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(bilateral)
bilateral_options
static const AVOption bilateral_options[]
Definition: vf_bilateral.c:59
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:378
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:416
OFFSET
#define OFFSET(x)
Definition: vf_bilateral.c:56
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:659
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
BilateralContext::slice_factor_a
float * slice_factor_a
Definition: vf_bilateral.c:50
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:398
inputs
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
Definition: filter_design.txt:243
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:412
BilateralContext::sigmaS
float sigmaS
Definition: vf_bilateral.c:35
BILATERAL
#define BILATERAL(type, name)
Definition: vf_bilateral.c:136
bilateral_inputs
static const AVFilterPad bilateral_inputs[]
Definition: vf_bilateral.c:342
desc
const char * desc
Definition: nvenc.c:79
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:402
BilateralContext::planes
int planes
Definition: vf_bilateral.c:37
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:404
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:436
internal.h
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#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:125
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:226
planes
static const struct @315 planes[]
in
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
Definition: audio_convert.c:326
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
BilateralContext::planeheight
int planeheight[4]
Definition: vf_bilateral.c:42
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:414
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
uint8_t
uint8_t
Definition: audio_convert.c:194
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:396
AVFilter
Filter definition.
Definition: avfilter.h:144
bilateral_outputs
static const AVFilterPad bilateral_outputs[]
Definition: vf_bilateral.c:352
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:433
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:401
BilateralContext::depth
int depth
Definition: vf_bilateral.c:40
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:406
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
avfilter.h
BilateralContext::line_factor_b
float * line_factor_b
Definition: vf_bilateral.c:53
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
BilateralContext
Definition: vf_bilateral.c:32
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
BilateralContext::line_factor_a
float * line_factor_a
Definition: vf_bilateral.c:52
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
BilateralContext::img_out_f
float * img_out_f
Definition: vf_bilateral.c:46
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:403
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:407
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:379
ff_vf_bilateral
AVFilter ff_vf_bilateral
Definition: vf_bilateral.c:360
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_bilateral.c:68
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:405