FFmpeg
vf_deblock.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  * Based on paper: A Simple and Efficient Deblocking Algorithm for Low Bit-Rate Video Coding.
23  */
24 
25 #include "libavutil/imgutils.h"
26 #include "libavutil/opt.h"
27 #include "libavutil/pixdesc.h"
28 
29 #include "avfilter.h"
30 #include "formats.h"
31 #include "internal.h"
32 #include "video.h"
33 
35 
36 typedef struct DeblockContext {
37  const AVClass *class;
39  int filter;
40  int block;
41  int planes;
42  float alpha;
43  float beta;
44  float gamma;
45  float delta;
46 
47  int ath;
48  int bth;
49  int gth;
50  int dth;
51  int max;
52  int depth;
53  int bpc;
54  int nb_planes;
55  int planewidth[4];
56  int planeheight[4];
57 
58  void (*deblockh)(uint8_t *dst, ptrdiff_t dst_linesize, int block,
59  int ath, int bth, int gth, int dth, int max);
60  void (*deblockv)(uint8_t *dst, ptrdiff_t dst_linesize, int block,
61  int ath, int bth, int gth, int dth, int max);
63 
65 {
66  static const enum AVPixelFormat pixel_fmts[] = {
85  };
87  if (!formats)
88  return AVERROR(ENOMEM);
89  return ff_set_common_formats(ctx, formats);
90 }
91 
92 #define WEAK_HFILTER(name, type, ldiv) \
93 static void deblockh##name##_weak(uint8_t *dstp, ptrdiff_t dst_linesize, int block, \
94  int ath, int bth, int gth, int dth, int max) \
95 { \
96  type *dst; \
97  int x; \
98  \
99  dst = (type *)dstp; \
100  dst_linesize /= ldiv; \
101  \
102  for (x = 0; x < block; x++) { \
103  int delta = dst[x] - dst[x - dst_linesize]; \
104  int A, B, C, D, a, b, c, d; \
105  \
106  if (FFABS(delta) >= ath || \
107  FFABS(dst[x - 1 * dst_linesize] - dst[x - 2 * dst_linesize]) >= bth || \
108  FFABS(dst[x + 0 * dst_linesize] - dst[x + 1 * dst_linesize]) >= gth) \
109  continue; \
110  \
111  A = dst[x - 2 * dst_linesize]; \
112  B = dst[x - 1 * dst_linesize]; \
113  C = dst[x + 0 * dst_linesize]; \
114  D = dst[x + 1 * dst_linesize]; \
115  \
116  a = A + delta / 8; \
117  b = B + delta / 2; \
118  c = C - delta / 2; \
119  d = D - delta / 8; \
120  \
121  dst[x - 2 * dst_linesize] = av_clip(a, 0, max); \
122  dst[x - 1 * dst_linesize] = av_clip(b, 0, max); \
123  dst[x + 0 * dst_linesize] = av_clip(c, 0, max); \
124  dst[x + 1 * dst_linesize] = av_clip(d, 0, max); \
125  } \
126 }
127 
128 WEAK_HFILTER(8, uint8_t, 1)
129 WEAK_HFILTER(16, uint16_t, 2)
130 
131 #define WEAK_VFILTER(name, type, ldiv) \
132 static void deblockv##name##_weak(uint8_t *dstp, ptrdiff_t dst_linesize, int block, \
133  int ath, int bth, int gth, int dth, int max) \
134 { \
135  type *dst; \
136  int y; \
137  \
138  dst = (type *)dstp; \
139  dst_linesize /= ldiv; \
140  \
141  for (y = 0; y < block; y++) { \
142  int delta = dst[0] - dst[-1]; \
143  int A, B, C, D, a, b, c, d; \
144  \
145  if (FFABS(delta) >= ath || \
146  FFABS(dst[-1] - dst[-2]) >= bth || \
147  FFABS(dst[0] - dst[1]) >= gth) \
148  continue; \
149  \
150  A = dst[-2]; \
151  B = dst[-1]; \
152  C = dst[+0]; \
153  D = dst[+1]; \
154  \
155  a = A + delta / 8; \
156  b = B + delta / 2; \
157  c = C - delta / 2; \
158  d = D - delta / 8; \
159  \
160  dst[-2] = av_clip(a, 0, max); \
161  dst[-1] = av_clip(b, 0, max); \
162  dst[+0] = av_clip(c, 0, max); \
163  dst[+1] = av_clip(d, 0, max); \
164  \
165  dst += dst_linesize; \
166  } \
167 }
168 
169 WEAK_VFILTER(8, uint8_t, 1)
170 WEAK_VFILTER(16, uint16_t, 2)
171 
172 #define STRONG_HFILTER(name, type, ldiv) \
173 static void deblockh##name##_strong(uint8_t *dstp, ptrdiff_t dst_linesize, int block,\
174  int ath, int bth, int gth, int dth, int max) \
175 { \
176  type *dst; \
177  int x; \
178  \
179  dst = (type *)dstp; \
180  dst_linesize /= ldiv; \
181  \
182  for (x = 0; x < block; x++) { \
183  int A, B, C, D, E, F, a, b, c, d, e, f; \
184  int delta = dst[x] - dst[x - dst_linesize]; \
185  \
186  if (FFABS(delta) >= ath || \
187  FFABS(dst[x - 1 * dst_linesize] - dst[x - 2 * dst_linesize]) >= bth || \
188  FFABS(dst[x + 1 * dst_linesize] - dst[x + 2 * dst_linesize]) >= gth || \
189  FFABS(dst[x + 0 * dst_linesize] - dst[x + 1 * dst_linesize]) >= dth) \
190  continue; \
191  \
192  A = dst[x - 3 * dst_linesize]; \
193  B = dst[x - 2 * dst_linesize]; \
194  C = dst[x - 1 * dst_linesize]; \
195  D = dst[x + 0 * dst_linesize]; \
196  E = dst[x + 1 * dst_linesize]; \
197  F = dst[x + 2 * dst_linesize]; \
198  \
199  a = A + delta / 8; \
200  b = B + delta / 4; \
201  c = C + delta / 2; \
202  d = D - delta / 2; \
203  e = E - delta / 4; \
204  f = F - delta / 8; \
205  \
206  dst[x - 3 * dst_linesize] = av_clip(a, 0, max); \
207  dst[x - 2 * dst_linesize] = av_clip(b, 0, max); \
208  dst[x - 1 * dst_linesize] = av_clip(c, 0, max); \
209  dst[x + 0 * dst_linesize] = av_clip(d, 0, max); \
210  dst[x + 1 * dst_linesize] = av_clip(e, 0, max); \
211  dst[x + 2 * dst_linesize] = av_clip(f, 0, max); \
212  } \
213 }
214 
215 STRONG_HFILTER(8, uint8_t, 1)
216 STRONG_HFILTER(16, uint16_t, 2)
217 
218 #define STRONG_VFILTER(name, type, ldiv) \
219 static void deblockv##name##_strong(uint8_t *dstp, ptrdiff_t dst_linesize, int block,\
220  int ath, int bth, int gth, int dth, int max) \
221 { \
222  type *dst; \
223  int y; \
224  \
225  dst = (type *)dstp; \
226  dst_linesize /= ldiv; \
227  \
228  for (y = 0; y < block; y++) { \
229  int A, B, C, D, E, F, a, b, c, d, e, f; \
230  int delta = dst[0] - dst[-1]; \
231  \
232  if (FFABS(delta) >= ath || \
233  FFABS(dst[-1] - dst[-2]) >= bth || \
234  FFABS(dst[+1] - dst[+2]) >= gth || \
235  FFABS(dst[+0] - dst[+1]) >= dth) \
236  continue; \
237  \
238  A = dst[-3]; \
239  B = dst[-2]; \
240  C = dst[-1]; \
241  D = dst[+0]; \
242  E = dst[+1]; \
243  F = dst[+2]; \
244  \
245  a = A + delta / 8; \
246  b = B + delta / 4; \
247  c = C + delta / 2; \
248  d = D - delta / 2; \
249  e = E - delta / 4; \
250  f = F - delta / 8; \
251  \
252  dst[-3] = av_clip(a, 0, max); \
253  dst[-2] = av_clip(b, 0, max); \
254  dst[-1] = av_clip(c, 0, max); \
255  dst[+0] = av_clip(d, 0, max); \
256  dst[+1] = av_clip(e, 0, max); \
257  dst[+2] = av_clip(f, 0, max); \
258  \
259  dst += dst_linesize; \
260  } \
261 }
262 
263 STRONG_VFILTER(8, uint8_t, 1)
264 STRONG_VFILTER(16, uint16_t, 2)
265 
266 static int config_output(AVFilterLink *outlink)
267 {
268  AVFilterContext *ctx = outlink->src;
269  DeblockContext *s = ctx->priv;
270  AVFilterLink *inlink = ctx->inputs[0];
271 
272  s->desc = av_pix_fmt_desc_get(outlink->format);
273  if (!s->desc)
274  return AVERROR_BUG;
275  s->nb_planes = av_pix_fmt_count_planes(outlink->format);
276  s->depth = s->desc->comp[0].depth;
277  s->bpc = (s->depth + 7) / 8;
278  s->max = (1 << s->depth) - 1;
279  s->ath = s->alpha * s->max;
280  s->bth = s->beta * s->max;
281  s->gth = s->gamma * s->max;
282  s->dth = s->delta * s->max;
283 
284  if (s->depth <= 8 && s->filter == WEAK) {
285  s->deblockh = deblockh8_weak;
286  s->deblockv = deblockv8_weak;
287  } else if (s->depth >= 8 && s->filter == WEAK) {
288  s->deblockh = deblockh16_weak;
289  s->deblockv = deblockv16_weak;
290  }
291  if (s->depth <= 8 && s->filter == STRONG) {
292  s->deblockh = deblockh8_strong;
293  s->deblockv = deblockv8_strong;
294  } else if (s->depth >= 8 && s->filter == STRONG) {
295  s->deblockh = deblockh16_strong;
296  s->deblockv = deblockv16_strong;
297  }
298 
299  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, s->desc->log2_chroma_w);
300  s->planewidth[0] = s->planewidth[3] = inlink->w;
301 
302  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h);
303  s->planeheight[0] = s->planeheight[3] = inlink->h;
304 
305  return 0;
306 }
307 
309 {
310  AVFilterContext *ctx = inlink->dst;
311  AVFilterLink *outlink = ctx->outputs[0];
312  DeblockContext *s = ctx->priv;
313  const int block = s->block;
314  AVFrame *out;
315  int plane, x, y;
316 
317  if (av_frame_is_writable(in)) {
318  out = in;
319  } else {
320  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
321  if (!out) {
322  av_frame_free(&in);
323  return AVERROR(ENOMEM);
324  }
325  av_frame_copy_props(out, in);
326  }
327 
328  for (plane = 0; plane < s->nb_planes; plane++) {
329  const int width = s->planewidth[plane];
330  const int height = s->planeheight[plane];
331  const uint8_t *src = (const uint8_t *)in->data[plane];
332  uint8_t *dst = (uint8_t *)out->data[plane];
333 
334  if (in != out)
335  av_image_copy_plane(dst, out->linesize[plane],
336  src, in->linesize[plane],
337  width * s->bpc, height);
338 
339  if (!((1 << plane) & s->planes))
340  continue;
341 
342  for (x = block; x < width; x += block)
343  s->deblockv(dst + x * s->bpc, out->linesize[plane],
344  FFMIN(block, height), s->ath, s->bth, s->gth, s->dth, s->max);
345 
346  for (y = block; y < height; y += block) {
347  dst += out->linesize[plane] * block;
348 
349  s->deblockh(dst, out->linesize[plane],
350  FFMIN(block, width),
351  s->ath, s->bth, s->gth, s->dth, s->max);
352 
353  for (x = block; x < width; x += block) {
354  s->deblockh(dst + x * s->bpc, out->linesize[plane],
355  FFMIN(block, width - x),
356  s->ath, s->bth, s->gth, s->dth, s->max);
357  s->deblockv(dst + x * s->bpc, out->linesize[plane],
358  FFMIN(block, height - y),
359  s->ath, s->bth, s->gth, s->dth, s->max);
360  }
361  }
362  }
363 
364  if (in != out)
365  av_frame_free(&in);
366  return ff_filter_frame(outlink, out);
367 }
368 
369 #define OFFSET(x) offsetof(DeblockContext, x)
370 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
371 
372 static const AVOption deblock_options[] = {
373  { "filter", "set type of filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=STRONG},0, 1, FLAGS, "filter" },
374  { "weak", 0, 0, AV_OPT_TYPE_CONST, {.i64=WEAK}, 0, 0, FLAGS, "filter" },
375  { "strong", 0, 0, AV_OPT_TYPE_CONST, {.i64=STRONG},0, 0, FLAGS, "filter" },
376  { "block", "set size of block", OFFSET(block), AV_OPT_TYPE_INT, {.i64=8}, 4, 512, FLAGS },
377  { "alpha", "set 1st detection threshold", OFFSET(alpha), AV_OPT_TYPE_FLOAT, {.dbl=.098}, 0, 1, FLAGS },
378  { "beta", "set 2nd detection threshold", OFFSET(beta), AV_OPT_TYPE_FLOAT, {.dbl=.05}, 0, 1, FLAGS },
379  { "gamma", "set 3rd detection threshold", OFFSET(gamma), AV_OPT_TYPE_FLOAT, {.dbl=.05}, 0, 1, FLAGS },
380  { "delta", "set 4th detection threshold", OFFSET(delta), AV_OPT_TYPE_FLOAT, {.dbl=.05}, 0, 1, FLAGS },
381  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, FLAGS },
382  { NULL },
383 };
384 
385 static const AVFilterPad inputs[] = {
386  {
387  .name = "default",
388  .type = AVMEDIA_TYPE_VIDEO,
389  .filter_frame = filter_frame,
390  },
391  { NULL }
392 };
393 
394 static const AVFilterPad outputs[] = {
395  {
396  .name = "default",
397  .type = AVMEDIA_TYPE_VIDEO,
398  .config_props = config_output,
399  },
400  { NULL }
401 };
402 
403 AVFILTER_DEFINE_CLASS(deblock);
404 
406  .name = "deblock",
407  .description = NULL_IF_CONFIG_SMALL("Deblock video."),
408  .priv_size = sizeof(DeblockContext),
409  .priv_class = &deblock_class,
411  .inputs = inputs,
412  .outputs = outputs,
414 };
int plane
Definition: avisynth_c.h:384
#define NULL
Definition: coverity.c:32
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:430
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:422
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2522
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
AVOption.
Definition: opt.h:246
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:424
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:397
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:407
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:425
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:2562
Main libavfilter public API header.
AVFilter ff_vf_deblock
Definition: vf_deblock.c:405
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:403
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:367
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:391
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
static const AVOption deblock_options[]
Definition: vf_deblock.c:372
#define src
Definition: vp8dsp.c:254
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:368
#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
const char * name
Pad name.
Definition: internal.h:60
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:369
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
static const AVFilterPad inputs[]
Definition: vf_deblock.c:385
FilterType
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
AVFILTER_DEFINE_CLASS(deblock)
AVOptions.
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:421
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:402
#define height
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:400
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:392
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:429
A filter pad used for either input or output.
Definition: internal.h:54
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:569
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:202
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
void * priv
private data for use by the filter
Definition: avfilter.h:353
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:431
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:408
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:390
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_deblock.c:308
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:409
int planewidth[4]
Definition: vf_deblock.c:55
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:385
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:406
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:371
#define FFMIN(a, b)
Definition: common.h:96
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
#define width
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
AVFormatContext * ctx
Definition: movenc.c:48
#define WEAK_HFILTER(name, type, ldiv)
Definition: vf_deblock.c:92
#define s(width, name)
Definition: cbs_vp9.c:257
static const AVFilterPad outputs[]
Definition: vf_deblock.c:394
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:426
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:386
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:405
const AVPixFmtDescriptor * desc
Definition: vf_deblock.c:38
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:398
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:395
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:326
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:370
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
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:387
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:144
const char * name
Filter name.
Definition: avfilter.h:148
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:393
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:384
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static int config_output(AVFilterLink *outlink)
Definition: vf_deblock.c:266
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:396
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:404
#define flags(name, subs,...)
Definition: cbs_av1.c:561
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:388
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:394
int planeheight[4]
Definition: vf_deblock.c:56
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:309
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
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
Y , 8bpp.
Definition: pixfmt.h:74
#define STRONG_HFILTER(name, type, ldiv)
Definition: vf_deblock.c:172
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:423
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
#define FLAGS
Definition: vf_deblock.c:370
void(* deblockh)(uint8_t *dst, ptrdiff_t dst_linesize, int block, int ath, int bth, int gth, int dth, int max)
Definition: vf_deblock.c:58
static int query_formats(AVFilterContext *ctx)
Definition: vf_deblock.c:64
#define STRONG_VFILTER(name, type, ldiv)
Definition: vf_deblock.c:218
#define OFFSET(x)
Definition: vf_deblock.c:369
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:258
An instance of a filter.
Definition: avfilter.h:338
void(* deblockv)(uint8_t *dst, ptrdiff_t dst_linesize, int block, int ath, int bth, int gth, int dth, int max)
Definition: vf_deblock.c:60
FILE * out
Definition: movenc.c:54
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
formats
Definition: signature.h:48
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
#define WEAK_VFILTER(name, type, ldiv)
Definition: vf_deblock.c:131
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:399
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58