FFmpegKit Android API 4.5
fftools_ffmpeg_filter.c
Go to the documentation of this file.
1/*
2 * ffmpeg filter configuration
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 * CHANGES 08.2018
23 * --------------------------------------------------------
24 * - fftools_ prefix added to file name and parent header
25 *
26 * CHANGES 07.2018
27 * --------------------------------------------------------
28 * - Unused headers removed
29 */
30
31#include <stdint.h>
32
33#include "fftools_ffmpeg.h"
34
35#include "libavfilter/avfilter.h"
36#include "libavfilter/buffersink.h"
37#include "libavfilter/buffersrc.h"
38
39#include "libavutil/avassert.h"
40#include "libavutil/avstring.h"
41#include "libavutil/bprint.h"
42#include "libavutil/channel_layout.h"
43#include "libavutil/display.h"
44#include "libavutil/opt.h"
45#include "libavutil/pixdesc.h"
46#include "libavutil/pixfmt.h"
47#include "libavutil/imgutils.h"
48#include "libavutil/samplefmt.h"
49
50// FIXME: YUV420P etc. are actually supported with full color range,
51// yet the latter information isn't available here.
52static const enum AVPixelFormat *get_compliance_normal_pix_fmts(const AVCodec *codec, const enum AVPixelFormat default_formats[])
53{
54 static const enum AVPixelFormat mjpeg_formats[] =
55 { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
56 AV_PIX_FMT_NONE};
57
58 if (!strcmp(codec->name, "mjpeg")) {
59 return mjpeg_formats;
60 } else {
61 return default_formats;
62 }
63}
64
65enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodecContext *enc_ctx,
66 const AVCodec *codec, enum AVPixelFormat target)
67{
68 if (codec && codec->pix_fmts) {
69 const enum AVPixelFormat *p = codec->pix_fmts;
70 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
71 //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
72 int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
73 enum AVPixelFormat best= AV_PIX_FMT_NONE;
74
75 if (enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
77 }
78 for (; *p != AV_PIX_FMT_NONE; p++) {
79 best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
80 if (*p == target)
81 break;
82 }
83 if (*p == AV_PIX_FMT_NONE) {
84 if (target != AV_PIX_FMT_NONE)
85 av_log(NULL, AV_LOG_WARNING,
86 "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
87 av_get_pix_fmt_name(target),
88 codec->name,
89 av_get_pix_fmt_name(best));
90 return best;
91 }
92 }
93 return target;
94}
95
96static char *choose_pix_fmts(OutputFilter *ofilter)
97{
98 OutputStream *ost = ofilter->ost;
99 AVDictionaryEntry *strict_dict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
100 if (strict_dict)
101 // used by choose_pixel_fmt() and below
102 av_opt_set(ost->enc_ctx, "strict", strict_dict->value, 0);
103
104 if (ost->keep_pix_fmt) {
105 avfilter_graph_set_auto_convert(ofilter->graph->graph,
106 AVFILTER_AUTO_CONVERT_NONE);
107 if (ost->enc_ctx->pix_fmt == AV_PIX_FMT_NONE)
108 return NULL;
109 return av_strdup(av_get_pix_fmt_name(ost->enc_ctx->pix_fmt));
110 }
111 if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
112 return av_strdup(av_get_pix_fmt_name(choose_pixel_fmt(ost->st, ost->enc_ctx, ost->enc, ost->enc_ctx->pix_fmt)));
113 } else if (ost->enc && ost->enc->pix_fmts) {
114 const enum AVPixelFormat *p;
115 AVIOContext *s = NULL;
116 uint8_t *ret;
117 int len;
118
119 if (avio_open_dyn_buf(&s) < 0)
120 exit_program(1);
121
122 p = ost->enc->pix_fmts;
123 if (ost->enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
125 }
126
127 for (; *p != AV_PIX_FMT_NONE; p++) {
128 const char *name = av_get_pix_fmt_name(*p);
129 avio_printf(s, "%s|", name);
130 }
131 len = avio_close_dyn_buf(s, &ret);
132 ret[len - 1] = 0;
133 return ret;
134 } else
135 return NULL;
136}
137
138/* Define a function for appending a list of allowed formats
139 * to an AVBPrint. If nonempty, the list will have a header. */
140#define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name) \
141static void choose_ ## name (OutputFilter *ofilter, AVBPrint *bprint) \
142{ \
143 if (ofilter->var == none && !ofilter->supported_list) \
144 return; \
145 av_bprintf(bprint, #name "="); \
146 if (ofilter->var != none) { \
147 av_bprintf(bprint, printf_format, get_name(ofilter->var)); \
148 } else { \
149 const type *p; \
150 \
151 for (p = ofilter->supported_list; *p != none; p++) { \
152 av_bprintf(bprint, printf_format "|", get_name(*p)); \
153 } \
154 if (bprint->len > 0) \
155 bprint->str[--bprint->len] = '\0'; \
156 } \
157 av_bprint_chars(bprint, ':', 1); \
158}
159
160//DEF_CHOOSE_FORMAT(pix_fmts, enum AVPixelFormat, format, formats, AV_PIX_FMT_NONE,
161// GET_PIX_FMT_NAME)
162
163DEF_CHOOSE_FORMAT(sample_fmts, enum AVSampleFormat, format, formats,
164 AV_SAMPLE_FMT_NONE, "%s", av_get_sample_fmt_name)
165
167 "%d", )
168
169DEF_CHOOSE_FORMAT(channel_layouts, uint64_t, channel_layout, channel_layouts, 0,
170 "0x%"PRIx64, )
171
173{
174 FilterGraph *fg = av_mallocz(sizeof(*fg));
175
176 if (!fg)
177 exit_program(1);
179
181 if (!(fg->outputs[0] = av_mallocz(sizeof(*fg->outputs[0]))))
182 exit_program(1);
183 fg->outputs[0]->ost = ost;
184 fg->outputs[0]->graph = fg;
185 fg->outputs[0]->format = -1;
186
187 ost->filter = fg->outputs[0];
188
189 GROW_ARRAY(fg->inputs, fg->nb_inputs);
190 if (!(fg->inputs[0] = av_mallocz(sizeof(*fg->inputs[0]))))
191 exit_program(1);
192 fg->inputs[0]->ist = ist;
193 fg->inputs[0]->graph = fg;
194 fg->inputs[0]->format = -1;
195
196 fg->inputs[0]->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*));
197 if (!fg->inputs[0]->frame_queue)
198 exit_program(1);
199
200 GROW_ARRAY(ist->filters, ist->nb_filters);
201 ist->filters[ist->nb_filters - 1] = fg->inputs[0];
202
205
206 return 0;
207}
208
209static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in)
210{
211 AVFilterContext *ctx = inout->filter_ctx;
212 AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads;
213 int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs;
214 AVIOContext *pb;
215 uint8_t *res = NULL;
216
217 if (avio_open_dyn_buf(&pb) < 0)
218 exit_program(1);
219
220 avio_printf(pb, "%s", ctx->filter->name);
221 if (nb_pads > 1)
222 avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));
223 avio_w8(pb, 0);
224 avio_close_dyn_buf(pb, &res);
225 return res;
226}
227
228static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
229{
230 InputStream *ist = NULL;
231 enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx);
232 int i;
233
234 // TODO: support other filter types
235 if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
236 av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "
237 "currently.\n");
238 exit_program(1);
239 }
240
241 if (in->name) {
242 AVFormatContext *s;
243 AVStream *st = NULL;
244 char *p;
245 int file_idx = strtol(in->name, &p, 0);
246
247 if (file_idx < 0 || file_idx >= nb_input_files) {
248 av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n",
249 file_idx, fg->graph_desc);
250 exit_program(1);
251 }
252 s = input_files[file_idx]->ctx;
253
254 for (i = 0; i < s->nb_streams; i++) {
255 enum AVMediaType stream_type = s->streams[i]->codecpar->codec_type;
256 if (stream_type != type &&
257 !(stream_type == AVMEDIA_TYPE_SUBTITLE &&
258 type == AVMEDIA_TYPE_VIDEO /* sub2video hack */))
259 continue;
260 if (check_stream_specifier(s, s->streams[i], *p == ':' ? p + 1 : p) == 1) {
261 st = s->streams[i];
262 break;
263 }
264 }
265 if (!st) {
266 av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
267 "matches no streams.\n", p, fg->graph_desc);
268 exit_program(1);
269 }
270 ist = input_streams[input_files[file_idx]->ist_index + st->index];
271 if (ist->user_set_discard == AVDISCARD_ALL) {
272 av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
273 "matches a disabled input stream.\n", p, fg->graph_desc);
274 exit_program(1);
275 }
276 } else {
277 /* find the first unused stream of corresponding type */
278 for (i = 0; i < nb_input_streams; i++) {
279 ist = input_streams[i];
280 if (ist->user_set_discard == AVDISCARD_ALL)
281 continue;
282 if (ist->dec_ctx->codec_type == type && ist->discard)
283 break;
284 }
285 if (i == nb_input_streams) {
286 av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "
287 "unlabeled input pad %d on filter %s\n", in->pad_idx,
288 in->filter_ctx->name);
289 exit_program(1);
290 }
291 }
292 av_assert0(ist);
293
294 ist->discard = 0;
295 ist->decoding_needed |= DECODING_FOR_FILTER;
296 ist->st->discard = AVDISCARD_NONE;
297
298 GROW_ARRAY(fg->inputs, fg->nb_inputs);
299 if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0]))))
300 exit_program(1);
301 fg->inputs[fg->nb_inputs - 1]->ist = ist;
302 fg->inputs[fg->nb_inputs - 1]->graph = fg;
303 fg->inputs[fg->nb_inputs - 1]->format = -1;
304 fg->inputs[fg->nb_inputs - 1]->type = ist->st->codecpar->codec_type;
305 fg->inputs[fg->nb_inputs - 1]->name = describe_filter_link(fg, in, 1);
306
307 fg->inputs[fg->nb_inputs - 1]->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*));
308 if (!fg->inputs[fg->nb_inputs - 1]->frame_queue)
309 exit_program(1);
310
311 GROW_ARRAY(ist->filters, ist->nb_filters);
312 ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];
313}
314
316{
317 AVFilterInOut *inputs, *outputs, *cur;
318 AVFilterGraph *graph;
319 int ret = 0;
320
321 /* this graph is only used for determining the kinds of inputs
322 * and outputs we have, and is discarded on exit from this function */
323 graph = avfilter_graph_alloc();
324 if (!graph)
325 return AVERROR(ENOMEM);
326 graph->nb_threads = 1;
327
328 ret = avfilter_graph_parse2(graph, fg->graph_desc, &inputs, &outputs);
329 if (ret < 0)
330 goto fail;
331
332 for (cur = inputs; cur; cur = cur->next)
333 init_input_filter(fg, cur);
334
335 for (cur = outputs; cur;) {
336 GROW_ARRAY(fg->outputs, fg->nb_outputs);
337 fg->outputs[fg->nb_outputs - 1] = av_mallocz(sizeof(*fg->outputs[0]));
338 if (!fg->outputs[fg->nb_outputs - 1])
339 exit_program(1);
340
341 fg->outputs[fg->nb_outputs - 1]->graph = fg;
342 fg->outputs[fg->nb_outputs - 1]->out_tmp = cur;
343 fg->outputs[fg->nb_outputs - 1]->type = avfilter_pad_get_type(cur->filter_ctx->output_pads,
344 cur->pad_idx);
345 fg->outputs[fg->nb_outputs - 1]->name = describe_filter_link(fg, cur, 0);
346 cur = cur->next;
347 fg->outputs[fg->nb_outputs - 1]->out_tmp->next = NULL;
348 }
349
350fail:
351 avfilter_inout_free(&inputs);
352 avfilter_graph_free(&graph);
353 return ret;
354}
355
356static int insert_trim(int64_t start_time, int64_t duration,
357 AVFilterContext **last_filter, int *pad_idx,
358 const char *filter_name)
359{
360 AVFilterGraph *graph = (*last_filter)->graph;
361 AVFilterContext *ctx;
362 const AVFilter *trim;
363 enum AVMediaType type = avfilter_pad_get_type((*last_filter)->output_pads, *pad_idx);
364 const char *name = (type == AVMEDIA_TYPE_VIDEO) ? "trim" : "atrim";
365 int ret = 0;
366
367 if (duration == INT64_MAX && start_time == AV_NOPTS_VALUE)
368 return 0;
369
370 trim = avfilter_get_by_name(name);
371 if (!trim) {
372 av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "
373 "recording time.\n", name);
374 return AVERROR_FILTER_NOT_FOUND;
375 }
376
377 ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
378 if (!ctx)
379 return AVERROR(ENOMEM);
380
381 if (duration != INT64_MAX) {
382 ret = av_opt_set_int(ctx, "durationi", duration,
383 AV_OPT_SEARCH_CHILDREN);
384 }
385 if (ret >= 0 && start_time != AV_NOPTS_VALUE) {
386 ret = av_opt_set_int(ctx, "starti", start_time,
387 AV_OPT_SEARCH_CHILDREN);
388 }
389 if (ret < 0) {
390 av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
391 return ret;
392 }
393
394 ret = avfilter_init_str(ctx, NULL);
395 if (ret < 0)
396 return ret;
397
398 ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
399 if (ret < 0)
400 return ret;
401
402 *last_filter = ctx;
403 *pad_idx = 0;
404 return 0;
405}
406
407static int insert_filter(AVFilterContext **last_filter, int *pad_idx,
408 const char *filter_name, const char *args)
409{
410 AVFilterGraph *graph = (*last_filter)->graph;
411 AVFilterContext *ctx;
412 int ret;
413
414 ret = avfilter_graph_create_filter(&ctx,
415 avfilter_get_by_name(filter_name),
416 filter_name, args, NULL, graph);
417 if (ret < 0)
418 return ret;
419
420 ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
421 if (ret < 0)
422 return ret;
423
424 *last_filter = ctx;
425 *pad_idx = 0;
426 return 0;
427}
428
429static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
430{
431 char *pix_fmts;
432 OutputStream *ost = ofilter->ost;
434 AVFilterContext *last_filter = out->filter_ctx;
435 int pad_idx = out->pad_idx;
436 int ret;
437 char name[255];
438
439 snprintf(name, sizeof(name), "out_%d_%d", ost->file_index, ost->index);
440 ret = avfilter_graph_create_filter(&ofilter->filter,
441 avfilter_get_by_name("buffersink"),
442 name, NULL, NULL, fg->graph);
443
444 if (ret < 0)
445 return ret;
446
447 if ((ofilter->width || ofilter->height) && ofilter->ost->autoscale) {
448 char args[255];
449 AVFilterContext *filter;
450 AVDictionaryEntry *e = NULL;
451
452 snprintf(args, sizeof(args), "%d:%d",
453 ofilter->width, ofilter->height);
454
455 while ((e = av_dict_get(ost->sws_dict, "", e,
456 AV_DICT_IGNORE_SUFFIX))) {
457 av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value);
458 }
459
460 snprintf(name, sizeof(name), "scaler_out_%d_%d",
462 if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
463 name, args, NULL, fg->graph)) < 0)
464 return ret;
465 if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
466 return ret;
467
468 last_filter = filter;
469 pad_idx = 0;
470 }
471
472 if ((pix_fmts = choose_pix_fmts(ofilter))) {
473 AVFilterContext *filter;
474
475 ret = avfilter_graph_create_filter(&filter,
476 avfilter_get_by_name("format"),
477 "format", pix_fmts, NULL, fg->graph);
478 av_freep(&pix_fmts);
479 if (ret < 0)
480 return ret;
481 if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
482 return ret;
483
484 last_filter = filter;
485 pad_idx = 0;
486 }
487
488 if (ost->frame_rate.num && 0) {
489 AVFilterContext *fps;
490 char args[255];
491
492 snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,
493 ost->frame_rate.den);
494 snprintf(name, sizeof(name), "fps_out_%d_%d",
496 ret = avfilter_graph_create_filter(&fps, avfilter_get_by_name("fps"),
497 name, args, NULL, fg->graph);
498 if (ret < 0)
499 return ret;
500
501 ret = avfilter_link(last_filter, pad_idx, fps, 0);
502 if (ret < 0)
503 return ret;
504 last_filter = fps;
505 pad_idx = 0;
506 }
507
508 snprintf(name, sizeof(name), "trim_out_%d_%d",
511 &last_filter, &pad_idx, name);
512 if (ret < 0)
513 return ret;
514
515
516 if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
517 return ret;
518
519 return 0;
520}
521
522static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
523{
524 OutputStream *ost = ofilter->ost;
526 AVCodecContext *codec = ost->enc_ctx;
527 AVFilterContext *last_filter = out->filter_ctx;
528 int pad_idx = out->pad_idx;
529 AVBPrint args;
530 char name[255];
531 int ret;
532
533 snprintf(name, sizeof(name), "out_%d_%d", ost->file_index, ost->index);
534 ret = avfilter_graph_create_filter(&ofilter->filter,
535 avfilter_get_by_name("abuffersink"),
536 name, NULL, NULL, fg->graph);
537 if (ret < 0)
538 return ret;
539 if ((ret = av_opt_set_int(ofilter->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0)
540 return ret;
541
542#define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
543 AVFilterContext *filt_ctx; \
544 \
545 av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
546 "similarly to -af " filter_name "=%s.\n", arg); \
547 \
548 ret = avfilter_graph_create_filter(&filt_ctx, \
549 avfilter_get_by_name(filter_name), \
550 filter_name, arg, NULL, fg->graph); \
551 if (ret < 0) \
552 goto fail; \
553 \
554 ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
555 if (ret < 0) \
556 goto fail; \
557 \
558 last_filter = filt_ctx; \
559 pad_idx = 0; \
560} while (0)
561 av_bprint_init(&args, 0, AV_BPRINT_SIZE_UNLIMITED);
563 int i;
564 av_bprintf(&args, "0x%"PRIx64,
565 av_get_default_channel_layout(ost->audio_channels_mapped));
566 for (i = 0; i < ost->audio_channels_mapped; i++)
567 if (ost->audio_channels_map[i] != -1)
568 av_bprintf(&args, "|c%d=c%d", i, ost->audio_channels_map[i]);
569
570 AUTO_INSERT_FILTER("-map_channel", "pan", args.str);
571 av_bprint_clear(&args);
572 }
573
574 if (codec->channels && !codec->channel_layout)
575 codec->channel_layout = av_get_default_channel_layout(codec->channels);
576
577 choose_sample_fmts(ofilter, &args);
578 choose_sample_rates(ofilter, &args);
579 choose_channel_layouts(ofilter, &args);
580 if (!av_bprint_is_complete(&args)) {
581 ret = AVERROR(ENOMEM);
582 goto fail;
583 }
584 if (args.len) {
585 AVFilterContext *format;
586
587 snprintf(name, sizeof(name), "format_out_%d_%d",
589 ret = avfilter_graph_create_filter(&format,
590 avfilter_get_by_name("aformat"),
591 name, args.str, NULL, fg->graph);
592 if (ret < 0)
593 goto fail;
594
595 ret = avfilter_link(last_filter, pad_idx, format, 0);
596 if (ret < 0)
597 goto fail;
598
599 last_filter = format;
600 pad_idx = 0;
601 }
602
603 if (ost->apad && of->shortest) {
604 int i;
605
606 for (i=0; i<of->ctx->nb_streams; i++)
607 if (of->ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
608 break;
609
610 if (i<of->ctx->nb_streams) {
611 AUTO_INSERT_FILTER("-apad", "apad", ost->apad);
612 }
613 }
614
615 snprintf(name, sizeof(name), "trim for output stream %d:%d",
618 &last_filter, &pad_idx, name);
619 if (ret < 0)
620 goto fail;
621
622 if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
623 goto fail;
624fail:
625 av_bprint_finalize(&args, NULL);
626
627 return ret;
628}
629
631 AVFilterInOut *out)
632{
633 if (!ofilter->ost) {
634 av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", ofilter->name);
635 exit_program(1);
636 }
637
638 switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
639 case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, ofilter, out);
640 case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, ofilter, out);
641 default: av_assert0(0); return 0;
642 }
643}
644
646{
647 int i;
648 for (i = 0; i < nb_filtergraphs; i++) {
649 int n;
650 for (n = 0; n < filtergraphs[i]->nb_outputs; n++) {
651 OutputFilter *output = filtergraphs[i]->outputs[n];
652 if (!output->ost) {
653 av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", output->name);
654 exit_program(1);
655 }
656 }
657 }
658}
659
661{
662 AVFormatContext *avf = input_files[ist->file_index]->ctx;
663 int i, w, h;
664
665 /* Compute the size of the canvas for the subtitles stream.
666 If the subtitles codecpar has set a size, use it. Otherwise use the
667 maximum dimensions of the video streams in the same file. */
668 w = ifilter->width;
669 h = ifilter->height;
670 if (!(w && h)) {
671 for (i = 0; i < avf->nb_streams; i++) {
672 if (avf->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
673 w = FFMAX(w, avf->streams[i]->codecpar->width);
674 h = FFMAX(h, avf->streams[i]->codecpar->height);
675 }
676 }
677 if (!(w && h)) {
678 w = FFMAX(w, 720);
679 h = FFMAX(h, 576);
680 }
681 av_log(avf, AV_LOG_INFO, "sub2video: using %dx%d canvas\n", w, h);
682 }
683 ist->sub2video.w = ifilter->width = w;
684 ist->sub2video.h = ifilter->height = h;
685
686 ifilter->width = ist->dec_ctx->width ? ist->dec_ctx->width : ist->sub2video.w;
687 ifilter->height = ist->dec_ctx->height ? ist->dec_ctx->height : ist->sub2video.h;
688
689 /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the
690 palettes for all rectangles are identical or compatible */
691 ifilter->format = AV_PIX_FMT_RGB32;
692
693 ist->sub2video.frame = av_frame_alloc();
694 if (!ist->sub2video.frame)
695 return AVERROR(ENOMEM);
696 ist->sub2video.last_pts = INT64_MIN;
697 ist->sub2video.end_pts = INT64_MIN;
698
699 /* sub2video structure has been (re-)initialized.
700 Mark it as such so that the system will be
701 initialized with the first received heartbeat. */
702 ist->sub2video.initialize = 1;
703
704 return 0;
705}
706
708 AVFilterInOut *in)
709{
710 AVFilterContext *last_filter;
711 const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
712 InputStream *ist = ifilter->ist;
713 InputFile *f = input_files[ist->file_index];
714 AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :
715 ist->st->time_base;
716 AVRational fr = ist->framerate;
717 AVRational sar;
718 AVBPrint args;
719 char name[255];
720 int ret, pad_idx = 0;
721 int64_t tsoffset = 0;
722 AVBufferSrcParameters *par = av_buffersrc_parameters_alloc();
723
724 if (!par)
725 return AVERROR(ENOMEM);
726 memset(par, 0, sizeof(*par));
727 par->format = AV_PIX_FMT_NONE;
728
729 if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
730 av_log(NULL, AV_LOG_ERROR, "Cannot connect video filter to audio input\n");
731 ret = AVERROR(EINVAL);
732 goto fail;
733 }
734
735 if (!fr.num)
736 fr = av_guess_frame_rate(input_files[ist->file_index]->ctx, ist->st, NULL);
737
738 if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
739 ret = sub2video_prepare(ist, ifilter);
740 if (ret < 0)
741 goto fail;
742 }
743
744 sar = ifilter->sample_aspect_ratio;
745 if(!sar.den)
746 sar = (AVRational){0,1};
747 av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC);
748 av_bprintf(&args,
749 "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
750 "pixel_aspect=%d/%d",
751 ifilter->width, ifilter->height, ifilter->format,
752 tb.num, tb.den, sar.num, sar.den);
753 if (fr.num && fr.den)
754 av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den);
755 snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
756 ist->file_index, ist->st->index);
757
758
759 if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name,
760 args.str, NULL, fg->graph)) < 0)
761 goto fail;
762 par->hw_frames_ctx = ifilter->hw_frames_ctx;
763 ret = av_buffersrc_parameters_set(ifilter->filter, par);
764 if (ret < 0)
765 goto fail;
766 av_freep(&par);
767 last_filter = ifilter->filter;
768
769 if (ist->autorotate) {
770 double theta = get_rotation(ist->st);
771
772 if (fabs(theta - 90) < 1.0) {
773 ret = insert_filter(&last_filter, &pad_idx, "transpose", "clock");
774 } else if (fabs(theta - 180) < 1.0) {
775 ret = insert_filter(&last_filter, &pad_idx, "hflip", NULL);
776 if (ret < 0)
777 return ret;
778 ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
779 } else if (fabs(theta - 270) < 1.0) {
780 ret = insert_filter(&last_filter, &pad_idx, "transpose", "cclock");
781 } else if (fabs(theta) > 1.0) {
782 char rotate_buf[64];
783 snprintf(rotate_buf, sizeof(rotate_buf), "%f*PI/180", theta);
784 ret = insert_filter(&last_filter, &pad_idx, "rotate", rotate_buf);
785 }
786 if (ret < 0)
787 return ret;
788 }
789
790 if (do_deinterlace) {
791 AVFilterContext *yadif;
792
793 snprintf(name, sizeof(name), "deinterlace_in_%d_%d",
794 ist->file_index, ist->st->index);
795 if ((ret = avfilter_graph_create_filter(&yadif,
796 avfilter_get_by_name("yadif"),
797 name, "", NULL,
798 fg->graph)) < 0)
799 return ret;
800
801 if ((ret = avfilter_link(last_filter, 0, yadif, 0)) < 0)
802 return ret;
803
804 last_filter = yadif;
805 }
806
807 snprintf(name, sizeof(name), "trim_in_%d_%d",
808 ist->file_index, ist->st->index);
809 if (copy_ts) {
810 tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
811 if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
812 tsoffset += f->ctx->start_time;
813 }
814 ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
815 AV_NOPTS_VALUE : tsoffset, f->recording_time,
816 &last_filter, &pad_idx, name);
817 if (ret < 0)
818 return ret;
819
820 if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
821 return ret;
822 return 0;
823fail:
824 av_freep(&par);
825
826 return ret;
827}
828
830 AVFilterInOut *in)
831{
832 AVFilterContext *last_filter;
833 const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
834 InputStream *ist = ifilter->ist;
835 InputFile *f = input_files[ist->file_index];
836 AVBPrint args;
837 char name[255];
838 int ret, pad_idx = 0;
839 int64_t tsoffset = 0;
840
841 if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_AUDIO) {
842 av_log(NULL, AV_LOG_ERROR, "Cannot connect audio filter to non audio input\n");
843 return AVERROR(EINVAL);
844 }
845
846 av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC);
847 av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
848 1, ifilter->sample_rate,
849 ifilter->sample_rate,
850 av_get_sample_fmt_name(ifilter->format));
851 if (ifilter->channel_layout)
852 av_bprintf(&args, ":channel_layout=0x%"PRIx64,
853 ifilter->channel_layout);
854 else
855 av_bprintf(&args, ":channels=%d", ifilter->channels);
856 snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index,
857 ist->file_index, ist->st->index);
858
859 if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt,
860 name, args.str, NULL,
861 fg->graph)) < 0)
862 return ret;
863 last_filter = ifilter->filter;
864
865#define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg) do { \
866 AVFilterContext *filt_ctx; \
867 \
868 av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
869 "similarly to -af " filter_name "=%s.\n", arg); \
870 \
871 snprintf(name, sizeof(name), "graph_%d_%s_in_%d_%d", \
872 fg->index, filter_name, ist->file_index, ist->st->index); \
873 ret = avfilter_graph_create_filter(&filt_ctx, \
874 avfilter_get_by_name(filter_name), \
875 name, arg, NULL, fg->graph); \
876 if (ret < 0) \
877 return ret; \
878 \
879 ret = avfilter_link(last_filter, 0, filt_ctx, 0); \
880 if (ret < 0) \
881 return ret; \
882 \
883 last_filter = filt_ctx; \
884} while (0)
885
886 if (audio_sync_method > 0) {
887 char args[256] = {0};
888
889 av_strlcatf(args, sizeof(args), "async=%d", audio_sync_method);
890 if (audio_drift_threshold != 0.1)
891 av_strlcatf(args, sizeof(args), ":min_hard_comp=%f", audio_drift_threshold);
892 if (!fg->reconfiguration)
893 av_strlcatf(args, sizeof(args), ":first_pts=0");
894 AUTO_INSERT_FILTER_INPUT("-async", "aresample", args);
895 }
896
897// if (ost->audio_channels_mapped) {
898// int i;
899// AVBPrint pan_buf;
900// av_bprint_init(&pan_buf, 256, 8192);
901// av_bprintf(&pan_buf, "0x%"PRIx64,
902// av_get_default_channel_layout(ost->audio_channels_mapped));
903// for (i = 0; i < ost->audio_channels_mapped; i++)
904// if (ost->audio_channels_map[i] != -1)
905// av_bprintf(&pan_buf, ":c%d=c%d", i, ost->audio_channels_map[i]);
906// AUTO_INSERT_FILTER_INPUT("-map_channel", "pan", pan_buf.str);
907// av_bprint_finalize(&pan_buf, NULL);
908// }
909
910 if (audio_volume != 256) {
911 char args[256];
912
913 av_log(NULL, AV_LOG_WARNING, "-vol has been deprecated. Use the volume "
914 "audio filter instead.\n");
915
916 snprintf(args, sizeof(args), "%f", audio_volume / 256.);
917 AUTO_INSERT_FILTER_INPUT("-vol", "volume", args);
918 }
919
920 snprintf(name, sizeof(name), "trim for input stream %d:%d",
921 ist->file_index, ist->st->index);
922 if (copy_ts) {
923 tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
924 if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
925 tsoffset += f->ctx->start_time;
926 }
927 ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
928 AV_NOPTS_VALUE : tsoffset, f->recording_time,
929 &last_filter, &pad_idx, name);
930 if (ret < 0)
931 return ret;
932
933 if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
934 return ret;
935
936 return 0;
937}
938
940 AVFilterInOut *in)
941{
942 if (!ifilter->ist->dec) {
943 av_log(NULL, AV_LOG_ERROR,
944 "No decoder for stream #%d:%d, filtering impossible\n",
945 ifilter->ist->file_index, ifilter->ist->st->index);
946 return AVERROR_DECODER_NOT_FOUND;
947 }
948 switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) {
949 case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in);
950 case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in);
951 default: av_assert0(0); return 0;
952 }
953}
954
956{
957 int i;
958 for (i = 0; i < fg->nb_outputs; i++)
959 fg->outputs[i]->filter = (AVFilterContext *)NULL;
960 for (i = 0; i < fg->nb_inputs; i++)
961 fg->inputs[i]->filter = (AVFilterContext *)NULL;
962 avfilter_graph_free(&fg->graph);
963}
964
966{
967 AVFilterInOut *inputs, *outputs, *cur;
968 int ret, i, simple = filtergraph_is_simple(fg);
969 const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
970 fg->graph_desc;
971
973 if (!(fg->graph = avfilter_graph_alloc()))
974 return AVERROR(ENOMEM);
975
976 if (simple) {
977 OutputStream *ost = fg->outputs[0]->ost;
978 char args[512];
979 AVDictionaryEntry *e = NULL;
980
981 fg->graph->nb_threads = filter_nbthreads;
982
983 args[0] = 0;
984 while ((e = av_dict_get(ost->sws_dict, "", e,
985 AV_DICT_IGNORE_SUFFIX))) {
986 av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
987 }
988 if (strlen(args))
989 args[strlen(args)-1] = 0;
990
991 if (!strncmp(args, "sws_flags=", 10)) {
992 // keep the 'flags=' part
993 fg->graph->scale_sws_opts = av_strdup(args+4);
994 }
995
996 args[0] = 0;
997 while ((e = av_dict_get(ost->swr_opts, "", e,
998 AV_DICT_IGNORE_SUFFIX))) {
999 av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
1000 }
1001 if (strlen(args))
1002 args[strlen(args)-1] = 0;
1003 av_opt_set(fg->graph, "aresample_swr_opts", args, 0);
1004
1005 args[0] = '\0';
1006 while ((e = av_dict_get(fg->outputs[0]->ost->resample_opts, "", e,
1007 AV_DICT_IGNORE_SUFFIX))) {
1008 av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
1009 }
1010 if (strlen(args))
1011 args[strlen(args) - 1] = '\0';
1012
1013 e = av_dict_get(ost->encoder_opts, "threads", NULL, 0);
1014 if (e)
1015 av_opt_set(fg->graph, "threads", e->value, 0);
1016 } else {
1017 fg->graph->nb_threads = filter_complex_nbthreads;
1018 }
1019
1020 if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
1021 goto fail;
1022
1024 if (ret < 0)
1025 goto fail;
1026
1027 if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {
1028 const char *num_inputs;
1029 const char *num_outputs;
1030 if (!outputs) {
1031 num_outputs = "0";
1032 } else if (outputs->next) {
1033 num_outputs = ">1";
1034 } else {
1035 num_outputs = "1";
1036 }
1037 if (!inputs) {
1038 num_inputs = "0";
1039 } else if (inputs->next) {
1040 num_inputs = ">1";
1041 } else {
1042 num_inputs = "1";
1043 }
1044 av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' was expected "
1045 "to have exactly 1 input and 1 output."
1046 " However, it had %s input(s) and %s output(s)."
1047 " Please adjust, or use a complex filtergraph (-filter_complex) instead.\n",
1048 graph_desc, num_inputs, num_outputs);
1049 ret = AVERROR(EINVAL);
1050 goto fail;
1051 }
1052
1053 for (cur = inputs, i = 0; cur; cur = cur->next, i++)
1054 if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0) {
1055 avfilter_inout_free(&inputs);
1056 avfilter_inout_free(&outputs);
1057 goto fail;
1058 }
1059 avfilter_inout_free(&inputs);
1060
1061 for (cur = outputs, i = 0; cur; cur = cur->next, i++)
1062 configure_output_filter(fg, fg->outputs[i], cur);
1063 avfilter_inout_free(&outputs);
1064
1066 avfilter_graph_set_auto_convert(fg->graph, AVFILTER_AUTO_CONVERT_NONE);
1067 if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
1068 goto fail;
1069
1070 /* limit the lists of allowed formats to the ones selected, to
1071 * make sure they stay the same if the filtergraph is reconfigured later */
1072 for (i = 0; i < fg->nb_outputs; i++) {
1073 OutputFilter *ofilter = fg->outputs[i];
1074 AVFilterContext *sink = ofilter->filter;
1075
1076 ofilter->format = av_buffersink_get_format(sink);
1077
1078 ofilter->width = av_buffersink_get_w(sink);
1079 ofilter->height = av_buffersink_get_h(sink);
1080
1081 ofilter->sample_rate = av_buffersink_get_sample_rate(sink);
1082 ofilter->channel_layout = av_buffersink_get_channel_layout(sink);
1083 }
1084
1085 fg->reconfiguration = 1;
1086
1087 for (i = 0; i < fg->nb_outputs; i++) {
1088 OutputStream *ost = fg->outputs[i]->ost;
1089 if (!ost->enc) {
1090 /* identical to the same check in ffmpeg.c, needed because
1091 complex filter graphs are initialized earlier */
1092 av_log(NULL, AV_LOG_ERROR, "Encoder (codec %s) not found for output stream #%d:%d\n",
1093 avcodec_get_name(ost->st->codecpar->codec_id), ost->file_index, ost->index);
1094 ret = AVERROR(EINVAL);
1095 goto fail;
1096 }
1097 if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
1098 !(ost->enc->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
1099 av_buffersink_set_frame_size(ost->filter->filter,
1100 ost->enc_ctx->frame_size);
1101 }
1102
1103 for (i = 0; i < fg->nb_inputs; i++) {
1104 while (av_fifo_size(fg->inputs[i]->frame_queue)) {
1105 AVFrame *tmp;
1106 av_fifo_generic_read(fg->inputs[i]->frame_queue, &tmp, sizeof(tmp), NULL);
1107 ret = av_buffersrc_add_frame(fg->inputs[i]->filter, tmp);
1108 av_frame_free(&tmp);
1109 if (ret < 0)
1110 goto fail;
1111 }
1112 }
1113
1114 /* send the EOFs for the finished inputs */
1115 for (i = 0; i < fg->nb_inputs; i++) {
1116 if (fg->inputs[i]->eof) {
1117 ret = av_buffersrc_add_frame(fg->inputs[i]->filter, NULL);
1118 if (ret < 0)
1119 goto fail;
1120 }
1121 }
1122
1123 /* process queued up subtitle packets */
1124 for (i = 0; i < fg->nb_inputs; i++) {
1125 InputStream *ist = fg->inputs[i]->ist;
1126 if (ist->sub2video.sub_queue && ist->sub2video.frame) {
1127 while (av_fifo_size(ist->sub2video.sub_queue)) {
1128 AVSubtitle tmp;
1129 av_fifo_generic_read(ist->sub2video.sub_queue, &tmp, sizeof(tmp), NULL);
1130 sub2video_update(ist, INT64_MIN, &tmp);
1131 avsubtitle_free(&tmp);
1132 }
1133 }
1134 }
1135
1136 return 0;
1137
1138fail:
1140 return ret;
1141}
1142
1143int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
1144{
1145 av_buffer_unref(&ifilter->hw_frames_ctx);
1146
1147 ifilter->format = frame->format;
1148
1149 ifilter->width = frame->width;
1150 ifilter->height = frame->height;
1151 ifilter->sample_aspect_ratio = frame->sample_aspect_ratio;
1152
1153 ifilter->sample_rate = frame->sample_rate;
1154 ifilter->channels = frame->channels;
1155 ifilter->channel_layout = frame->channel_layout;
1156
1157 if (frame->hw_frames_ctx) {
1158 ifilter->hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
1159 if (!ifilter->hw_frames_ctx)
1160 return AVERROR(ENOMEM);
1161 }
1162
1163 return 0;
1164}
1165
1167{
1168 return !fg->graph_desc;
1169}
void exit_program(int ret)
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
double get_rotation(AVStream *st)
__thread InputStream ** input_streams
__thread int nb_input_streams
__thread OutputFile ** output_files
__thread int nb_input_files
__thread InputFile ** input_files
void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub)
__thread int nb_filtergraphs
__thread int filter_complex_nbthreads
__thread int audio_volume
__thread int copy_ts
__thread int filter_nbthreads
#define DECODING_FOR_FILTER
__thread int do_deinterlace
__thread int audio_sync_method
int hw_device_setup_for_filter(FilterGraph *fg)
int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
__thread float audio_drift_threshold
__thread int start_at_zero
__thread int auto_conversion_filters
static void cleanup_filtergraph(FilterGraph *fg)
int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
static int sub2video_prepare(InputStream *ist, InputFilter *ifilter)
static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
static enum AVPixelFormat * get_compliance_normal_pix_fmts(const AVCodec *codec, const enum AVPixelFormat default_formats[])
fg inputs[0] ist
OutputStream * ost
enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodecContext *enc_ctx, const AVCodec *codec, enum AVPixelFormat target)
GROW_ARRAY(fg->outputs, fg->nb_outputs)
static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
ost filter
static char * choose_pix_fmts(OutputFilter *ofilter)
filtergraphs[nb_filtergraphs - 1]
fg outputs[0] format
static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
static int insert_trim(int64_t start_time, int64_t duration, AVFilterContext **last_filter, int *pad_idx, const char *filter_name)
fg outputs[0] graph
#define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg)
static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
static char * describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in)
#define AUTO_INSERT_FILTER(opt_name, filter_name, arg)
static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
int filtergraph_is_simple(FilterGraph *fg)
void check_filter_outputs(void)
static int insert_filter(AVFilterContext **last_filter, int *pad_idx, const char *filter_name, const char *args)
#define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name)
int configure_filtergraph(FilterGraph *fg)
int init_complex_filtergraph(FilterGraph *fg)
OutputFilter ** outputs
const char * graph_desc
AVFilterGraph * graph
InputFilter ** inputs
AVFormatContext * ctx
int64_t recording_time
int64_t start_time
AVBufferRef * hw_frames_ctx
uint8_t * name
struct InputStream * ist
AVFilterContext * filter
enum AVMediaType type
AVFifoBuffer * frame_queue
uint64_t channel_layout
struct FilterGraph * graph
AVRational sample_aspect_ratio
AVStream * st
const AVCodec * dec
AVFormatContext * ctx
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
AVFilterInOut * out_tmp
struct OutputStream * ost
AVFilterContext * filter
uint8_t * name
struct FilterGraph * graph
uint64_t channel_layout
enum AVMediaType type
AVDictionary * swr_opts
int * audio_channels_map
const AVCodec * enc
int audio_channels_mapped
AVDictionary * resample_opts
AVRational frame_rate
AVCodecContext * enc_ctx
AVDictionary * encoder_opts
AVStream * st
AVDictionary * sws_dict
OutputFilter * filter