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