34 #define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name, separator)\
35 static char *choose_ ## var ## s(OutputStream *ost) \
37 if (ost->st->codec->var != none) { \
38 get_name(ost->st->codec->var); \
39 return av_strdup(name); \
40 } else if (ost->enc->supported_list) { \
42 AVIOContext *s = NULL; \
46 if (avio_open_dyn_buf(&s) < 0) \
49 for (p = ost->enc->supported_list; *p != none; p++) { \
51 avio_printf(s, "%s" separator, name); \
53 len = avio_close_dyn_buf(s, &ret); \
95 ist->filters[ist->nb_filters - 1] = fg->
inputs[0];
120 int file_idx = strtol(in->
name, &p, 0);
150 if (i == nb_input_streams) {
152 "unlabeled input pad %d on filter %s", in->
pad_idx,
183 snprintf(name,
sizeof(name),
"output stream %d:%d", ost->
file_index, ost->
index);
194 snprintf(args,
sizeof(args),
"%d:%d:flags=0x%X",
198 snprintf(name,
sizeof(name),
"scaler for output stream %d:%d",
203 if ((ret =
avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
210 if ((pix_fmts = choose_pix_fmts(ost))) {
212 snprintf(name,
sizeof(name),
"pixel format for output stream %d:%d",
216 "format", pix_fmts,
NULL,
219 if ((ret =
avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
231 snprintf(args,
sizeof(args),
"fps=%d/%d", ost->
frame_rate.
num,
233 snprintf(name,
sizeof(name),
"fps for output stream %d:%d",
259 char *
sample_fmts, *sample_rates, *channel_layouts;
264 snprintf(name,
sizeof(name),
"output stream %d:%d", ost->
file_index, ost->
index);
274 sample_fmts = choose_sample_fmts(ost);
275 sample_rates = choose_sample_rates(ost);
276 channel_layouts = choose_channel_layouts(ost);
277 if (sample_fmts || sample_rates || channel_layouts) {
283 len += snprintf(args + len,
sizeof(args) - len,
"sample_fmts=%s:",
286 len += snprintf(args + len,
sizeof(args) - len,
"sample_rates=%s:",
289 len += snprintf(args + len,
sizeof(args) - len,
"channel_layouts=%s:",
297 snprintf(name,
sizeof(name),
"audio format for output stream %d:%d",
309 last_filter = format;
319 #define DESCRIBE_FILTER_LINK(f, inout, in) \
321 AVFilterContext *ctx = inout->filter_ctx; \
322 AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; \
323 int nb_pads = in ? ctx->input_count : ctx->output_count; \
326 if (avio_open_dyn_buf(&pb) < 0) \
329 avio_printf(pb, "%s", ctx->filter->name); \
331 avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));\
333 avio_close_dyn_buf(pb, &f->name); \
357 char args[255],
name[255];
364 snprintf(args,
sizeof(args),
"%d:%d:%d:%d:%d:%d:%d", ist->
st->
codec->
width,
367 snprintf(name,
sizeof(name),
"graph %d input from stream %d:%d", fg->
index,
377 snprintf(name,
sizeof(name),
"force CFR for input from stream %d:%d",
385 if ((ret =
avfilter_link(setpts, 0, first_filter, pad_idx)) < 0)
388 first_filter = setpts;
404 char args[255],
name[255];
407 snprintf(args,
sizeof(args),
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s"
408 ":channel_layout=0x%"PRIx64,
413 snprintf(name,
sizeof(name),
"graph %d input from stream %d:%d", fg->
index,
426 "asyncts audio filter instead.\n");
429 len += snprintf(args + len,
sizeof(args) - len,
"compensate=1:"
431 snprintf(args + len,
sizeof(args) - len,
"min_delta=%f",
434 snprintf(name,
sizeof(name),
"graph %d audio sync for input stream %d:%d",
446 first_filter = async;
453 "audio filter instead.\n");
455 snprintf(args,
sizeof(args),
"volume=%f",
audio_volume / 256.0);
457 snprintf(name,
sizeof(name),
"graph %d volume for input stream %d:%d",
469 first_filter = volume;
505 snprintf(args,
sizeof(args),
"flags=0x%X", (
unsigned)ost->
sws_flags);
512 if (simple && (!inputs || inputs->
next || !outputs || outputs->
next)) {
514 "exactly one input and output.\n", graph_desc);
518 for (cur = inputs; !simple && init && cur; cur = cur->
next)
521 for (cur = inputs, i = 0; cur; cur = cur->
next, i++)
526 if (!init || simple) {
529 for (cur = outputs, i = 0; cur; cur = cur->
next, i++)
537 for (cur = outputs; cur;) {
uint64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
static const AVFilterPad outputs[]
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int index
stream index in AVFormatContext
static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
FilterGraph * init_simple_filtergraph(InputStream *ist, OutputStream *ost)
FilterGraph ** filtergraphs
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int configure_filtergraph(FilterGraph *fg)
char * name
name of this filter instance
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
AVFilterPad * output_pads
array of output pads
enum AVSampleFormat sample_fmt
audio sample format
float audio_drift_threshold
#define DESCRIBE_FILTER_LINK(f, inout, in)
static int init(AVCodecParserContext *s)
AVFilterPad * input_pads
array of input pads
static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
#define GET_CH_LAYOUT_NAME(ch_layout)
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
uint64_t channel_layout
Audio channel layout.
AVCodecContext * codec
Codec context associated with this stream.
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
unsigned int nb_streams
A list of all streams in the file.
audio channel layout utility functions
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
struct OutputStream * ost
int width
picture width / height.
#define GET_PIX_FMT_NAME(pix_fmt)
int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs)
Add a graph described by a string to a graph.
enum AVPixelFormat pix_fmt
static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
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.
AVFilterContext * filter_ctx
filter context associated to this input/output
A linked-list of the inputs/outputs of the filter chain.
#define GET_SAMPLE_RATE_NAME(rate)
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
enum AVMediaType codec_type
char * av_strdup(const char *s)
Duplicate the string s.
int sample_rate
samples per second
main external API structure.
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.
static const AVFilterPad inputs[]
int pad_idx
index of the filt_ctx pad to use for linking
rational number numerator/denominator
static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
char * name
unique name for this input/output in the list
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
struct FilterGraph * graph
InputStream ** input_streams
AVSampleFormat
Audio Sample Formats.
static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
#define GROW_ARRAY(array, nb_elems)
int channels
number of audio channels
#define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name, separator)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
AVPixelFormat
Pixel format.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)