FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_extractplanes.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 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 #include "libavutil/avstring.h"
22 #include "libavutil/imgutils.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/pixdesc.h"
25 #include "avfilter.h"
26 #include "drawutils.h"
27 #include "internal.h"
28 
29 #define PLANE_R 0x01
30 #define PLANE_G 0x02
31 #define PLANE_B 0x04
32 #define PLANE_A 0x08
33 #define PLANE_Y 0x10
34 #define PLANE_U 0x20
35 #define PLANE_V 0x40
36 
37 typedef struct {
38  const AVClass *class;
40  int map[4];
41  int linesize[4];
43  int depth;
44  int step;
46 
47 #define OFFSET(x) offsetof(ExtractPlanesContext, x)
48 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
49 static const AVOption extractplanes_options[] = {
50  { "planes", "set planes", OFFSET(requested_planes), AV_OPT_TYPE_FLAGS, {.i64=1}, 1, 0xff, FLAGS, "flags"},
51  { "y", "set luma plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_Y}, 0, 0, FLAGS, "flags"},
52  { "u", "set u plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_U}, 0, 0, FLAGS, "flags"},
53  { "v", "set v plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_V}, 0, 0, FLAGS, "flags"},
54  { "r", "set red plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_R}, 0, 0, FLAGS, "flags"},
55  { "g", "set green plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_G}, 0, 0, FLAGS, "flags"},
56  { "b", "set blue plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_B}, 0, 0, FLAGS, "flags"},
57  { "a", "set alpha plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_A}, 0, 0, FLAGS, "flags"},
58  { NULL }
59 };
60 
61 AVFILTER_DEFINE_CLASS(extractplanes);
62 
64 {
65  static const enum AVPixelFormat in_pixfmts[] = {
93  };
94  static const enum AVPixelFormat out8_pixfmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE };
95  static const enum AVPixelFormat out16le_pixfmts[] = { AV_PIX_FMT_GRAY16LE, AV_PIX_FMT_NONE };
96  static const enum AVPixelFormat out16be_pixfmts[] = { AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_NONE };
97  const enum AVPixelFormat *out_pixfmts;
98  const AVPixFmtDescriptor *desc;
99  AVFilterFormats *avff;
100  int i, depth = 0, be = 0;
101 
102  if (!ctx->inputs[0]->in_formats ||
103  !ctx->inputs[0]->in_formats->nb_formats) {
104  return AVERROR(EAGAIN);
105  }
106 
107  if (!ctx->inputs[0]->out_formats)
108  ff_formats_ref(ff_make_format_list(in_pixfmts), &ctx->inputs[0]->out_formats);
109 
110  avff = ctx->inputs[0]->in_formats;
111  desc = av_pix_fmt_desc_get(avff->formats[0]);
112  depth = desc->comp[0].depth_minus1;
113  be = desc->flags & AV_PIX_FMT_FLAG_BE;
114  for (i = 1; i < avff->nb_formats; i++) {
115  desc = av_pix_fmt_desc_get(avff->formats[i]);
116  if (depth != desc->comp[0].depth_minus1 ||
117  be != (desc->flags & AV_PIX_FMT_FLAG_BE)) {
118  return AVERROR(EAGAIN);
119  }
120  }
121 
122  if (depth == 7)
123  out_pixfmts = out8_pixfmts;
124  else if (be)
125  out_pixfmts = out16be_pixfmts;
126  else
127  out_pixfmts = out16le_pixfmts;
128 
129  for (i = 0; i < ctx->nb_outputs; i++)
130  ff_formats_ref(ff_make_format_list(out_pixfmts), &ctx->outputs[i]->in_formats);
131  return 0;
132 }
133 
134 static int config_input(AVFilterLink *inlink)
135 {
136  AVFilterContext *ctx = inlink->dst;
137  ExtractPlanesContext *s = ctx->priv;
138  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
139  int plane_avail, ret, i;
140  uint8_t rgba_map[4];
141 
142  plane_avail = ((desc->flags & AV_PIX_FMT_FLAG_RGB) ? PLANE_R|PLANE_G|PLANE_B :
143  PLANE_Y |
144  ((desc->nb_components > 2) ? PLANE_U|PLANE_V : 0)) |
145  ((desc->flags & AV_PIX_FMT_FLAG_ALPHA) ? PLANE_A : 0);
146  if (s->requested_planes & ~plane_avail) {
147  av_log(ctx, AV_LOG_ERROR, "Requested planes not available.\n");
148  return AVERROR(EINVAL);
149  }
150  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
151  return ret;
152 
153  s->depth = (desc->comp[0].depth_minus1 + 1) >> 3;
154  s->step = av_get_padded_bits_per_pixel(desc) >> 3;
156  if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
157  ff_fill_rgba_map(rgba_map, inlink->format);
158  for (i = 0; i < 4; i++)
159  s->map[i] = rgba_map[s->map[i]];
160  }
161 
162  return 0;
163 }
164 
165 static int config_output(AVFilterLink *outlink)
166 {
167  AVFilterContext *ctx = outlink->src;
168  AVFilterLink *inlink = ctx->inputs[0];
169  ExtractPlanesContext *s = ctx->priv;
170  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
171  const int output = outlink->srcpad - ctx->output_pads;
172 
173  if (s->map[output] == 1 || s->map[output] == 2) {
174  outlink->h = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
175  outlink->w = FF_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
176  }
177 
178  return 0;
179 }
180 
181 static void extract_from_packed(uint8_t *dst, int dst_linesize,
182  const uint8_t *src, int src_linesize,
183  int width, int height,
184  int depth, int step, int comp)
185 {
186  int x, y;
187 
188  for (y = 0; y < height; y++) {
189  switch (depth) {
190  case 1:
191  for (x = 0; x < width; x++)
192  dst[x] = src[x * step + comp];
193  break;
194  case 2:
195  for (x = 0; x < width; x++) {
196  dst[x * 2 ] = src[x * step + comp * 2 ];
197  dst[x * 2 + 1] = src[x * step + comp * 2 + 1];
198  }
199  break;
200  }
201  dst += dst_linesize;
202  src += src_linesize;
203  }
204 }
205 
206 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
207 {
208  AVFilterContext *ctx = inlink->dst;
209  ExtractPlanesContext *s = ctx->priv;
210  int i, eof = 0, ret = 0;
211 
212  for (i = 0; i < ctx->nb_outputs; i++) {
213  AVFilterLink *outlink = ctx->outputs[i];
214  const int idx = s->map[i];
215  AVFrame *out;
216 
217  if (outlink->closed)
218  continue;
219 
220  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
221  if (!out) {
222  ret = AVERROR(ENOMEM);
223  break;
224  }
225  av_frame_copy_props(out, frame);
226 
227  if (s->is_packed_rgb) {
228  extract_from_packed(out->data[0], out->linesize[0],
229  frame->data[0], frame->linesize[0],
230  outlink->w, outlink->h,
231  s->depth,
232  s->step, idx);
233  } else {
234  av_image_copy_plane(out->data[0], out->linesize[0],
235  frame->data[idx], frame->linesize[idx],
236  s->linesize[idx], outlink->h);
237  }
238 
239  ret = ff_filter_frame(outlink, out);
240  if (ret == AVERROR_EOF)
241  eof++;
242  else if (ret < 0)
243  break;
244  }
245  av_frame_free(&frame);
246 
247  if (eof == ctx->nb_outputs)
248  ret = AVERROR_EOF;
249  else if (ret == AVERROR_EOF)
250  ret = 0;
251  return ret;
252 }
253 
254 static av_cold int init(AVFilterContext *ctx)
255 {
256  ExtractPlanesContext *s = ctx->priv;
257  int planes = (s->requested_planes & 0xf) | (s->requested_planes >> 4);
258  int i;
259 
260  for (i = 0; i < 4; i++) {
261  char *name;
262  AVFilterPad pad = { 0 };
263 
264  if (!(planes & (1 << i)))
265  continue;
266 
267  name = av_asprintf("out%d", ctx->nb_outputs);
268  if (!name)
269  return AVERROR(ENOMEM);
270  s->map[ctx->nb_outputs] = i;
271  pad.name = name;
272  pad.type = AVMEDIA_TYPE_VIDEO;
274 
275  ff_insert_outpad(ctx, ctx->nb_outputs, &pad);
276  }
277 
278  return 0;
279 }
280 
281 static av_cold void uninit(AVFilterContext *ctx)
282 {
283  int i;
284 
285  for (i = 0; i < ctx->nb_outputs; i++)
286  av_freep(&ctx->output_pads[i].name);
287 }
288 
290  {
291  .name = "default",
292  .type = AVMEDIA_TYPE_VIDEO,
293  .filter_frame = filter_frame,
294  .config_props = config_input,
295  },
296  { NULL }
297 };
298 
300  .name = "extractplanes",
301  .description = NULL_IF_CONFIG_SMALL("Extract planes as grayscale frames."),
302  .priv_size = sizeof(ExtractPlanesContext),
303  .priv_class = &extractplanes_class,
304  .init = init,
305  .uninit = uninit,
307  .inputs = extractplanes_inputs,
308  .outputs = NULL,
310 };
311 
312 #if CONFIG_ALPHAEXTRACT_FILTER
313 
314 static av_cold int init_alphaextract(AVFilterContext *ctx)
315 {
316  ExtractPlanesContext *s = ctx->priv;
317 
319 
320  return init(ctx);
321 }
322 
323 AVFilter ff_vf_alphaextract = {
324  .name = "alphaextract",
325  .description = NULL_IF_CONFIG_SMALL("Extract an alpha channel as a "
326  "grayscale image component."),
327  .priv_size = sizeof(ExtractPlanesContext),
328  .init = init_alphaextract,
329  .uninit = uninit,
331  .inputs = extractplanes_inputs,
332  .outputs = NULL,
334 };
335 #endif /* CONFIG_ALPHAEXTRACT_FILTER */
#define NULL
Definition: coverity.c:32
static const AVFilterPad extractplanes_inputs[]
#define PLANE_U
const char * s
Definition: avisynth_c.h:631
#define PLANE_A
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2090
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
AVFILTER_DEFINE_CLASS(extractplanes)
AVOption.
Definition: opt.h:255
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:262
static av_cold void uninit(AVFilterContext *ctx)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:68
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
#define OFFSET(x)
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:65
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:176
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:261
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:72
static int config_input(AVFilterLink *inlink)
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
#define FLAGS
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:128
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:67
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:641
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:288
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:204
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1145
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:647
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:103
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:100
uint8_t
#define av_cold
Definition: attributes.h:74
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:156
AVOptions.
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:112
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:259
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:96
static AVFrame * frame
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:205
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:181
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:102
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:76
#define AVERROR_EOF
End of file.
Definition: error.h:55
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:208
static void extract_from_packed(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int width, int height, int depth, int step, int comp)
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition: avfilter.h:437
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:61
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:269
uint16_t depth_minus1
Number of bits in the component minus 1.
Definition: pixdesc.h:57
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
static const AVOption extractplanes_options[]
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:133
#define AVERROR(e)
Definition: error.h:43
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:131
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
unsigned nb_outputs
number of output pads
Definition: avfilter.h:652
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:97
void * priv
private data for use by the filter
Definition: avfilter.h:654
int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel for the pixel format described by pixdesc, including any padding ...
Definition: pixdesc.c:2055
static int config_output(AVFilterLink *outlink)
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:131
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:94
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:149
int depth
Definition: v4l.c:61
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:95
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
AVFilter ff_vf_extractplanes
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:146
float y
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:75
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:422
ret
Definition: avfilter.c:974
#define FF_CEIL_RSHIFT(a, b)
Definition: common.h:57
unsigned nb_formats
number of formats
Definition: formats.h:65
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:66
#define PLANE_Y
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:148
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:33
#define PLANE_V
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:129
#define PLANE_R
AVS_Value src
Definition: avisynth_c.h:482
misc drawing utilities
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
static int query_formats(AVFilterContext *ctx)
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:268
uint8_t flags
Definition: pixdesc.h:90
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:206
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:69
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:207
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:88
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:209
Y , 16bpp, big-endian.
Definition: pixfmt.h:99
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
#define PLANE_G
const char * name
Filter name.
Definition: avfilter.h:474
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
static av_cold int init(AVFilterContext *ctx)
static int flags
Definition: cpu.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:132
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
Y , 8bpp.
Definition: pixfmt.h:71
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:287
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:111
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:130
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:77
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:70
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
Definition: pixdesc.h:111
Y , 16bpp, little-endian.
Definition: pixfmt.h:100
A list of supported formats for one end of a filter link.
Definition: formats.h:64
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
An instance of a filter.
Definition: avfilter.h:633
#define PLANE_B
#define av_freep(p)
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:136
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:83
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:101
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:182
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:273
internal API functions
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:289
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
Definition: internal.h:283
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:127
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:548
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:260
const char * name
Definition: opengl_enc.c:103
int * formats
list of media formats
Definition: formats.h:66
static int width