You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1160 lines
43KB

  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. #include <stdint.h>
  21. #include "ffmpeg.h"
  22. #include "libavfilter/avfilter.h"
  23. #include "libavfilter/buffersink.h"
  24. #include "libavfilter/buffersrc.h"
  25. #include "libavresample/avresample.h"
  26. #include "libavutil/avassert.h"
  27. #include "libavutil/avstring.h"
  28. #include "libavutil/bprint.h"
  29. #include "libavutil/channel_layout.h"
  30. #include "libavutil/display.h"
  31. #include "libavutil/opt.h"
  32. #include "libavutil/pixdesc.h"
  33. #include "libavutil/pixfmt.h"
  34. #include "libavutil/imgutils.h"
  35. #include "libavutil/samplefmt.h"
  36. static const enum AVPixelFormat *get_compliance_unofficial_pix_fmts(enum AVCodecID codec_id, const enum AVPixelFormat default_formats[])
  37. {
  38. static const enum AVPixelFormat mjpeg_formats[] =
  39. { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
  40. AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P,
  41. AV_PIX_FMT_NONE };
  42. static const enum AVPixelFormat ljpeg_formats[] =
  43. { AV_PIX_FMT_BGR24 , AV_PIX_FMT_BGRA , AV_PIX_FMT_BGR0,
  44. AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P,
  45. AV_PIX_FMT_YUV420P , AV_PIX_FMT_YUV444P , AV_PIX_FMT_YUV422P,
  46. AV_PIX_FMT_NONE};
  47. if (codec_id == AV_CODEC_ID_MJPEG) {
  48. return mjpeg_formats;
  49. } else if (codec_id == AV_CODEC_ID_LJPEG) {
  50. return ljpeg_formats;
  51. } else {
  52. return default_formats;
  53. }
  54. }
  55. enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodecContext *enc_ctx, AVCodec *codec, enum AVPixelFormat target)
  56. {
  57. if (codec && codec->pix_fmts) {
  58. const enum AVPixelFormat *p = codec->pix_fmts;
  59. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
  60. int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
  61. enum AVPixelFormat best= AV_PIX_FMT_NONE;
  62. if (enc_ctx->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) {
  63. p = get_compliance_unofficial_pix_fmts(enc_ctx->codec_id, p);
  64. }
  65. for (; *p != AV_PIX_FMT_NONE; p++) {
  66. best= avcodec_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
  67. if (*p == target)
  68. break;
  69. }
  70. if (*p == AV_PIX_FMT_NONE) {
  71. if (target != AV_PIX_FMT_NONE)
  72. av_log(NULL, AV_LOG_WARNING,
  73. "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
  74. av_get_pix_fmt_name(target),
  75. codec->name,
  76. av_get_pix_fmt_name(best));
  77. return best;
  78. }
  79. }
  80. return target;
  81. }
  82. void choose_sample_fmt(AVStream *st, AVCodec *codec)
  83. {
  84. if (codec && codec->sample_fmts) {
  85. const enum AVSampleFormat *p = codec->sample_fmts;
  86. for (; *p != -1; p++) {
  87. if (*p == st->codecpar->format)
  88. break;
  89. }
  90. if (*p == -1) {
  91. if((codec->capabilities & AV_CODEC_CAP_LOSSLESS) && av_get_sample_fmt_name(st->codecpar->format) > av_get_sample_fmt_name(codec->sample_fmts[0]))
  92. av_log(NULL, AV_LOG_ERROR, "Conversion will not be lossless.\n");
  93. if(av_get_sample_fmt_name(st->codecpar->format))
  94. av_log(NULL, AV_LOG_WARNING,
  95. "Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n",
  96. av_get_sample_fmt_name(st->codecpar->format),
  97. codec->name,
  98. av_get_sample_fmt_name(codec->sample_fmts[0]));
  99. st->codecpar->format = codec->sample_fmts[0];
  100. }
  101. }
  102. }
  103. static char *choose_pix_fmts(OutputStream *ost)
  104. {
  105. AVDictionaryEntry *strict_dict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
  106. if (strict_dict)
  107. // used by choose_pixel_fmt() and below
  108. av_opt_set(ost->enc_ctx, "strict", strict_dict->value, 0);
  109. if (ost->keep_pix_fmt) {
  110. if (ost->filter)
  111. avfilter_graph_set_auto_convert(ost->filter->graph->graph,
  112. AVFILTER_AUTO_CONVERT_NONE);
  113. if (ost->enc_ctx->pix_fmt == AV_PIX_FMT_NONE)
  114. return NULL;
  115. return av_strdup(av_get_pix_fmt_name(ost->enc_ctx->pix_fmt));
  116. }
  117. if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
  118. return av_strdup(av_get_pix_fmt_name(choose_pixel_fmt(ost->st, ost->enc_ctx, ost->enc, ost->enc_ctx->pix_fmt)));
  119. } else if (ost->enc && ost->enc->pix_fmts) {
  120. const enum AVPixelFormat *p;
  121. AVIOContext *s = NULL;
  122. uint8_t *ret;
  123. int len;
  124. if (avio_open_dyn_buf(&s) < 0)
  125. exit_program(1);
  126. p = ost->enc->pix_fmts;
  127. if (ost->enc_ctx->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) {
  128. p = get_compliance_unofficial_pix_fmts(ost->enc_ctx->codec_id, p);
  129. }
  130. for (; *p != AV_PIX_FMT_NONE; p++) {
  131. const char *name = av_get_pix_fmt_name(*p);
  132. avio_printf(s, "%s|", name);
  133. }
  134. len = avio_close_dyn_buf(s, &ret);
  135. ret[len - 1] = 0;
  136. return ret;
  137. } else
  138. return NULL;
  139. }
  140. /* Define a function for building a string containing a list of
  141. * allowed formats. */
  142. #define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name) \
  143. static char *choose_ ## var ## s(OutputStream *ost) \
  144. { \
  145. if (ost->enc_ctx->var != none) { \
  146. get_name(ost->enc_ctx->var); \
  147. return av_strdup(name); \
  148. } else if (ost->enc && ost->enc->supported_list) { \
  149. const type *p; \
  150. AVIOContext *s = NULL; \
  151. uint8_t *ret; \
  152. int len; \
  153. \
  154. if (avio_open_dyn_buf(&s) < 0) \
  155. exit_program(1); \
  156. \
  157. for (p = ost->enc->supported_list; *p != none; p++) { \
  158. get_name(*p); \
  159. avio_printf(s, "%s|", name); \
  160. } \
  161. len = avio_close_dyn_buf(s, &ret); \
  162. ret[len - 1] = 0; \
  163. return ret; \
  164. } else \
  165. return NULL; \
  166. }
  167. // DEF_CHOOSE_FORMAT(enum AVPixelFormat, pix_fmt, pix_fmts, AV_PIX_FMT_NONE,
  168. // GET_PIX_FMT_NAME)
  169. DEF_CHOOSE_FORMAT(enum AVSampleFormat, sample_fmt, sample_fmts,
  170. AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME)
  171. DEF_CHOOSE_FORMAT(int, sample_rate, supported_samplerates, 0,
  172. GET_SAMPLE_RATE_NAME)
  173. DEF_CHOOSE_FORMAT(uint64_t, channel_layout, channel_layouts, 0,
  174. GET_CH_LAYOUT_NAME)
  175. int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
  176. {
  177. FilterGraph *fg = av_mallocz(sizeof(*fg));
  178. if (!fg)
  179. exit_program(1);
  180. fg->index = nb_filtergraphs;
  181. GROW_ARRAY(fg->outputs, fg->nb_outputs);
  182. if (!(fg->outputs[0] = av_mallocz(sizeof(*fg->outputs[0]))))
  183. exit_program(1);
  184. fg->outputs[0]->ost = ost;
  185. fg->outputs[0]->graph = fg;
  186. ost->filter = fg->outputs[0];
  187. GROW_ARRAY(fg->inputs, fg->nb_inputs);
  188. if (!(fg->inputs[0] = av_mallocz(sizeof(*fg->inputs[0]))))
  189. exit_program(1);
  190. fg->inputs[0]->ist = ist;
  191. fg->inputs[0]->graph = fg;
  192. fg->inputs[0]->format = -1;
  193. GROW_ARRAY(ist->filters, ist->nb_filters);
  194. ist->filters[ist->nb_filters - 1] = fg->inputs[0];
  195. GROW_ARRAY(filtergraphs, nb_filtergraphs);
  196. filtergraphs[nb_filtergraphs - 1] = fg;
  197. return 0;
  198. }
  199. static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
  200. {
  201. InputStream *ist = NULL;
  202. enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx);
  203. int i;
  204. // TODO: support other filter types
  205. if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
  206. av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "
  207. "currently.\n");
  208. exit_program(1);
  209. }
  210. if (in->name) {
  211. AVFormatContext *s;
  212. AVStream *st = NULL;
  213. char *p;
  214. int file_idx = strtol(in->name, &p, 0);
  215. if (file_idx < 0 || file_idx >= nb_input_files) {
  216. av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n",
  217. file_idx, fg->graph_desc);
  218. exit_program(1);
  219. }
  220. s = input_files[file_idx]->ctx;
  221. for (i = 0; i < s->nb_streams; i++) {
  222. enum AVMediaType stream_type = s->streams[i]->codecpar->codec_type;
  223. if (stream_type != type &&
  224. !(stream_type == AVMEDIA_TYPE_SUBTITLE &&
  225. type == AVMEDIA_TYPE_VIDEO /* sub2video hack */))
  226. continue;
  227. if (check_stream_specifier(s, s->streams[i], *p == ':' ? p + 1 : p) == 1) {
  228. st = s->streams[i];
  229. break;
  230. }
  231. }
  232. if (!st) {
  233. av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
  234. "matches no streams.\n", p, fg->graph_desc);
  235. exit_program(1);
  236. }
  237. ist = input_streams[input_files[file_idx]->ist_index + st->index];
  238. } else {
  239. /* find the first unused stream of corresponding type */
  240. for (i = 0; i < nb_input_streams; i++) {
  241. ist = input_streams[i];
  242. if (ist->dec_ctx->codec_type == type && ist->discard)
  243. break;
  244. }
  245. if (i == nb_input_streams) {
  246. av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "
  247. "unlabeled input pad %d on filter %s\n", in->pad_idx,
  248. in->filter_ctx->name);
  249. exit_program(1);
  250. }
  251. }
  252. av_assert0(ist);
  253. ist->discard = 0;
  254. ist->decoding_needed |= DECODING_FOR_FILTER;
  255. ist->st->discard = AVDISCARD_NONE;
  256. GROW_ARRAY(fg->inputs, fg->nb_inputs);
  257. if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0]))))
  258. exit_program(1);
  259. fg->inputs[fg->nb_inputs - 1]->ist = ist;
  260. fg->inputs[fg->nb_inputs - 1]->graph = fg;
  261. fg->inputs[fg->nb_inputs - 1]->format = -1;
  262. GROW_ARRAY(ist->filters, ist->nb_filters);
  263. ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];
  264. }
  265. int init_complex_filtergraph(FilterGraph *fg)
  266. {
  267. AVFilterInOut *inputs, *outputs, *cur;
  268. AVFilterGraph *graph;
  269. int ret = 0;
  270. /* this graph is only used for determining the kinds of inputs
  271. * and outputs we have, and is discarded on exit from this function */
  272. graph = avfilter_graph_alloc();
  273. if (!graph)
  274. return AVERROR(ENOMEM);
  275. ret = avfilter_graph_parse2(graph, fg->graph_desc, &inputs, &outputs);
  276. if (ret < 0)
  277. goto fail;
  278. for (cur = inputs; cur; cur = cur->next)
  279. init_input_filter(fg, cur);
  280. for (cur = outputs; cur;) {
  281. GROW_ARRAY(fg->outputs, fg->nb_outputs);
  282. fg->outputs[fg->nb_outputs - 1] = av_mallocz(sizeof(*fg->outputs[0]));
  283. if (!fg->outputs[fg->nb_outputs - 1])
  284. exit_program(1);
  285. fg->outputs[fg->nb_outputs - 1]->graph = fg;
  286. fg->outputs[fg->nb_outputs - 1]->out_tmp = cur;
  287. fg->outputs[fg->nb_outputs - 1]->type = avfilter_pad_get_type(cur->filter_ctx->output_pads,
  288. cur->pad_idx);
  289. cur = cur->next;
  290. fg->outputs[fg->nb_outputs - 1]->out_tmp->next = NULL;
  291. }
  292. fail:
  293. avfilter_inout_free(&inputs);
  294. avfilter_graph_free(&graph);
  295. return ret;
  296. }
  297. static int insert_trim(int64_t start_time, int64_t duration,
  298. AVFilterContext **last_filter, int *pad_idx,
  299. const char *filter_name)
  300. {
  301. AVFilterGraph *graph = (*last_filter)->graph;
  302. AVFilterContext *ctx;
  303. const AVFilter *trim;
  304. enum AVMediaType type = avfilter_pad_get_type((*last_filter)->output_pads, *pad_idx);
  305. const char *name = (type == AVMEDIA_TYPE_VIDEO) ? "trim" : "atrim";
  306. int ret = 0;
  307. if (duration == INT64_MAX && start_time == AV_NOPTS_VALUE)
  308. return 0;
  309. trim = avfilter_get_by_name(name);
  310. if (!trim) {
  311. av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "
  312. "recording time.\n", name);
  313. return AVERROR_FILTER_NOT_FOUND;
  314. }
  315. ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
  316. if (!ctx)
  317. return AVERROR(ENOMEM);
  318. if (duration != INT64_MAX) {
  319. ret = av_opt_set_int(ctx, "durationi", duration,
  320. AV_OPT_SEARCH_CHILDREN);
  321. }
  322. if (ret >= 0 && start_time != AV_NOPTS_VALUE) {
  323. ret = av_opt_set_int(ctx, "starti", start_time,
  324. AV_OPT_SEARCH_CHILDREN);
  325. }
  326. if (ret < 0) {
  327. av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
  328. return ret;
  329. }
  330. ret = avfilter_init_str(ctx, NULL);
  331. if (ret < 0)
  332. return ret;
  333. ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
  334. if (ret < 0)
  335. return ret;
  336. *last_filter = ctx;
  337. *pad_idx = 0;
  338. return 0;
  339. }
  340. static int insert_filter(AVFilterContext **last_filter, int *pad_idx,
  341. const char *filter_name, const char *args)
  342. {
  343. AVFilterGraph *graph = (*last_filter)->graph;
  344. AVFilterContext *ctx;
  345. int ret;
  346. ret = avfilter_graph_create_filter(&ctx,
  347. avfilter_get_by_name(filter_name),
  348. filter_name, args, NULL, graph);
  349. if (ret < 0)
  350. return ret;
  351. ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
  352. if (ret < 0)
  353. return ret;
  354. *last_filter = ctx;
  355. *pad_idx = 0;
  356. return 0;
  357. }
  358. static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
  359. {
  360. char *pix_fmts;
  361. OutputStream *ost = ofilter->ost;
  362. OutputFile *of = output_files[ost->file_index];
  363. AVCodecContext *codec = ost->enc_ctx;
  364. AVFilterContext *last_filter = out->filter_ctx;
  365. int pad_idx = out->pad_idx;
  366. int ret;
  367. char name[255];
  368. snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);
  369. ret = avfilter_graph_create_filter(&ofilter->filter,
  370. avfilter_get_by_name("buffersink"),
  371. name, NULL, NULL, fg->graph);
  372. if (ret < 0)
  373. return ret;
  374. if (!hw_device_ctx && (codec->width || codec->height)) {
  375. char args[255];
  376. AVFilterContext *filter;
  377. AVDictionaryEntry *e = NULL;
  378. snprintf(args, sizeof(args), "%d:%d",
  379. codec->width,
  380. codec->height);
  381. while ((e = av_dict_get(ost->sws_dict, "", e,
  382. AV_DICT_IGNORE_SUFFIX))) {
  383. av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value);
  384. }
  385. snprintf(name, sizeof(name), "scaler for output stream %d:%d",
  386. ost->file_index, ost->index);
  387. if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
  388. name, args, NULL, fg->graph)) < 0)
  389. return ret;
  390. if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
  391. return ret;
  392. last_filter = filter;
  393. pad_idx = 0;
  394. }
  395. if ((pix_fmts = choose_pix_fmts(ost))) {
  396. AVFilterContext *filter;
  397. snprintf(name, sizeof(name), "pixel format for output stream %d:%d",
  398. ost->file_index, ost->index);
  399. ret = avfilter_graph_create_filter(&filter,
  400. avfilter_get_by_name("format"),
  401. "format", pix_fmts, NULL, fg->graph);
  402. av_freep(&pix_fmts);
  403. if (ret < 0)
  404. return ret;
  405. if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
  406. return ret;
  407. last_filter = filter;
  408. pad_idx = 0;
  409. }
  410. if (ost->frame_rate.num && 0) {
  411. AVFilterContext *fps;
  412. char args[255];
  413. snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,
  414. ost->frame_rate.den);
  415. snprintf(name, sizeof(name), "fps for output stream %d:%d",
  416. ost->file_index, ost->index);
  417. ret = avfilter_graph_create_filter(&fps, avfilter_get_by_name("fps"),
  418. name, args, NULL, fg->graph);
  419. if (ret < 0)
  420. return ret;
  421. ret = avfilter_link(last_filter, pad_idx, fps, 0);
  422. if (ret < 0)
  423. return ret;
  424. last_filter = fps;
  425. pad_idx = 0;
  426. }
  427. snprintf(name, sizeof(name), "trim for output stream %d:%d",
  428. ost->file_index, ost->index);
  429. ret = insert_trim(of->start_time, of->recording_time,
  430. &last_filter, &pad_idx, name);
  431. if (ret < 0)
  432. return ret;
  433. if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
  434. return ret;
  435. return 0;
  436. }
  437. static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
  438. {
  439. OutputStream *ost = ofilter->ost;
  440. OutputFile *of = output_files[ost->file_index];
  441. AVCodecContext *codec = ost->enc_ctx;
  442. AVFilterContext *last_filter = out->filter_ctx;
  443. int pad_idx = out->pad_idx;
  444. char *sample_fmts, *sample_rates, *channel_layouts;
  445. char name[255];
  446. int ret;
  447. snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);
  448. ret = avfilter_graph_create_filter(&ofilter->filter,
  449. avfilter_get_by_name("abuffersink"),
  450. name, NULL, NULL, fg->graph);
  451. if (ret < 0)
  452. return ret;
  453. if ((ret = av_opt_set_int(ofilter->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0)
  454. return ret;
  455. #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
  456. AVFilterContext *filt_ctx; \
  457. \
  458. av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
  459. "similarly to -af " filter_name "=%s.\n", arg); \
  460. \
  461. ret = avfilter_graph_create_filter(&filt_ctx, \
  462. avfilter_get_by_name(filter_name), \
  463. filter_name, arg, NULL, fg->graph); \
  464. if (ret < 0) \
  465. return ret; \
  466. \
  467. ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
  468. if (ret < 0) \
  469. return ret; \
  470. \
  471. last_filter = filt_ctx; \
  472. pad_idx = 0; \
  473. } while (0)
  474. if (ost->audio_channels_mapped) {
  475. int i;
  476. AVBPrint pan_buf;
  477. av_bprint_init(&pan_buf, 256, 8192);
  478. av_bprintf(&pan_buf, "0x%"PRIx64,
  479. av_get_default_channel_layout(ost->audio_channels_mapped));
  480. for (i = 0; i < ost->audio_channels_mapped; i++)
  481. if (ost->audio_channels_map[i] != -1)
  482. av_bprintf(&pan_buf, "|c%d=c%d", i, ost->audio_channels_map[i]);
  483. AUTO_INSERT_FILTER("-map_channel", "pan", pan_buf.str);
  484. av_bprint_finalize(&pan_buf, NULL);
  485. }
  486. if (codec->channels && !codec->channel_layout)
  487. codec->channel_layout = av_get_default_channel_layout(codec->channels);
  488. sample_fmts = choose_sample_fmts(ost);
  489. sample_rates = choose_sample_rates(ost);
  490. channel_layouts = choose_channel_layouts(ost);
  491. if (sample_fmts || sample_rates || channel_layouts) {
  492. AVFilterContext *format;
  493. char args[256];
  494. args[0] = 0;
  495. if (sample_fmts)
  496. av_strlcatf(args, sizeof(args), "sample_fmts=%s:",
  497. sample_fmts);
  498. if (sample_rates)
  499. av_strlcatf(args, sizeof(args), "sample_rates=%s:",
  500. sample_rates);
  501. if (channel_layouts)
  502. av_strlcatf(args, sizeof(args), "channel_layouts=%s:",
  503. channel_layouts);
  504. av_freep(&sample_fmts);
  505. av_freep(&sample_rates);
  506. av_freep(&channel_layouts);
  507. snprintf(name, sizeof(name), "audio format for output stream %d:%d",
  508. ost->file_index, ost->index);
  509. ret = avfilter_graph_create_filter(&format,
  510. avfilter_get_by_name("aformat"),
  511. name, args, NULL, fg->graph);
  512. if (ret < 0)
  513. return ret;
  514. ret = avfilter_link(last_filter, pad_idx, format, 0);
  515. if (ret < 0)
  516. return ret;
  517. last_filter = format;
  518. pad_idx = 0;
  519. }
  520. if (audio_volume != 256 && 0) {
  521. char args[256];
  522. snprintf(args, sizeof(args), "%f", audio_volume / 256.);
  523. AUTO_INSERT_FILTER("-vol", "volume", args);
  524. }
  525. if (ost->apad && of->shortest) {
  526. char args[256];
  527. int i;
  528. for (i=0; i<of->ctx->nb_streams; i++)
  529. if (of->ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
  530. break;
  531. if (i<of->ctx->nb_streams) {
  532. snprintf(args, sizeof(args), "%s", ost->apad);
  533. AUTO_INSERT_FILTER("-apad", "apad", args);
  534. }
  535. }
  536. snprintf(name, sizeof(name), "trim for output stream %d:%d",
  537. ost->file_index, ost->index);
  538. ret = insert_trim(of->start_time, of->recording_time,
  539. &last_filter, &pad_idx, name);
  540. if (ret < 0)
  541. return ret;
  542. if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
  543. return ret;
  544. return 0;
  545. }
  546. #define DESCRIBE_FILTER_LINK(f, inout, in) \
  547. { \
  548. AVFilterContext *ctx = inout->filter_ctx; \
  549. AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; \
  550. int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs; \
  551. AVIOContext *pb; \
  552. \
  553. if (avio_open_dyn_buf(&pb) < 0) \
  554. exit_program(1); \
  555. \
  556. avio_printf(pb, "%s", ctx->filter->name); \
  557. if (nb_pads > 1) \
  558. avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));\
  559. avio_w8(pb, 0); \
  560. avio_close_dyn_buf(pb, &f->name); \
  561. }
  562. int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
  563. {
  564. av_freep(&ofilter->name);
  565. DESCRIBE_FILTER_LINK(ofilter, out, 0);
  566. if (!ofilter->ost) {
  567. av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", ofilter->name);
  568. exit_program(1);
  569. }
  570. switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
  571. case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, ofilter, out);
  572. case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, ofilter, out);
  573. default: av_assert0(0);
  574. }
  575. }
  576. static int sub2video_prepare(InputStream *ist, InputFilter *ifilter)
  577. {
  578. AVFormatContext *avf = input_files[ist->file_index]->ctx;
  579. int i, w, h;
  580. /* Compute the size of the canvas for the subtitles stream.
  581. If the subtitles codecpar has set a size, use it. Otherwise use the
  582. maximum dimensions of the video streams in the same file. */
  583. w = ifilter->width;
  584. h = ifilter->height;
  585. if (!(w && h)) {
  586. for (i = 0; i < avf->nb_streams; i++) {
  587. if (avf->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
  588. w = FFMAX(w, avf->streams[i]->codecpar->width);
  589. h = FFMAX(h, avf->streams[i]->codecpar->height);
  590. }
  591. }
  592. if (!(w && h)) {
  593. w = FFMAX(w, 720);
  594. h = FFMAX(h, 576);
  595. }
  596. av_log(avf, AV_LOG_INFO, "sub2video: using %dx%d canvas\n", w, h);
  597. }
  598. ist->sub2video.w = ist->resample_width = ifilter->width = w;
  599. ist->sub2video.h = ist->resample_height = ifilter->height = h;
  600. /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the
  601. palettes for all rectangles are identical or compatible */
  602. ist->resample_pix_fmt = ifilter->format = AV_PIX_FMT_RGB32;
  603. ist->sub2video.frame = av_frame_alloc();
  604. if (!ist->sub2video.frame)
  605. return AVERROR(ENOMEM);
  606. ist->sub2video.last_pts = INT64_MIN;
  607. return 0;
  608. }
  609. static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
  610. AVFilterInOut *in)
  611. {
  612. AVFilterContext *last_filter;
  613. const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
  614. InputStream *ist = ifilter->ist;
  615. InputFile *f = input_files[ist->file_index];
  616. AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :
  617. ist->st->time_base;
  618. AVRational fr = ist->framerate;
  619. AVRational sar;
  620. AVBPrint args;
  621. char name[255];
  622. int ret, pad_idx = 0;
  623. int64_t tsoffset = 0;
  624. AVBufferSrcParameters *par = av_buffersrc_parameters_alloc();
  625. if (!par)
  626. return AVERROR(ENOMEM);
  627. memset(par, 0, sizeof(*par));
  628. par->format = AV_PIX_FMT_NONE;
  629. if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
  630. av_log(NULL, AV_LOG_ERROR, "Cannot connect video filter to audio input\n");
  631. ret = AVERROR(EINVAL);
  632. goto fail;
  633. }
  634. if (!fr.num)
  635. fr = av_guess_frame_rate(input_files[ist->file_index]->ctx, ist->st, NULL);
  636. if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
  637. ret = sub2video_prepare(ist, ifilter);
  638. if (ret < 0)
  639. goto fail;
  640. }
  641. sar = ifilter->sample_aspect_ratio;
  642. if(!sar.den)
  643. sar = (AVRational){0,1};
  644. av_bprint_init(&args, 0, 1);
  645. av_bprintf(&args,
  646. "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
  647. "pixel_aspect=%d/%d:sws_param=flags=%d",
  648. ifilter->width, ifilter->height, ifilter->format,
  649. tb.num, tb.den, sar.num, sar.den,
  650. SWS_BILINEAR + ((ist->dec_ctx->flags&AV_CODEC_FLAG_BITEXACT) ? SWS_BITEXACT:0));
  651. if (fr.num && fr.den)
  652. av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den);
  653. snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
  654. ist->file_index, ist->st->index);
  655. if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name,
  656. args.str, NULL, fg->graph)) < 0)
  657. goto fail;
  658. par->hw_frames_ctx = ifilter->hw_frames_ctx;
  659. ret = av_buffersrc_parameters_set(ifilter->filter, par);
  660. if (ret < 0)
  661. goto fail;
  662. av_freep(&par);
  663. last_filter = ifilter->filter;
  664. if (ist->autorotate) {
  665. double theta = get_rotation(ist->st);
  666. if (fabs(theta - 90) < 1.0) {
  667. ret = insert_filter(&last_filter, &pad_idx, "transpose", "clock");
  668. } else if (fabs(theta - 180) < 1.0) {
  669. ret = insert_filter(&last_filter, &pad_idx, "hflip", NULL);
  670. if (ret < 0)
  671. return ret;
  672. ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
  673. } else if (fabs(theta - 270) < 1.0) {
  674. ret = insert_filter(&last_filter, &pad_idx, "transpose", "cclock");
  675. } else if (fabs(theta) > 1.0) {
  676. char rotate_buf[64];
  677. snprintf(rotate_buf, sizeof(rotate_buf), "%f*PI/180", theta);
  678. ret = insert_filter(&last_filter, &pad_idx, "rotate", rotate_buf);
  679. }
  680. if (ret < 0)
  681. return ret;
  682. }
  683. if (ist->framerate.num) {
  684. AVFilterContext *setpts;
  685. snprintf(name, sizeof(name), "force CFR for input from stream %d:%d",
  686. ist->file_index, ist->st->index);
  687. if ((ret = avfilter_graph_create_filter(&setpts,
  688. avfilter_get_by_name("setpts"),
  689. name, "N", NULL,
  690. fg->graph)) < 0)
  691. return ret;
  692. if ((ret = avfilter_link(last_filter, 0, setpts, 0)) < 0)
  693. return ret;
  694. last_filter = setpts;
  695. }
  696. if (do_deinterlace) {
  697. AVFilterContext *yadif;
  698. snprintf(name, sizeof(name), "deinterlace input from stream %d:%d",
  699. ist->file_index, ist->st->index);
  700. if ((ret = avfilter_graph_create_filter(&yadif,
  701. avfilter_get_by_name("yadif"),
  702. name, "", NULL,
  703. fg->graph)) < 0)
  704. return ret;
  705. if ((ret = avfilter_link(last_filter, 0, yadif, 0)) < 0)
  706. return ret;
  707. last_filter = yadif;
  708. }
  709. snprintf(name, sizeof(name), "trim for input stream %d:%d",
  710. ist->file_index, ist->st->index);
  711. if (copy_ts) {
  712. tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
  713. if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
  714. tsoffset += f->ctx->start_time;
  715. }
  716. ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
  717. AV_NOPTS_VALUE : tsoffset, f->recording_time,
  718. &last_filter, &pad_idx, name);
  719. if (ret < 0)
  720. return ret;
  721. if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
  722. return ret;
  723. return 0;
  724. fail:
  725. av_freep(&par);
  726. return ret;
  727. }
  728. static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter,
  729. AVFilterInOut *in)
  730. {
  731. AVFilterContext *last_filter;
  732. const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
  733. InputStream *ist = ifilter->ist;
  734. InputFile *f = input_files[ist->file_index];
  735. AVBPrint args;
  736. char name[255];
  737. int ret, pad_idx = 0;
  738. int64_t tsoffset = 0;
  739. if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_AUDIO) {
  740. av_log(NULL, AV_LOG_ERROR, "Cannot connect audio filter to non audio input\n");
  741. return AVERROR(EINVAL);
  742. }
  743. av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC);
  744. av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
  745. 1, ifilter->sample_rate,
  746. ifilter->sample_rate,
  747. av_get_sample_fmt_name(ifilter->format));
  748. if (ifilter->channel_layout)
  749. av_bprintf(&args, ":channel_layout=0x%"PRIx64,
  750. ifilter->channel_layout);
  751. else
  752. av_bprintf(&args, ":channels=%d", ifilter->channels);
  753. snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
  754. ist->file_index, ist->st->index);
  755. if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt,
  756. name, args.str, NULL,
  757. fg->graph)) < 0)
  758. return ret;
  759. last_filter = ifilter->filter;
  760. #define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg) do { \
  761. AVFilterContext *filt_ctx; \
  762. \
  763. av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
  764. "similarly to -af " filter_name "=%s.\n", arg); \
  765. \
  766. snprintf(name, sizeof(name), "graph %d %s for input stream %d:%d", \
  767. fg->index, filter_name, ist->file_index, ist->st->index); \
  768. ret = avfilter_graph_create_filter(&filt_ctx, \
  769. avfilter_get_by_name(filter_name), \
  770. name, arg, NULL, fg->graph); \
  771. if (ret < 0) \
  772. return ret; \
  773. \
  774. ret = avfilter_link(last_filter, 0, filt_ctx, 0); \
  775. if (ret < 0) \
  776. return ret; \
  777. \
  778. last_filter = filt_ctx; \
  779. } while (0)
  780. if (audio_sync_method > 0) {
  781. char args[256] = {0};
  782. av_strlcatf(args, sizeof(args), "async=%d", audio_sync_method);
  783. if (audio_drift_threshold != 0.1)
  784. av_strlcatf(args, sizeof(args), ":min_hard_comp=%f", audio_drift_threshold);
  785. if (!fg->reconfiguration)
  786. av_strlcatf(args, sizeof(args), ":first_pts=0");
  787. AUTO_INSERT_FILTER_INPUT("-async", "aresample", args);
  788. }
  789. // if (ost->audio_channels_mapped) {
  790. // int i;
  791. // AVBPrint pan_buf;
  792. // av_bprint_init(&pan_buf, 256, 8192);
  793. // av_bprintf(&pan_buf, "0x%"PRIx64,
  794. // av_get_default_channel_layout(ost->audio_channels_mapped));
  795. // for (i = 0; i < ost->audio_channels_mapped; i++)
  796. // if (ost->audio_channels_map[i] != -1)
  797. // av_bprintf(&pan_buf, ":c%d=c%d", i, ost->audio_channels_map[i]);
  798. // AUTO_INSERT_FILTER_INPUT("-map_channel", "pan", pan_buf.str);
  799. // av_bprint_finalize(&pan_buf, NULL);
  800. // }
  801. if (audio_volume != 256) {
  802. char args[256];
  803. av_log(NULL, AV_LOG_WARNING, "-vol has been deprecated. Use the volume "
  804. "audio filter instead.\n");
  805. snprintf(args, sizeof(args), "%f", audio_volume / 256.);
  806. AUTO_INSERT_FILTER_INPUT("-vol", "volume", args);
  807. }
  808. snprintf(name, sizeof(name), "trim for input stream %d:%d",
  809. ist->file_index, ist->st->index);
  810. if (copy_ts) {
  811. tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
  812. if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
  813. tsoffset += f->ctx->start_time;
  814. }
  815. ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
  816. AV_NOPTS_VALUE : tsoffset, f->recording_time,
  817. &last_filter, &pad_idx, name);
  818. if (ret < 0)
  819. return ret;
  820. if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
  821. return ret;
  822. return 0;
  823. }
  824. static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter,
  825. AVFilterInOut *in)
  826. {
  827. av_freep(&ifilter->name);
  828. DESCRIBE_FILTER_LINK(ifilter, in, 1);
  829. if (!ifilter->ist->dec) {
  830. av_log(NULL, AV_LOG_ERROR,
  831. "No decoder for stream #%d:%d, filtering impossible\n",
  832. ifilter->ist->file_index, ifilter->ist->st->index);
  833. return AVERROR_DECODER_NOT_FOUND;
  834. }
  835. switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) {
  836. case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in);
  837. case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in);
  838. default: av_assert0(0);
  839. }
  840. }
  841. int configure_filtergraph(FilterGraph *fg)
  842. {
  843. AVFilterInOut *inputs, *outputs, *cur;
  844. int ret, i, simple = filtergraph_is_simple(fg);
  845. const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
  846. fg->graph_desc;
  847. avfilter_graph_free(&fg->graph);
  848. if (!(fg->graph = avfilter_graph_alloc()))
  849. return AVERROR(ENOMEM);
  850. if (simple) {
  851. OutputStream *ost = fg->outputs[0]->ost;
  852. char args[512];
  853. AVDictionaryEntry *e = NULL;
  854. args[0] = 0;
  855. while ((e = av_dict_get(ost->sws_dict, "", e,
  856. AV_DICT_IGNORE_SUFFIX))) {
  857. av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
  858. }
  859. if (strlen(args))
  860. args[strlen(args)-1] = 0;
  861. fg->graph->scale_sws_opts = av_strdup(args);
  862. args[0] = 0;
  863. while ((e = av_dict_get(ost->swr_opts, "", e,
  864. AV_DICT_IGNORE_SUFFIX))) {
  865. av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
  866. }
  867. if (strlen(args))
  868. args[strlen(args)-1] = 0;
  869. av_opt_set(fg->graph, "aresample_swr_opts", args, 0);
  870. args[0] = '\0';
  871. while ((e = av_dict_get(fg->outputs[0]->ost->resample_opts, "", e,
  872. AV_DICT_IGNORE_SUFFIX))) {
  873. av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
  874. }
  875. if (strlen(args))
  876. args[strlen(args) - 1] = '\0';
  877. fg->graph->resample_lavr_opts = av_strdup(args);
  878. e = av_dict_get(ost->encoder_opts, "threads", NULL, 0);
  879. if (e)
  880. av_opt_set(fg->graph, "threads", e->value, 0);
  881. }
  882. if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
  883. return ret;
  884. if (hw_device_ctx) {
  885. for (i = 0; i < fg->graph->nb_filters; i++) {
  886. fg->graph->filters[i]->hw_device_ctx = av_buffer_ref(hw_device_ctx);
  887. }
  888. }
  889. if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {
  890. const char *num_inputs;
  891. const char *num_outputs;
  892. if (!outputs) {
  893. num_outputs = "0";
  894. } else if (outputs->next) {
  895. num_outputs = ">1";
  896. } else {
  897. num_outputs = "1";
  898. }
  899. if (!inputs) {
  900. num_inputs = "0";
  901. } else if (inputs->next) {
  902. num_inputs = ">1";
  903. } else {
  904. num_inputs = "1";
  905. }
  906. av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' was expected "
  907. "to have exactly 1 input and 1 output."
  908. " However, it had %s input(s) and %s output(s)."
  909. " Please adjust, or use a complex filtergraph (-filter_complex) instead.\n",
  910. graph_desc, num_inputs, num_outputs);
  911. return AVERROR(EINVAL);
  912. }
  913. for (cur = inputs, i = 0; cur; cur = cur->next, i++)
  914. if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0) {
  915. avfilter_inout_free(&inputs);
  916. avfilter_inout_free(&outputs);
  917. return ret;
  918. }
  919. avfilter_inout_free(&inputs);
  920. for (cur = outputs, i = 0; cur; cur = cur->next, i++)
  921. configure_output_filter(fg, fg->outputs[i], cur);
  922. avfilter_inout_free(&outputs);
  923. if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
  924. return ret;
  925. fg->reconfiguration = 1;
  926. for (i = 0; i < fg->nb_outputs; i++) {
  927. OutputStream *ost = fg->outputs[i]->ost;
  928. if (!ost->enc) {
  929. /* identical to the same check in ffmpeg.c, needed because
  930. complex filter graphs are initialized earlier */
  931. av_log(NULL, AV_LOG_ERROR, "Encoder (codec %s) not found for output stream #%d:%d\n",
  932. avcodec_get_name(ost->st->codecpar->codec_id), ost->file_index, ost->index);
  933. return AVERROR(EINVAL);
  934. }
  935. if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
  936. !(ost->enc->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
  937. av_buffersink_set_frame_size(ost->filter->filter,
  938. ost->enc_ctx->frame_size);
  939. }
  940. return 0;
  941. }
  942. int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
  943. {
  944. av_buffer_unref(&ifilter->hw_frames_ctx);
  945. ifilter->format = frame->format;
  946. ifilter->width = frame->width;
  947. ifilter->height = frame->height;
  948. ifilter->sample_aspect_ratio = frame->sample_aspect_ratio;
  949. ifilter->sample_rate = frame->sample_rate;
  950. ifilter->channels = av_frame_get_channels(frame);
  951. ifilter->channel_layout = frame->channel_layout;
  952. if (frame->hw_frames_ctx) {
  953. ifilter->hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
  954. if (!ifilter->hw_frames_ctx)
  955. return AVERROR(ENOMEM);
  956. }
  957. return 0;
  958. }
  959. int ifilter_parameters_from_decoder(InputFilter *ifilter, const AVCodecContext *avctx)
  960. {
  961. av_buffer_unref(&ifilter->hw_frames_ctx);
  962. if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
  963. ifilter->format = avctx->pix_fmt;
  964. else
  965. ifilter->format = avctx->sample_fmt;
  966. ifilter->width = avctx->width;
  967. ifilter->height = avctx->height;
  968. if (ifilter->ist && ifilter->ist->st && ifilter->ist->st->sample_aspect_ratio.num)
  969. ifilter->sample_aspect_ratio = ifilter->ist->st->sample_aspect_ratio;
  970. else
  971. ifilter->sample_aspect_ratio = avctx->sample_aspect_ratio;
  972. ifilter->sample_rate = avctx->sample_rate;
  973. ifilter->channels = avctx->channels;
  974. ifilter->channel_layout = avctx->channel_layout;
  975. if (avctx->hw_frames_ctx) {
  976. ifilter->hw_frames_ctx = av_buffer_ref(avctx->hw_frames_ctx);
  977. if (!ifilter->hw_frames_ctx)
  978. return AVERROR(ENOMEM);
  979. }
  980. return 0;
  981. }
  982. int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)
  983. {
  984. int i;
  985. for (i = 0; i < fg->nb_inputs; i++)
  986. if (fg->inputs[i]->ist == ist)
  987. return 1;
  988. return 0;
  989. }
  990. int filtergraph_is_simple(FilterGraph *fg)
  991. {
  992. return !fg->graph_desc;
  993. }