23 #include "libavfilter/avfilter.h"
24 #include "libavfilter/avfiltergraph.h"
25 #include "libavfilter/buffersink.h"
29 #include "libavutil/avassert.h"
30 #include "libavutil/avstring.h"
31 #include "libavutil/bprint.h"
32 #include "libavutil/channel_layout.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/pixfmt.h"
36 #include "libavutil/imgutils.h"
37 #include "libavutil/samplefmt.h"
65 "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
79 for (; *p != -1; p++) {
88 "Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n",
141 #define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name, separator)\
142 static char *choose_ ## var ## s(OutputStream *ost) \
144 if (ost->st->codec->var != none) { \
145 get_name(ost->st->codec->var); \
146 return av_strdup(name); \
147 } else if (ost->enc && ost->enc->supported_list) { \
149 AVIOContext *s = NULL; \
153 if (avio_open_dyn_buf(&s) < 0) \
156 for (p = ost->enc->supported_list; *p != none; p++) { \
158 avio_printf(s, "%s" separator, name); \
160 len = avio_close_dyn_buf(s, &ret); \
202 ist->filters[ist->nb_filters - 1] = fg->
inputs[0];
227 int file_idx = strtol(in->
name, &p, 0);
238 if (stream_type != type &&
260 if (i == nb_input_streams) {
262 "unlabeled input pad %d on filter %s\n", in->
pad_idx,
307 snprintf(args,
sizeof(args),
"%d:%d:flags=0x%X",
311 snprintf(name,
sizeof(name),
"scaler for output stream %d:%d",
316 if ((ret =
avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
325 snprintf(name,
sizeof(name),
"pixel format for output stream %d:%d",
329 "format", pix_fmts,
NULL,
332 if ((ret =
avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
346 snprintf(name,
sizeof(name),
"fps for output stream %d:%d",
372 char *
sample_fmts, *sample_rates, *channel_layouts;
388 #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
389 AVFilterContext *filt_ctx; \
391 av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
392 "similarly to -af " filter_name "=%s.\n", arg); \
394 ret = avfilter_graph_create_filter(&filt_ctx, \
395 avfilter_get_by_name(filter_name), \
396 filter_name, arg, NULL, fg->graph); \
400 ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
404 last_filter = filt_ctx; \
424 sample_fmts = choose_sample_fmts(ost);
425 sample_rates = choose_sample_rates(ost);
426 channel_layouts = choose_channel_layouts(ost);
427 if (sample_fmts || sample_rates || channel_layouts) {
436 av_strlcatf(args,
sizeof(args),
"sample_rates=%s:",
439 av_strlcatf(args,
sizeof(args),
"channel_layouts=%s:",
446 snprintf(name,
sizeof(name),
"audio format for output stream %d:%d",
458 last_filter = format;
475 #define DESCRIBE_FILTER_LINK(f, inout, in) \
477 AVFilterContext *ctx = inout->filter_ctx; \
478 AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; \
479 int nb_pads = in ? ctx->input_count : ctx->output_count; \
482 if (avio_open_dyn_buf(&pb) < 0) \
485 avio_printf(pb, "%s", ctx->filter->name); \
487 avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));\
489 avio_close_dyn_buf(pb, &f->name); \
539 memset(image[0], 0, h * linesize[0]);
559 ist->
st->r_frame_rate;
588 "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
595 snprintf(name,
sizeof(name),
"graph %d input from stream %d:%d", fg->
index,
605 snprintf(name,
sizeof(name),
"force CFR for input from stream %d:%d",
613 if ((ret =
avfilter_link(setpts, 0, first_filter, pad_idx)) < 0)
616 first_filter = setpts;
637 av_bprintf(&args,
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
642 av_bprintf(&args,
":channel_layout=0x%"PRIx64,
646 snprintf(name,
sizeof(name),
"graph %d input from stream %d:%d", fg->
index,
650 name, args.str,
NULL,
654 #define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg) do { \
655 AVFilterContext *filt_ctx; \
657 av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
658 "similarly to -af " filter_name "=%s.\n", arg); \
660 snprintf(name, sizeof(name), "graph %d %s for input stream %d:%d", \
661 fg->index, filter_name, ist->file_index, ist->st->index); \
662 ret = avfilter_graph_create_filter(&filt_ctx, \
663 avfilter_get_by_name(filter_name), \
664 name, arg, NULL, fg->graph); \
668 ret = avfilter_link(filt_ctx, 0, first_filter, pad_idx); \
672 first_filter = filt_ctx; \
676 char args[256] = {0};
703 "audio filter instead.\n");
752 args[strlen(args)-1] = 0;
761 args[strlen(args) - 1] =
'\0';
768 if (simple && (!inputs || inputs->
next || !outputs || outputs->
next)) {
770 "exactly one input and output.\n", graph_desc);
774 for (cur = inputs; !simple && init && cur; cur = cur->
next)
777 for (cur = inputs, i = 0; cur; cur = cur->
next, i++)
782 if (!init || simple) {
785 for (cur = outputs, i = 0; cur; cur = cur->
next, i++)
793 for (cur = outputs; cur;) {