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.

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