lavfi.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
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  * @file
23  * libavfilter virtual input device
24  */
25 
26 /* #define DEBUG */
27 
28 #include <float.h> /* DBL_MIN, DBL_MAX */
29 
30 #include "libavutil/bprint.h"
32 #include "libavutil/file.h"
33 #include "libavutil/log.h"
34 #include "libavutil/mem.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/parseutils.h"
37 #include "libavutil/pixdesc.h"
38 #include "libavfilter/avfilter.h"
40 #include "libavfilter/buffersink.h"
41 #include "libavformat/internal.h"
42 #include "avdevice.h"
43 
44 typedef struct {
45  AVClass *class; ///< class for private options
46  char *graph_str;
48  char *dump_graph;
52  int *sink_eof;
55 } LavfiContext;
56 
57 static int *create_all_formats(int n)
58 {
59  int i, j, *fmts, count = 0;
60 
61  for (i = 0; i < n; i++) {
62  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
63  if (!(desc->flags & PIX_FMT_HWACCEL))
64  count++;
65  }
66 
67  if (!(fmts = av_malloc((count+1) * sizeof(int))))
68  return NULL;
69  for (j = 0, i = 0; i < n; i++) {
70  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
71  if (!(desc->flags & PIX_FMT_HWACCEL))
72  fmts[j++] = i;
73  }
74  fmts[j] = -1;
75  return fmts;
76 }
77 
79 {
80  LavfiContext *lavfi = avctx->priv_data;
81 
82  av_freep(&lavfi->sink_stream_map);
83  av_freep(&lavfi->sink_eof);
84  av_freep(&lavfi->stream_sink_map);
85  av_freep(&lavfi->sinks);
86  avfilter_graph_free(&lavfi->graph);
88 
89  return 0;
90 }
91 
93 {
94  LavfiContext *lavfi = avctx->priv_data;
95  AVFilterInOut *input_links = NULL, *output_links = NULL, *inout;
96  AVFilter *buffersink, *abuffersink;
97  int *pix_fmts = create_all_formats(AV_PIX_FMT_NB);
98  enum AVMediaType type;
99  int ret = 0, i, n;
100 
101 #define FAIL(ERR) { ret = ERR; goto end; }
102 
103  if (!pix_fmts)
104  FAIL(AVERROR(ENOMEM));
105 
107 
108  buffersink = avfilter_get_by_name("buffersink");
109  abuffersink = avfilter_get_by_name("abuffersink");
110 
111  if (lavfi->graph_filename && lavfi->graph_str) {
112  av_log(avctx, AV_LOG_ERROR,
113  "Only one of the graph or graph_file options must be specified\n");
114  FAIL(AVERROR(EINVAL));
115  }
116 
117  if (lavfi->graph_filename) {
118  uint8_t *file_buf, *graph_buf;
119  size_t file_bufsize;
120  ret = av_file_map(lavfi->graph_filename,
121  &file_buf, &file_bufsize, 0, avctx);
122  if (ret < 0)
123  goto end;
124 
125  /* create a 0-terminated string based on the read file */
126  graph_buf = av_malloc(file_bufsize + 1);
127  if (!graph_buf) {
128  av_file_unmap(file_buf, file_bufsize);
129  FAIL(AVERROR(ENOMEM));
130  }
131  memcpy(graph_buf, file_buf, file_bufsize);
132  graph_buf[file_bufsize] = 0;
133  av_file_unmap(file_buf, file_bufsize);
134  lavfi->graph_str = graph_buf;
135  }
136 
137  if (!lavfi->graph_str)
138  lavfi->graph_str = av_strdup(avctx->filename);
139 
140  /* parse the graph, create a stream for each open output */
141  if (!(lavfi->graph = avfilter_graph_alloc()))
142  FAIL(AVERROR(ENOMEM));
143 
144  if ((ret = avfilter_graph_parse(lavfi->graph, lavfi->graph_str,
145  &input_links, &output_links, avctx)) < 0)
146  FAIL(ret);
147 
148  if (input_links) {
149  av_log(avctx, AV_LOG_ERROR,
150  "Open inputs in the filtergraph are not acceptable\n");
151  FAIL(AVERROR(EINVAL));
152  }
153 
154  /* count the outputs */
155  for (n = 0, inout = output_links; inout; n++, inout = inout->next);
156 
157  if (!(lavfi->sink_stream_map = av_malloc(sizeof(int) * n)))
158  FAIL(AVERROR(ENOMEM));
159  if (!(lavfi->sink_eof = av_mallocz(sizeof(int) * n)))
160  FAIL(AVERROR(ENOMEM));
161  if (!(lavfi->stream_sink_map = av_malloc(sizeof(int) * n)))
162  FAIL(AVERROR(ENOMEM));
163 
164  for (i = 0; i < n; i++)
165  lavfi->stream_sink_map[i] = -1;
166 
167  /* parse the output link names - they need to be of the form out0, out1, ...
168  * create a mapping between them and the streams */
169  for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
170  int stream_idx;
171  if (!strcmp(inout->name, "out"))
172  stream_idx = 0;
173  else if (sscanf(inout->name, "out%d\n", &stream_idx) != 1) {
174  av_log(avctx, AV_LOG_ERROR,
175  "Invalid outpad name '%s'\n", inout->name);
176  FAIL(AVERROR(EINVAL));
177  }
178 
179  if ((unsigned)stream_idx >= n) {
180  av_log(avctx, AV_LOG_ERROR,
181  "Invalid index was specified in output '%s', "
182  "must be a non-negative value < %d\n",
183  inout->name, n);
184  FAIL(AVERROR(EINVAL));
185  }
186 
187  /* is an audio or video output? */
188  type = inout->filter_ctx->output_pads[inout->pad_idx].type;
189  if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
190  av_log(avctx, AV_LOG_ERROR,
191  "Output '%s' is not a video or audio output, not yet supported\n", inout->name);
192  FAIL(AVERROR(EINVAL));
193  }
194 
195  if (lavfi->stream_sink_map[stream_idx] != -1) {
196  av_log(avctx, AV_LOG_ERROR,
197  "An output with stream index %d was already specified\n",
198  stream_idx);
199  FAIL(AVERROR(EINVAL));
200  }
201  lavfi->sink_stream_map[i] = stream_idx;
202  lavfi->stream_sink_map[stream_idx] = i;
203  }
204 
205  /* for each open output create a corresponding stream */
206  for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
207  AVStream *st;
208  if (!(st = avformat_new_stream(avctx, NULL)))
209  FAIL(AVERROR(ENOMEM));
210  st->id = i;
211  }
212 
213  /* create a sink for each output and connect them to the graph */
214  lavfi->sinks = av_malloc(sizeof(AVFilterContext *) * avctx->nb_streams);
215  if (!lavfi->sinks)
216  FAIL(AVERROR(ENOMEM));
217 
218  for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
219  AVFilterContext *sink;
220 
221  type = inout->filter_ctx->output_pads[inout->pad_idx].type;
222 
223  if (type == AVMEDIA_TYPE_VIDEO && ! buffersink ||
224  type == AVMEDIA_TYPE_AUDIO && ! abuffersink) {
225  av_log(avctx, AV_LOG_ERROR, "Missing required buffersink filter, aborting.\n");
227  }
228 
229  if (type == AVMEDIA_TYPE_VIDEO) {
230  ret = avfilter_graph_create_filter(&sink, buffersink,
231  inout->name, NULL,
232  NULL, lavfi->graph);
233  if (ret >= 0)
234  ret = av_opt_set_int_list(sink, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
235  if (ret < 0)
236  goto end;
237  } else if (type == AVMEDIA_TYPE_AUDIO) {
242  AV_SAMPLE_FMT_DBL, -1 };
243 
244  ret = avfilter_graph_create_filter(&sink, abuffersink,
245  inout->name, NULL,
246  NULL, lavfi->graph);
247  if (ret >= 0)
248  ret = av_opt_set_int_list(sink, "sample_fmts", sample_fmts, AV_SAMPLE_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
249  if (ret < 0)
250  goto end;
251  }
252 
253  lavfi->sinks[i] = sink;
254  if ((ret = avfilter_link(inout->filter_ctx, inout->pad_idx, sink, 0)) < 0)
255  FAIL(ret);
256  }
257 
258  /* configure the graph */
259  if ((ret = avfilter_graph_config(lavfi->graph, avctx)) < 0)
260  FAIL(ret);
261 
262  if (lavfi->dump_graph) {
263  char *dump = avfilter_graph_dump(lavfi->graph, lavfi->dump_graph);
264  fputs(dump, stderr);
265  fflush(stderr);
266  av_free(dump);
267  }
268 
269  /* fill each stream with the information in the corresponding sink */
270  for (i = 0; i < avctx->nb_streams; i++) {
271  AVFilterLink *link = lavfi->sinks[lavfi->stream_sink_map[i]]->inputs[0];
272  AVStream *st = avctx->streams[i];
273  st->codec->codec_type = link->type;
274  avpriv_set_pts_info(st, 64, link->time_base.num, link->time_base.den);
275  if (link->type == AVMEDIA_TYPE_VIDEO) {
277  st->codec->pix_fmt = link->format;
278  st->codec->time_base = link->time_base;
279  st->codec->width = link->w;
280  st->codec->height = link->h;
281  st ->sample_aspect_ratio =
283  avctx->probesize = FFMAX(avctx->probesize,
284  link->w * link->h *
286  30);
287  } else if (link->type == AVMEDIA_TYPE_AUDIO) {
288  st->codec->codec_id = av_get_pcm_codec(link->format, -1);
290  st->codec->sample_fmt = link->format;
291  st->codec->sample_rate = link->sample_rate;
292  st->codec->time_base = link->time_base;
293  st->codec->channel_layout = link->channel_layout;
294  if (st->codec->codec_id == AV_CODEC_ID_NONE)
295  av_log(avctx, AV_LOG_ERROR,
296  "Could not find PCM codec for sample format %s.\n",
298  }
299  }
300 
301  if (!(lavfi->decoded_frame = av_frame_alloc()))
302  FAIL(AVERROR(ENOMEM));
303 
304 end:
305  av_free(pix_fmts);
306  avfilter_inout_free(&input_links);
307  avfilter_inout_free(&output_links);
308  if (ret < 0)
309  lavfi_read_close(avctx);
310  return ret;
311 }
312 
314 {
315  LavfiContext *lavfi = avctx->priv_data;
316  double min_pts = DBL_MAX;
317  int stream_idx, min_pts_sink_idx = 0;
318  AVFrame *frame = lavfi->decoded_frame;
319  AVPicture pict;
320  AVDictionary *frame_metadata;
321  int ret, i;
322  int size = 0;
323 
324  /* iterate through all the graph sinks. Select the sink with the
325  * minimum PTS */
326  for (i = 0; i < avctx->nb_streams; i++) {
327  AVRational tb = lavfi->sinks[i]->inputs[0]->time_base;
328  double d;
329  int ret;
330 
331  if (lavfi->sink_eof[i])
332  continue;
333 
334  ret = av_buffersink_get_frame_flags(lavfi->sinks[i], frame,
336  if (ret == AVERROR_EOF) {
337  av_dlog(avctx, "EOF sink_idx:%d\n", i);
338  lavfi->sink_eof[i] = 1;
339  continue;
340  } else if (ret < 0)
341  return ret;
342  d = av_rescale_q(frame->pts, tb, AV_TIME_BASE_Q);
343  av_dlog(avctx, "sink_idx:%d time:%f\n", i, d);
344  av_frame_unref(frame);
345 
346  if (d < min_pts) {
347  min_pts = d;
348  min_pts_sink_idx = i;
349  }
350  }
351  if (min_pts == DBL_MAX)
352  return AVERROR_EOF;
353 
354  av_dlog(avctx, "min_pts_sink_idx:%i\n", min_pts_sink_idx);
355 
356  av_buffersink_get_frame_flags(lavfi->sinks[min_pts_sink_idx], frame, 0);
357  stream_idx = lavfi->sink_stream_map[min_pts_sink_idx];
358 
359  if (frame->width /* FIXME best way of testing a video */) {
360  size = avpicture_get_size(frame->format, frame->width, frame->height);
361  if ((ret = av_new_packet(pkt, size)) < 0)
362  return ret;
363 
364  memcpy(pict.data, frame->data, 4*sizeof(frame->data[0]));
365  memcpy(pict.linesize, frame->linesize, 4*sizeof(frame->linesize[0]));
366 
367  avpicture_layout(&pict, frame->format, frame->width, frame->height,
368  pkt->data, size);
369  } else if (av_frame_get_channels(frame) /* FIXME test audio */) {
370  size = frame->nb_samples * av_get_bytes_per_sample(frame->format) *
371  av_frame_get_channels(frame);
372  if ((ret = av_new_packet(pkt, size)) < 0)
373  return ret;
374  memcpy(pkt->data, frame->data[0], size);
375  }
376 
377  frame_metadata = av_frame_get_metadata(frame);
378  if (frame_metadata) {
379  uint8_t *metadata;
380  AVDictionaryEntry *e = NULL;
381  AVBPrint meta_buf;
382 
384  while ((e = av_dict_get(frame_metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {
385  av_bprintf(&meta_buf, "%s", e->key);
386  av_bprint_chars(&meta_buf, '\0', 1);
387  av_bprintf(&meta_buf, "%s", e->value);
388  av_bprint_chars(&meta_buf, '\0', 1);
389  }
390  if (!av_bprint_is_complete(&meta_buf) ||
392  meta_buf.len))) {
393  av_bprint_finalize(&meta_buf, NULL);
394  return AVERROR(ENOMEM);
395  }
396  memcpy(metadata, meta_buf.str, meta_buf.len);
397  av_bprint_finalize(&meta_buf, NULL);
398  }
399 
400  pkt->stream_index = stream_idx;
401  pkt->pts = frame->pts;
402  pkt->pos = av_frame_get_pkt_pos(frame);
403  pkt->size = size;
404  av_frame_unref(frame);
405  return size;
406 }
407 
408 #define OFFSET(x) offsetof(LavfiContext, x)
409 
410 #define DEC AV_OPT_FLAG_DECODING_PARAM
411 
412 static const AVOption options[] = {
413  { "graph", "set libavfilter graph", OFFSET(graph_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
414  { "graph_file","set libavfilter graph filename", OFFSET(graph_filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC},
415  { "dumpgraph", "dump graph to stderr", OFFSET(dump_graph), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
416  { NULL },
417 };
418 
419 static const AVClass lavfi_class = {
420  .class_name = "lavfi indev",
421  .item_name = av_default_item_name,
422  .option = options,
423  .version = LIBAVUTIL_VERSION_INT,
424 };
425 
427  .name = "lavfi",
428  .long_name = NULL_IF_CONFIG_SMALL("Libavfilter virtual input device"),
429  .priv_data_size = sizeof(LavfiContext),
433  .flags = AVFMT_NOFILE,
434  .priv_class = &lavfi_class,
435 };
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:93
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1778
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
AVOption.
Definition: opt.h:251
av_default_item_name
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:53
external API header
memory handling functions
int64_t pos
byte position in stream, -1 if unknown
static av_cold int lavfi_read_close(AVFormatContext *avctx)
Definition: lavfi.c:78
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
Definition: graphparser.c:175
#define av_opt_set_int_list(obj, name, val, term, flags)
Set a binary option to an integer list.
Definition: opt.h:671
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:709
int num
numerator
Definition: rational.h:44
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
Definition: avfiltergraph.c:75
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int avpicture_layout(const AVPicture *src, enum AVPixelFormat pix_fmt, int width, int height, unsigned char *dest, int dest_size)
Copy pixel data from an AVPicture into a buffer, always assume a linesize alignment of 1...
Definition: avpicture.c:41
enum AVMediaType type
AVFilterPad type.
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
signed 16 bits
Definition: samplefmt.h:52
four components are given, that&#39;s all.
int * sink_eof
Definition: lavfi.c:52
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:193
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
set threshold d
Format I/O context.
Definition: avformat.h:944
memory buffer sink API for audio and video
AVInputFormat ff_lavfi_demuxer
Definition: lavfi.c:426
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:55
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:532
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition: avfilter.c:114
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:538
enum AVSampleFormat sample_fmt
audio sample format
uint8_t
#define av_cold
Definition: attributes.h:78
AV_SAMPLE_FMT_U8
AVOptions.
uint8_t * data[AV_NUM_DATA_POINTERS]
static AVPacket pkt
Definition: demuxing.c:56
int id
Format-specific stream ID.
Definition: avformat.h:650
end end
#define OFFSET(x)
Definition: lavfi.c:408
static const AVClass lavfi_class
Definition: lavfi.c:419
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:159
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
Definition: avformat.h:992
void avfilter_register_all(void)
Initialize the filter system.
Definition: allfilters.c:40
Misc file utilities.
uint8_t * data
#define AVERROR_EOF
End of file.
Definition: error.h:55
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
AVFrame * decoded_frame
Definition: lavfi.c:54
int * sink_stream_map
Definition: lavfi.c:51
frame
Definition: stft.m:14
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:130
Main libavdevice API header.
#define AV_BUFFERSINK_FLAG_PEEK
Tell av_buffersink_get_buffer_ref() to read video/samples buffer reference, but not remove it from th...
Definition: buffersink.h:103
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:73
int width
width and height of the video frame
Definition: frame.h:122
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
char * dump_graph
Definition: lavfi.c:48
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
#define AV_BPRINT_SIZE_UNLIMITED
Convenience macros for special values for av_bprint_init() size_max parameter.
Definition: bprint.h:89
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Init a print buffer.
Definition: bprint.c:68
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:1744
static int av_bprint_is_complete(AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:166
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
#define FFMAX(a, b)
Definition: common.h:56
int size
uint64_t channel_layout
Audio channel layout.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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 link
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
signed 32 bits
Definition: samplefmt.h:53
static av_cold int lavfi_read_header(AVFormatContext *avctx)
Definition: lavfi.c:92
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
Buffer to print data progressively.
Definition: bprint.h:75
audio channel layout utility functions
int av_frame_get_channels(const AVFrame *frame)
char filename[1024]
input or output filename
Definition: avformat.h:994
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:538
ret
Definition: avfilter.c:821
int width
picture width / height.
unsigned int probesize
decoding: size of data to probe; encoding: unused.
Definition: avformat.h:1039
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:47
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Get a frame with filtered data from sink and put it in frame.
Definition: buffersink.c:126
AVFilterContext ** sinks
Definition: lavfi.c:50
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:517
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:104
Stream structure.
Definition: avformat.h:643
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1123
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:134
#define PIX_FMT_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:92
NULL
Definition: eval.c:55
enum AVMediaType codec_type
A list of zero terminated key/value strings.
enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
Return the PCM codec associated with a sample format.
enum AVCodecID codec_id
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:202
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:220
int sample_rate
samples per second
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
uint8_t flags
Definition: pixdesc.h:76
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
AVDictionary * av_frame_get_metadata(const AVFrame *frame)
int * stream_sink_map
Definition: lavfi.c:53
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:436
synthesis window for stochastic i
rational number numerator/denominator
Definition: rational.h:43
static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
Definition: lavfi.c:313
char * graph_filename
Definition: lavfi.c:47
AVMediaType
Definition: avutil.h:141
const char * name
filter name
Definition: avfilter.h:437
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:330
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
misc parsing utilities
#define type
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:95
#define FAIL(ERR)
static int flags
Definition: cpu.c:23
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
#define AVERROR_FILTER_NOT_FOUND
Filter not found.
Definition: error.h:58
AVFilterGraph * graph
Definition: lavfi.c:49
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:345
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:108
char * graph_str
Definition: lavfi.c:46
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
char * avfilter_graph_dump(AVFilterGraph *graph, const char *options)
Dump a graph into a human-readable string representation.
Definition: graphdump.c:153
char * key
Definition: dict.h:81
int den
denominator
Definition: rational.h:45
static const AVOption options[]
Definition: lavfi.c:412
char * value
Definition: dict.h:82
int channels
number of audio channels
void * priv_data
Format private data.
Definition: avformat.h:964
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
Calculate the size in bytes that a picture of the given width and height would occupy if stored in th...
Definition: avpicture.c:49
int64_t av_frame_get_pkt_pos(const AVFrame *frame)
An instance of a filter.
Definition: avfilter.h:524
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition: pixfmt.h:237
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:700
int height
Definition: frame.h:122
void INT64 INT64 count
Definition: avisynth_c.h:594
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:68
static int * create_all_formats(int n)
Definition: lavfi.c:57
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
Definition: avpacket.c:264
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: avfilter.c:391
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:127
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
for(j=16;j >0;--j)
#define tb
Definition: regdef.h:68
#define DEC
Definition: lavfi.c:410
int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs, void *log_ctx)
Add a graph described by a string to a graph.
Definition: graphparser.c:447
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:116