49#include "libavfilter/avfilter.h"
50#include "libavfilter/buffersink.h"
51#include "libavfilter/buffersrc.h"
53#include "libavutil/avassert.h"
54#include "libavutil/avstring.h"
55#include "libavutil/bprint.h"
56#include "libavutil/channel_layout.h"
57#include "libavutil/display.h"
58#include "libavutil/opt.h"
59#include "libavutil/pixdesc.h"
60#include "libavutil/pixfmt.h"
61#include "libavutil/imgutils.h"
62#include "libavutil/samplefmt.h"
68 static const enum AVPixelFormat mjpeg_formats[] =
69 { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
72 if (!strcmp(codec->name,
"mjpeg")) {
75 return default_formats;
81 int strict_std_compliance)
83 if (codec && codec->pix_fmts) {
84 const enum AVPixelFormat *p = codec->pix_fmts;
85 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
87 int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
88 enum AVPixelFormat best= AV_PIX_FMT_NONE;
90 if (strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
93 for (; *p != AV_PIX_FMT_NONE; p++) {
94 best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
98 if (*p == AV_PIX_FMT_NONE) {
99 if (target != AV_PIX_FMT_NONE)
100 av_log(NULL, AV_LOG_WARNING,
101 "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
102 av_get_pix_fmt_name(target),
104 av_get_pix_fmt_name(best));
117 AVCodecContext *enc = ost->
enc_ctx;
118 const AVDictionaryEntry *strict_dict = av_dict_get(ost->
encoder_opts,
"strict", NULL, 0);
121 av_opt_set(ost->
enc_ctx,
"strict", strict_dict->value, 0);
124 avfilter_graph_set_auto_convert(ofilter->
graph->
graph,
125 AVFILTER_AUTO_CONVERT_NONE);
126 if (ost->
enc_ctx->pix_fmt == AV_PIX_FMT_NONE)
128 return av_get_pix_fmt_name(ost->
enc_ctx->pix_fmt);
130 if (ost->
enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
132 ost->
enc_ctx->strict_std_compliance));
133 }
else if (enc->codec->pix_fmts) {
134 const enum AVPixelFormat *p;
136 p = enc->codec->pix_fmts;
137 if (ost->
enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
141 for (; *p != AV_PIX_FMT_NONE; p++) {
142 const char *name = av_get_pix_fmt_name(*p);
143 av_bprintf(bprint,
"%s%c", name, p[1] == AV_PIX_FMT_NONE ?
'\0' :
'|');
145 if (!av_bprint_is_complete(bprint))
154#define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name) \
155static void choose_ ## name (OutputFilter *ofilter, AVBPrint *bprint) \
157 if (ofilter->var == none && !ofilter->supported_list) \
159 av_bprintf(bprint, #name "="); \
160 if (ofilter->var != none) { \
161 av_bprintf(bprint, printf_format, get_name(ofilter->var)); \
165 for (p = ofilter->supported_list; *p != none; p++) { \
166 av_bprintf(bprint, printf_format "|", get_name(*p)); \
168 if (bprint->len > 0) \
169 bprint->str[--bprint->len] = '\0'; \
171 av_bprint_chars(bprint, ':', 1); \
178 AV_SAMPLE_FMT_NONE,
"%s", av_get_sample_fmt_name)
185 if (av_channel_layout_check(&ofilter->ch_layout)) {
186 av_bprintf(bprint,
"channel_layouts=");
187 av_channel_layout_describe_bprint(&ofilter->ch_layout, bprint);
188 }
else if (ofilter->ch_layouts) {
189 const AVChannelLayout *p;
191 av_bprintf(bprint,
"channel_layouts=");
192 for (p = ofilter->ch_layouts; p->nb_channels; p++) {
193 av_channel_layout_describe_bprint(p, bprint);
194 av_bprintf(bprint,
"|");
197 bprint->str[--bprint->len] =
'\0';
200 av_bprint_chars(bprint,
':', 1);
225 ifilter->
frame_queue = av_fifo_alloc2(8,
sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
240 AVFilterContext *ctx = inout->filter_ctx;
241 AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads;
242 int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs;
246 res = av_strdup(ctx->filter->name);
248 res = av_asprintf(
"%s:%s", ctx->filter->name,
249 avfilter_pad_get_name(pads, inout->pad_idx));
258 enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx);
263 if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
264 av_log(NULL, AV_LOG_FATAL,
"Only video and audio filters supported "
273 int file_idx = strtol(in->name, &p, 0);
276 av_log(NULL, AV_LOG_FATAL,
"Invalid file index %d in filtergraph description %s.\n",
282 for (i = 0; i < s->nb_streams; i++) {
283 enum AVMediaType stream_type = s->streams[i]->codecpar->codec_type;
284 if (stream_type != type &&
285 !(stream_type == AVMEDIA_TYPE_SUBTITLE &&
286 type == AVMEDIA_TYPE_VIDEO ))
294 av_log(NULL, AV_LOG_FATAL,
"Stream specifier '%s' in filtergraph description %s "
300 av_log(NULL, AV_LOG_FATAL,
"Stream specifier '%s' in filtergraph description %s "
301 "matches a disabled input stream.\n", p, fg->
graph_desc);
313 av_log(NULL, AV_LOG_FATAL,
"Cannot find a matching stream for "
314 "unlabeled input pad %d on filter %s\n", in->pad_idx,
315 in->filter_ctx->name);
324 ist->
st->discard = AVDISCARD_NONE;
330 ifilter->
type = ist->
st->codecpar->codec_type;
333 ifilter->
frame_queue = av_fifo_alloc2(8,
sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
343 AVIOContext *io = NULL;
350 ret = avio_open2(&io, path, AVIO_FLAG_READ, &
int_cb, NULL);
352 av_log(NULL, AV_LOG_ERROR,
"Cannot open file '%s': %s\n",
353 path, av_err2str(ret));
357 fsize = avio_size(io);
358 if (fsize < 0 || fsize > INT_MAX) {
359 av_log(NULL, AV_LOG_ERROR,
"Cannot obtain size of file %s\n", path);
364 *data = av_malloc(fsize);
366 ret = AVERROR(ENOMEM);
370 ret = avio_read(io, *data, fsize);
372 av_log(NULL, AV_LOG_ERROR,
"Error reading file %s\n", path);
373 ret = ret < 0 ? ret : AVERROR(EIO);
389 const AVOption *o = NULL;
392 ret = av_opt_set(f, key, val, AV_OPT_SEARCH_CHILDREN);
396 if (ret == AVERROR_OPTION_NOT_FOUND && key[0] ==
'/')
397 o = av_opt_find(f, key + 1, NULL, 0, AV_OPT_SEARCH_CHILDREN);
405 if (o->type == AV_OPT_TYPE_BINARY) {
413 ret = av_opt_set_bin(f, key, data, len, AV_OPT_SEARCH_CHILDREN);
422 ret = av_opt_set(f, key, data, AV_OPT_SEARCH_CHILDREN);
431 av_log(NULL, AV_LOG_ERROR,
432 "Error applying option '%s' to filter '%s': %s\n",
433 key, f->filter->name, av_err2str(ret));
436 av_log(NULL, AV_LOG_ERROR,
437 "Error loading value for option '%s' from file '%s'\n",
444 for (
size_t i = 0; i < seg->nb_chains; i++) {
445 AVFilterChain *ch = seg->chains[i];
447 for (
size_t j = 0; j < ch->nb_filters; j++) {
448 AVFilterParams *p = ch->filters[j];
449 const AVDictionaryEntry *e = NULL;
451 av_assert0(p->filter);
453 while ((e = av_dict_iterate(p->opts, e))) {
459 av_dict_free(&p->opts);
467 AVFilterInOut **inputs, AVFilterInOut **outputs)
469 AVFilterGraphSegment *seg;
472 ret = avfilter_graph_segment_parse(graph, desc, 0, &seg);
476 ret = avfilter_graph_segment_create_filters(seg, 0);
484 ret = avfilter_graph_segment_apply(seg, 0, inputs, outputs);
487 avfilter_graph_segment_free(&seg);
493 AVFilterInOut *inputs, *outputs, *cur;
494 AVFilterGraph *graph;
499 graph = avfilter_graph_alloc();
501 return AVERROR(ENOMEM);
502 graph->nb_threads = 1;
508 for (cur = inputs; cur; cur = cur->next)
511 for (cur = outputs; cur;) {
516 ofilter->
type = avfilter_pad_get_type(cur->filter_ctx->output_pads,
524 avfilter_inout_free(&inputs);
525 avfilter_graph_free(&graph);
530 AVFilterContext **last_filter,
int *pad_idx,
531 const char *filter_name)
533 AVFilterGraph *graph = (*last_filter)->graph;
534 AVFilterContext *ctx;
535 const AVFilter *trim;
536 enum AVMediaType type = avfilter_pad_get_type((*last_filter)->output_pads, *pad_idx);
537 const char *name = (type == AVMEDIA_TYPE_VIDEO) ?
"trim" :
"atrim";
540 if (duration == INT64_MAX && start_time == AV_NOPTS_VALUE)
543 trim = avfilter_get_by_name(name);
545 av_log(NULL, AV_LOG_ERROR,
"%s filter not present, cannot limit "
546 "recording time.\n", name);
547 return AVERROR_FILTER_NOT_FOUND;
550 ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
552 return AVERROR(ENOMEM);
554 if (duration != INT64_MAX) {
555 ret = av_opt_set_int(ctx,
"durationi", duration,
556 AV_OPT_SEARCH_CHILDREN);
558 if (ret >= 0 && start_time != AV_NOPTS_VALUE) {
559 ret = av_opt_set_int(ctx,
"starti", start_time,
560 AV_OPT_SEARCH_CHILDREN);
563 av_log(ctx, AV_LOG_ERROR,
"Error configuring the %s filter", name);
567 ret = avfilter_init_str(ctx, NULL);
571 ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
581 const char *filter_name,
const char *args)
583 AVFilterGraph *graph = (*last_filter)->graph;
584 AVFilterContext *ctx;
587 ret = avfilter_graph_create_filter(&ctx,
588 avfilter_get_by_name(filter_name),
589 filter_name, args, NULL, graph);
593 ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
606 AVFilterContext *last_filter = out->filter_ctx;
608 int pad_idx = out->pad_idx;
610 const char *pix_fmts;
613 snprintf(name,
sizeof(name),
"out_%d_%d", ost->
file_index, ost->
index);
614 ret = avfilter_graph_create_filter(&ofilter->
filter,
615 avfilter_get_by_name(
"buffersink"),
616 name, NULL, NULL, fg->
graph);
623 AVFilterContext *filter;
624 const AVDictionaryEntry *e = NULL;
626 snprintf(args,
sizeof(args),
"%d:%d",
629 while ((e = av_dict_iterate(ost->
sws_dict, e))) {
630 av_strlcatf(args,
sizeof(args),
":%s=%s", e->key, e->value);
633 snprintf(name,
sizeof(name),
"scaler_out_%d_%d",
635 if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name(
"scale"),
636 name, args, NULL, fg->
graph)) < 0)
638 if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
641 last_filter = filter;
645 av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
647 AVFilterContext *filter;
649 ret = avfilter_graph_create_filter(&filter,
650 avfilter_get_by_name(
"format"),
651 "format", pix_fmts, NULL, fg->
graph);
652 av_bprint_finalize(&bprint, NULL);
655 if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
658 last_filter = filter;
663 AVFilterContext *fps;
666 snprintf(args,
sizeof(args),
"fps=%d/%d", ost->
frame_rate.num,
668 snprintf(name,
sizeof(name),
"fps_out_%d_%d",
670 ret = avfilter_graph_create_filter(&fps, avfilter_get_by_name(
"fps"),
671 name, args, NULL, fg->
graph);
675 ret = avfilter_link(last_filter, pad_idx, fps, 0);
682 snprintf(name,
sizeof(name),
"trim_out_%d_%d",
685 &last_filter, &pad_idx, name);
690 if ((ret = avfilter_link(last_filter, pad_idx, ofilter->
filter, 0)) < 0)
700 AVCodecContext *codec = ost->
enc_ctx;
701 AVFilterContext *last_filter = out->filter_ctx;
702 int pad_idx = out->pad_idx;
707 snprintf(name,
sizeof(name),
"out_%d_%d", ost->
file_index, ost->
index);
708 ret = avfilter_graph_create_filter(&ofilter->
filter,
709 avfilter_get_by_name(
"abuffersink"),
710 name, NULL, NULL, fg->
graph);
713 if ((ret = av_opt_set_int(ofilter->
filter,
"all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0)
716#define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
717 AVFilterContext *filt_ctx; \
719 av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
720 "similarly to -af " filter_name "=%s.\n", arg); \
722 ret = avfilter_graph_create_filter(&filt_ctx, \
723 avfilter_get_by_name(filter_name), \
724 filter_name, arg, NULL, fg->graph); \
728 ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
732 last_filter = filt_ctx; \
735 av_bprint_init(&args, 0, AV_BPRINT_SIZE_UNLIMITED);
736#if FFMPEG_OPT_MAP_CHANNEL
738 AVChannelLayout mapped_layout = { 0 };
741 av_channel_layout_describe_bprint(&mapped_layout, &args);
747 av_bprint_clear(&args);
751 if (codec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
752 av_channel_layout_default(&codec->ch_layout, codec->ch_layout.nb_channels);
754 choose_sample_fmts(ofilter, &args);
755 choose_sample_rates(ofilter, &args);
757 if (!av_bprint_is_complete(&args)) {
758 ret = AVERROR(ENOMEM);
762 AVFilterContext *format;
764 snprintf(name,
sizeof(name),
"format_out_%d_%d",
766 ret = avfilter_graph_create_filter(&format,
767 avfilter_get_by_name(
"aformat"),
768 name, args.str, NULL, fg->
graph);
772 ret = avfilter_link(last_filter, pad_idx, format, 0);
776 last_filter = format;
784 if (of->
streams[i]->
st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
792 snprintf(name,
sizeof(name),
"trim for output stream %d:%d",
795 &last_filter, &pad_idx, name);
799 if ((ret = avfilter_link(last_filter, pad_idx, ofilter->
filter, 0)) < 0)
802 av_bprint_finalize(&args, NULL);
811 av_log(NULL, AV_LOG_FATAL,
"Filter %s has an unconnected output\n", ofilter->
name);
815 switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
818 default: av_assert0(0);
return 0;
830 av_log(NULL, AV_LOG_FATAL,
"Filter %s has an unconnected output\n", output->
name);
848 for (i = 0; i < avf->nb_streams; i++) {
849 if (avf->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
850 w = FFMAX(w, avf->streams[i]->codecpar->width);
851 h = FFMAX(h, avf->streams[i]->codecpar->height);
858 av_log(avf, AV_LOG_INFO,
"sub2video: using %dx%d canvas\n", w, h);
868 ifilter->
format = AV_PIX_FMT_RGB32;
872 return AVERROR(ENOMEM);
887 AVFilterContext *last_filter;
888 const AVFilter *buffer_filt = avfilter_get_by_name(
"buffer");
889 const AVPixFmtDescriptor *desc;
898 int ret, pad_idx = 0;
899 int64_t tsoffset = 0;
900 AVBufferSrcParameters *par = av_buffersrc_parameters_alloc();
903 return AVERROR(ENOMEM);
904 memset(par, 0,
sizeof(*par));
905 par->format = AV_PIX_FMT_NONE;
907 if (ist->
dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
908 av_log(NULL, AV_LOG_ERROR,
"Cannot connect video filter to audio input\n");
909 ret = AVERROR(EINVAL);
916 if (ist->
dec_ctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
924 sar = (AVRational){0,1};
925 av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC);
927 "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
928 "pixel_aspect=%d/%d",
930 tb.num, tb.den, sar.num, sar.den);
931 if (fr.num && fr.den)
932 av_bprintf(&args,
":frame_rate=%d/%d", fr.num, fr.den);
933 snprintf(name,
sizeof(name),
"graph %d input from stream %d:%d", fg->
index,
937 if ((ret = avfilter_graph_create_filter(&ifilter->
filter, buffer_filt, name,
938 args.str, NULL, fg->
graph)) < 0)
941 ret = av_buffersrc_parameters_set(ifilter->
filter, par);
945 last_filter = ifilter->
filter;
947 desc = av_pix_fmt_desc_get(ifilter->
format);
951 if (ist->
autorotate && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
956 displaymatrix = (int32_t *)av_stream_get_side_data(ist->
st, AV_PKT_DATA_DISPLAYMATRIX, NULL);
959 if (fabs(theta - 90) < 1.0) {
961 displaymatrix[3] > 0 ?
"cclock_flip" :
"clock");
962 }
else if (fabs(theta - 180) < 1.0) {
963 if (displaymatrix[0] < 0) {
968 if (displaymatrix[4] < 0) {
971 }
else if (fabs(theta - 270) < 1.0) {
973 displaymatrix[3] < 0 ?
"clock_flip" :
"cclock");
974 }
else if (fabs(theta) > 1.0) {
976 snprintf(rotate_buf,
sizeof(rotate_buf),
"%f*PI/180", theta);
977 ret =
insert_filter(&last_filter, &pad_idx,
"rotate", rotate_buf);
978 }
else if (fabs(theta) < 1.0) {
979 if (displaymatrix && displaymatrix[4] < 0) {
987 snprintf(name,
sizeof(name),
"trim_in_%d_%d",
992 tsoffset += f->
ctx->start_time;
996 &last_filter, &pad_idx, name);
1000 if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
1012 AVFilterContext *last_filter;
1013 const AVFilter *abuffer_filt = avfilter_get_by_name(
"abuffer");
1018 int ret, pad_idx = 0;
1019 int64_t tsoffset = 0;
1021 if (ist->
dec_ctx->codec_type != AVMEDIA_TYPE_AUDIO) {
1022 av_log(NULL, AV_LOG_ERROR,
"Cannot connect audio filter to non audio input\n");
1023 return AVERROR(EINVAL);
1026 av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC);
1027 av_bprintf(&args,
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
1030 av_get_sample_fmt_name(ifilter->
format));
1031 if (av_channel_layout_check(&ifilter->
ch_layout) &&
1032 ifilter->
ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
1033 av_bprintf(&args,
":channel_layout=");
1034 av_channel_layout_describe_bprint(&ifilter->
ch_layout, &args);
1036 av_bprintf(&args,
":channels=%d", ifilter->
ch_layout.nb_channels);
1037 snprintf(name,
sizeof(name),
"graph_%d_in_%d_%d", fg->
index,
1040 if ((ret = avfilter_graph_create_filter(&ifilter->
filter, abuffer_filt,
1041 name, args.str, NULL,
1044 last_filter = ifilter->
filter;
1046#define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg) do { \
1047 AVFilterContext *filt_ctx; \
1049 av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
1050 "similarly to -af " filter_name "=%s.\n", arg); \
1052 snprintf(name, sizeof(name), "graph_%d_%s_in_%d_%d", \
1053 fg->index, filter_name, ist->file_index, ist->st->index); \
1054 ret = avfilter_graph_create_filter(&filt_ctx, \
1055 avfilter_get_by_name(filter_name), \
1056 name, arg, NULL, fg->graph); \
1060 ret = avfilter_link(last_filter, 0, filt_ctx, 0); \
1064 last_filter = filt_ctx; \
1067 snprintf(name,
sizeof(name),
"trim for input stream %d:%d",
1072 tsoffset += f->
ctx->start_time;
1076 &last_filter, &pad_idx, name);
1080 if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
1089 if (!ifilter->
ist->
dec) {
1090 av_log(NULL, AV_LOG_ERROR,
1091 "No decoder for stream #%d:%d, filtering impossible\n",
1093 return AVERROR_DECODER_NOT_FOUND;
1095 switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) {
1098 default: av_assert0(0);
return 0;
1109 avfilter_graph_free(&fg->
graph);
1114 return f->nb_inputs == 0 &&
1115 (!strcmp(f->filter->name,
"buffer") ||
1116 !strcmp(f->filter->name,
"abuffer"));
1121 for (
unsigned i = 0; i < graph->nb_filters; i++) {
1122 const AVFilterContext *f = graph->filters[i];
1128 if (!((f->filter->flags & AVFILTER_FLAG_METADATA_ONLY) ||
1129 f->nb_outputs == 0 ||
1138 AVFilterInOut *inputs, *outputs, *cur;
1144 if (!(fg->
graph = avfilter_graph_alloc()))
1145 return AVERROR(ENOMEM);
1155 const AVDictionaryEntry *e = NULL;
1156 e = av_dict_get(ost->
encoder_opts,
"threads", NULL, 0);
1158 av_opt_set(fg->
graph,
"threads", e->value, 0);
1161 if (av_dict_count(ost->
sws_dict)) {
1162 ret = av_dict_get_string(ost->
sws_dict,
1163 &fg->
graph->scale_sws_opts,
1169 if (av_dict_count(ost->
swr_opts)) {
1171 ret = av_dict_get_string(ost->
swr_opts, &args,
'=',
':');
1174 av_opt_set(fg->
graph,
"aresample_swr_opts", args, 0);
1188 if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {
1189 const char *num_inputs;
1190 const char *num_outputs;
1193 }
else if (outputs->next) {
1200 }
else if (inputs->next) {
1205 av_log(NULL, AV_LOG_ERROR,
"Simple filtergraph '%s' was expected "
1206 "to have exactly 1 input and 1 output."
1207 " However, it had %s input(s) and %s output(s)."
1208 " Please adjust, or use a complex filtergraph (-filter_complex) instead.\n",
1209 graph_desc, num_inputs, num_outputs);
1210 ret = AVERROR(EINVAL);
1214 for (cur = inputs, i = 0; cur; cur = cur->next, i++)
1216 avfilter_inout_free(&inputs);
1217 avfilter_inout_free(&outputs);
1220 avfilter_inout_free(&inputs);
1222 for (cur = outputs, i = 0; cur; cur = cur->next, i++)
1224 avfilter_inout_free(&outputs);
1227 avfilter_graph_set_auto_convert(fg->
graph, AVFILTER_AUTO_CONVERT_NONE);
1228 if ((ret = avfilter_graph_config(fg->
graph, NULL)) < 0)
1237 AVFilterContext *sink = ofilter->
filter;
1239 ofilter->
format = av_buffersink_get_format(sink);
1241 ofilter->
width = av_buffersink_get_w(sink);
1242 ofilter->
height = av_buffersink_get_h(sink);
1244 ofilter->
sample_rate = av_buffersink_get_sample_rate(sink);
1245 av_channel_layout_uninit(&ofilter->
ch_layout);
1246 ret = av_buffersink_get_ch_layout(sink, &ofilter->
ch_layout);
1255 if (ost->
enc_ctx->codec_type == AVMEDIA_TYPE_AUDIO &&
1256 !(ost->
enc_ctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
1264 ret = av_buffersrc_add_frame(fg->
inputs[i]->
filter, tmp);
1265 av_frame_free(&tmp);
1274 ret = av_buffersrc_add_frame(fg->
inputs[i]->
filter, NULL);
1287 avsubtitle_free(&tmp);
1301 AVFrameSideData *sd;
1306 ifilter->
format = frame->format;
1308 ifilter->
width = frame->width;
1309 ifilter->
height = frame->height;
1313 ret = av_channel_layout_copy(&ifilter->
ch_layout, &frame->ch_layout);
1318 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX);
1320 ifilter->
displaymatrix = av_memdup(sd->data,
sizeof(int32_t) * 9);
1322 if (frame->hw_frames_ctx) {
1323 ifilter->
hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
1325 return AVERROR(ENOMEM);
int64_t start_time
start time in microseconds == AV_TIME_BASE units
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
struct OutputStream * ost
struct FilterGraph * graph
AVChannelLayout ch_layout
int audio_channels_mapped
AVDictionary * encoder_opts