30 #include "libavutil/bprint.h"
31 #include "libavutil/channel_layout.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"
39 #include "libavfilter/avfiltergraph.h"
40 #include "libavfilter/buffersink.h"
59 int i, j, *fmts,
count = 0;
61 for (i = 0; i <
n; i++) {
67 if (!(fmts =
av_malloc((count+1) *
sizeof(
int))))
69 for (j = 0, i = 0; i <
n; i++) {
95 AVFilterInOut *input_links = NULL, *output_links = NULL, *inout;
101 #define FAIL(ERR) { ret = ERR; goto end; }
113 "Only one of the graph or graph_file options must be specified\n");
121 &file_buf, &file_bufsize, 0, avctx);
131 memcpy(graph_buf, file_buf, file_bufsize);
132 graph_buf[file_bufsize] = 0;
145 &input_links, &output_links, avctx)) < 0)
150 "Open inputs in the filtergraph are not acceptable\n");
155 for (n = 0, inout = output_links; inout; n++, inout = inout->next);
164 for (i = 0; i <
n; i++)
169 for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
171 if (!strcmp(inout->name,
"out"))
173 else if (sscanf(inout->name,
"out%d\n", &stream_idx) != 1) {
175 "Invalid outpad name '%s'\n", inout->name);
179 if ((
unsigned)stream_idx >= n) {
181 "Invalid index was specified in output '%s', "
182 "must be a non-negative value < %d\n",
188 type = inout->filter_ctx->output_pads[inout->pad_idx].type;
191 "Output '%s' is not a video or audio output, not yet supported\n", inout->name);
197 "An output with stream index %d was already specified\n",
206 for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
218 for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
253 lavfi->
sinks[i] = sink;
254 if ((ret =
avfilter_link(inout->filter_ctx, inout->pad_idx, sink, 0)) < 0)
296 "Could not find PCM codec for sample format %s.\n",
316 double min_pts = DBL_MAX;
317 int stream_idx, min_pts_sink_idx = 0;
337 av_dlog(avctx,
"EOF sink_idx:%d\n", i);
343 av_dlog(avctx,
"sink_idx:%d time:%f\n", i, d);
348 min_pts_sink_idx = i;
351 if (min_pts == DBL_MAX)
354 av_dlog(avctx,
"min_pts_sink_idx:%i\n", min_pts_sink_idx);
364 memcpy(pict.
data, frame->
data, 4*
sizeof(frame->
data[0]));
374 memcpy(pkt->
data, frame->
data[0], size);
378 if (frame_metadata) {
396 memcpy(metadata, meta_buf.str, meta_buf.len);
408 #define OFFSET(x) offsetof(LavfiContext, x)
410 #define DEC AV_OPT_FLAG_DECODING_PARAM
434 .priv_class = &lavfi_class,
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
This structure describes decoded (raw) audio or video data.
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.
const char * name
Filter name.
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
#define AVERROR_FILTER_NOT_FOUND
#define LIBAVUTIL_VERSION_INT
int64_t pos
byte position in stream, -1 if unknown
static av_cold int lavfi_read_close(AVFormatContext *avctx)
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
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.
int h
agreed upon image height
#define av_opt_set_int_list(obj, name, val, term, flags)
Set a binary option to an integer list.
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
AVCodecContext * codec
Codec context associated with this stream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
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.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
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.
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)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
AVInputFormat ff_lavfi_demuxer
#define AV_BUFFERSINK_FLAG_PEEK
Tell av_buffersink_get_buffer_ref() to read video/samples buffer reference, but not remove it from th...
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
const char * av_default_item_name(void *ctx)
Return the context name.
enum AVSampleFormat sample_fmt
audio sample format
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static av_cold int end(AVCodecContext *avctx)
int id
Format-specific stream ID.
static const AVClass lavfi_class
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
void avfilter_register_all(void)
Initialize the filter system.
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
static av_cold int read_close(AVFormatContext *ctx)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointers to the image data planes
const OptionDef options[]
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
int sample_rate
samples per second
void * priv_data
Format private data.
char filename[1024]
input or output filename
#define AV_BPRINT_SIZE_UNLIMITED
Convenience macros for special values for av_bprint_init() size_max parameter.
int avfilter_link_get_channels(AVFilterLink *link)
Get the number of channels of a link.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
int av_frame_get_channels(const AVFrame *frame)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
uint64_t channel_layout
Audio channel layout.
int w
agreed upon image width
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Init a print buffer.
static av_cold int lavfi_read_header(AVFormatContext *avctx)
unsigned int nb_streams
A list of all streams in the file.
int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Get a frame with filtered data from sink and put it in frame.
Buffer to print data progressively.
static int av_bprint_is_complete(AVBPrint *buf)
Test if the print buffer is complete (not truncated).
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
int width
picture width / height.
AVDictionary * av_frame_get_metadata(const AVFrame *frame)
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
unsigned int probesize
decoding: size of data to probe; encoding: unused.
int format
agreed upon media format
static int read_header(FFV1Context *f)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
A linked-list of the inputs/outputs of the filter chain.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
AVSampleFormat
Audio Sample Formats.
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
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.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int sample_rate
samples per second
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Main libavdevice API header.
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Describe the class of an AVClass context structure.
AVFilterLink ** inputs
array of pointers to input links
rational number numerator/denominator
static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
enum AVMediaType type
filter media type
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
void av_bprintf(AVBPrint *buf, const char *fmt,...) av_printf_format(2
Append a formatted string to a print buffer.
int channels
number of audio channels
char * avfilter_graph_dump(AVFilterGraph *graph, const char *options)
Dump a graph into a human-readable string representation.
AVFilterPad * output_pads
array of output pads
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...
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 ...
int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs, void *log_ctx)
Add a graph described by a string to a graph.
static enum AVSampleFormat sample_fmts[]
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_DICT_IGNORE_SUFFIX
static int * create_all_formats(int n)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int64_t av_frame_get_pkt_pos(const AVFrame *frame)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...