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.

635 lines
23KB

  1. /*
  2. * avconv filter configuration
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "avconv.h"
  21. #include "libavfilter/avfilter.h"
  22. #include "libavresample/avresample.h"
  23. #include "libavutil/avassert.h"
  24. #include "libavutil/avstring.h"
  25. #include "libavutil/channel_layout.h"
  26. #include "libavutil/opt.h"
  27. #include "libavutil/pixdesc.h"
  28. #include "libavutil/pixfmt.h"
  29. #include "libavutil/samplefmt.h"
  30. /* Define a function for building a string containing a list of
  31. * allowed formats. */
  32. #define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name) \
  33. static char *choose_ ## var ## s(OutputStream *ost) \
  34. { \
  35. if (ost->st->codec->var != none) { \
  36. get_name(ost->st->codec->var); \
  37. return av_strdup(name); \
  38. } else if (ost->enc && ost->enc->supported_list) { \
  39. const type *p; \
  40. AVIOContext *s = NULL; \
  41. uint8_t *ret; \
  42. int len; \
  43. \
  44. if (avio_open_dyn_buf(&s) < 0) \
  45. exit(1); \
  46. \
  47. for (p = ost->enc->supported_list; *p != none; p++) { \
  48. get_name(*p); \
  49. avio_printf(s, "%s|", name); \
  50. } \
  51. len = avio_close_dyn_buf(s, &ret); \
  52. ret[len - 1] = 0; \
  53. return ret; \
  54. } else \
  55. return NULL; \
  56. }
  57. DEF_CHOOSE_FORMAT(enum AVPixelFormat, pix_fmt, pix_fmts, AV_PIX_FMT_NONE,
  58. GET_PIX_FMT_NAME)
  59. DEF_CHOOSE_FORMAT(enum AVSampleFormat, sample_fmt, sample_fmts,
  60. AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME)
  61. DEF_CHOOSE_FORMAT(int, sample_rate, supported_samplerates, 0,
  62. GET_SAMPLE_RATE_NAME)
  63. DEF_CHOOSE_FORMAT(uint64_t, channel_layout, channel_layouts, 0,
  64. GET_CH_LAYOUT_NAME)
  65. FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost)
  66. {
  67. FilterGraph *fg = av_mallocz(sizeof(*fg));
  68. if (!fg)
  69. exit(1);
  70. fg->index = nb_filtergraphs;
  71. GROW_ARRAY(fg->outputs, fg->nb_outputs);
  72. if (!(fg->outputs[0] = av_mallocz(sizeof(*fg->outputs[0]))))
  73. exit(1);
  74. fg->outputs[0]->ost = ost;
  75. fg->outputs[0]->graph = fg;
  76. ost->filter = fg->outputs[0];
  77. GROW_ARRAY(fg->inputs, fg->nb_inputs);
  78. if (!(fg->inputs[0] = av_mallocz(sizeof(*fg->inputs[0]))))
  79. exit(1);
  80. fg->inputs[0]->ist = ist;
  81. fg->inputs[0]->graph = fg;
  82. GROW_ARRAY(ist->filters, ist->nb_filters);
  83. ist->filters[ist->nb_filters - 1] = fg->inputs[0];
  84. GROW_ARRAY(filtergraphs, nb_filtergraphs);
  85. filtergraphs[nb_filtergraphs - 1] = fg;
  86. return fg;
  87. }
  88. static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
  89. {
  90. InputStream *ist = NULL;
  91. enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx);
  92. int i;
  93. // TODO: support other filter types
  94. if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
  95. av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "
  96. "currently.\n");
  97. exit(1);
  98. }
  99. if (in->name) {
  100. AVFormatContext *s;
  101. AVStream *st = NULL;
  102. char *p;
  103. int file_idx = strtol(in->name, &p, 0);
  104. if (file_idx < 0 || file_idx >= nb_input_files) {
  105. av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtegraph description %s.\n",
  106. file_idx, fg->graph_desc);
  107. exit(1);
  108. }
  109. s = input_files[file_idx]->ctx;
  110. for (i = 0; i < s->nb_streams; i++) {
  111. if (s->streams[i]->codec->codec_type != type)
  112. continue;
  113. if (check_stream_specifier(s, s->streams[i], *p == ':' ? p + 1 : p) == 1) {
  114. st = s->streams[i];
  115. break;
  116. }
  117. }
  118. if (!st) {
  119. av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
  120. "matches no streams.\n", p, fg->graph_desc);
  121. exit(1);
  122. }
  123. ist = input_streams[input_files[file_idx]->ist_index + st->index];
  124. } else {
  125. /* find the first unused stream of corresponding type */
  126. for (i = 0; i < nb_input_streams; i++) {
  127. ist = input_streams[i];
  128. if (ist->st->codec->codec_type == type && ist->discard)
  129. break;
  130. }
  131. if (i == nb_input_streams) {
  132. av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "
  133. "unlabeled input pad %d on filter %s", in->pad_idx,
  134. in->filter_ctx->name);
  135. exit(1);
  136. }
  137. }
  138. av_assert0(ist);
  139. ist->discard = 0;
  140. ist->decoding_needed = 1;
  141. ist->st->discard = AVDISCARD_NONE;
  142. GROW_ARRAY(fg->inputs, fg->nb_inputs);
  143. if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0]))))
  144. exit(1);
  145. fg->inputs[fg->nb_inputs - 1]->ist = ist;
  146. fg->inputs[fg->nb_inputs - 1]->graph = fg;
  147. GROW_ARRAY(ist->filters, ist->nb_filters);
  148. ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];
  149. }
  150. static int insert_trim(OutputStream *ost, AVFilterContext **last_filter, int *pad_idx)
  151. {
  152. OutputFile *of = output_files[ost->file_index];
  153. AVFilterGraph *graph = (*last_filter)->graph;
  154. AVFilterContext *ctx;
  155. const AVFilter *trim;
  156. const char *name = ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO ? "trim" : "atrim";
  157. char filter_name[128];
  158. int ret = 0;
  159. if (of->recording_time == INT64_MAX && !of->start_time)
  160. return 0;
  161. trim = avfilter_get_by_name(name);
  162. if (!trim) {
  163. av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "
  164. "recording time.\n", name);
  165. return AVERROR_FILTER_NOT_FOUND;
  166. }
  167. snprintf(filter_name, sizeof(filter_name), "%s for output stream %d:%d",
  168. name, ost->file_index, ost->index);
  169. ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
  170. if (!ctx)
  171. return AVERROR(ENOMEM);
  172. if (of->recording_time != INT64_MAX) {
  173. ret = av_opt_set_double(ctx, "duration", (double)of->recording_time / 1e6,
  174. AV_OPT_SEARCH_CHILDREN);
  175. }
  176. if (ret >= 0 && of->start_time) {
  177. ret = av_opt_set_double(ctx, "start", (double)of->start_time / 1e6,
  178. AV_OPT_SEARCH_CHILDREN);
  179. }
  180. if (ret < 0) {
  181. av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
  182. return ret;
  183. }
  184. ret = avfilter_init_str(ctx, NULL);
  185. if (ret < 0)
  186. return ret;
  187. ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
  188. if (ret < 0)
  189. return ret;
  190. *last_filter = ctx;
  191. *pad_idx = 0;
  192. return 0;
  193. }
  194. static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
  195. {
  196. char *pix_fmts;
  197. OutputStream *ost = ofilter->ost;
  198. AVCodecContext *codec = ost->st->codec;
  199. AVFilterContext *last_filter = out->filter_ctx;
  200. int pad_idx = out->pad_idx;
  201. int ret;
  202. char name[255];
  203. snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);
  204. ret = avfilter_graph_create_filter(&ofilter->filter,
  205. avfilter_get_by_name("buffersink"),
  206. name, NULL, NULL, fg->graph);
  207. if (ret < 0)
  208. return ret;
  209. if (codec->width || codec->height) {
  210. char args[255];
  211. AVFilterContext *filter;
  212. snprintf(args, sizeof(args), "%d:%d:0x%X",
  213. codec->width,
  214. codec->height,
  215. (unsigned)ost->sws_flags);
  216. snprintf(name, sizeof(name), "scaler for output stream %d:%d",
  217. ost->file_index, ost->index);
  218. if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
  219. name, args, NULL, fg->graph)) < 0)
  220. return ret;
  221. if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
  222. return ret;
  223. last_filter = filter;
  224. pad_idx = 0;
  225. }
  226. if ((pix_fmts = choose_pix_fmts(ost))) {
  227. AVFilterContext *filter;
  228. snprintf(name, sizeof(name), "pixel format for output stream %d:%d",
  229. ost->file_index, ost->index);
  230. if ((ret = avfilter_graph_create_filter(&filter,
  231. avfilter_get_by_name("format"),
  232. "format", pix_fmts, NULL,
  233. fg->graph)) < 0)
  234. return ret;
  235. if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
  236. return ret;
  237. last_filter = filter;
  238. pad_idx = 0;
  239. av_freep(&pix_fmts);
  240. }
  241. if (ost->frame_rate.num) {
  242. AVFilterContext *fps;
  243. char args[255];
  244. snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,
  245. ost->frame_rate.den);
  246. snprintf(name, sizeof(name), "fps for output stream %d:%d",
  247. ost->file_index, ost->index);
  248. ret = avfilter_graph_create_filter(&fps, avfilter_get_by_name("fps"),
  249. name, args, NULL, fg->graph);
  250. if (ret < 0)
  251. return ret;
  252. ret = avfilter_link(last_filter, pad_idx, fps, 0);
  253. if (ret < 0)
  254. return ret;
  255. last_filter = fps;
  256. pad_idx = 0;
  257. }
  258. ret = insert_trim(ost, &last_filter, &pad_idx);
  259. if (ret < 0)
  260. return ret;
  261. if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
  262. return ret;
  263. return 0;
  264. }
  265. static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
  266. {
  267. OutputStream *ost = ofilter->ost;
  268. AVCodecContext *codec = ost->st->codec;
  269. AVFilterContext *last_filter = out->filter_ctx;
  270. int pad_idx = out->pad_idx;
  271. char *sample_fmts, *sample_rates, *channel_layouts;
  272. char name[255];
  273. int ret;
  274. snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);
  275. ret = avfilter_graph_create_filter(&ofilter->filter,
  276. avfilter_get_by_name("abuffersink"),
  277. name, NULL, NULL, fg->graph);
  278. if (ret < 0)
  279. return ret;
  280. if (codec->channels && !codec->channel_layout)
  281. codec->channel_layout = av_get_default_channel_layout(codec->channels);
  282. sample_fmts = choose_sample_fmts(ost);
  283. sample_rates = choose_sample_rates(ost);
  284. channel_layouts = choose_channel_layouts(ost);
  285. if (sample_fmts || sample_rates || channel_layouts) {
  286. AVFilterContext *format;
  287. char args[256];
  288. int len = 0;
  289. if (sample_fmts)
  290. len += snprintf(args + len, sizeof(args) - len, "sample_fmts=%s:",
  291. sample_fmts);
  292. if (sample_rates)
  293. len += snprintf(args + len, sizeof(args) - len, "sample_rates=%s:",
  294. sample_rates);
  295. if (channel_layouts)
  296. len += snprintf(args + len, sizeof(args) - len, "channel_layouts=%s:",
  297. channel_layouts);
  298. args[len - 1] = 0;
  299. av_freep(&sample_fmts);
  300. av_freep(&sample_rates);
  301. av_freep(&channel_layouts);
  302. snprintf(name, sizeof(name), "audio format for output stream %d:%d",
  303. ost->file_index, ost->index);
  304. ret = avfilter_graph_create_filter(&format,
  305. avfilter_get_by_name("aformat"),
  306. name, args, NULL, fg->graph);
  307. if (ret < 0)
  308. return ret;
  309. ret = avfilter_link(last_filter, pad_idx, format, 0);
  310. if (ret < 0)
  311. return ret;
  312. last_filter = format;
  313. pad_idx = 0;
  314. }
  315. ret = insert_trim(ost, &last_filter, &pad_idx);
  316. if (ret < 0)
  317. return ret;
  318. if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
  319. return ret;
  320. return 0;
  321. }
  322. #define DESCRIBE_FILTER_LINK(f, inout, in) \
  323. { \
  324. AVFilterContext *ctx = inout->filter_ctx; \
  325. AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; \
  326. int nb_pads = in ? ctx->input_count : ctx->output_count; \
  327. AVIOContext *pb; \
  328. \
  329. if (avio_open_dyn_buf(&pb) < 0) \
  330. exit(1); \
  331. \
  332. avio_printf(pb, "%s", ctx->filter->name); \
  333. if (nb_pads > 1) \
  334. avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));\
  335. avio_w8(pb, 0); \
  336. avio_close_dyn_buf(pb, &f->name); \
  337. }
  338. int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
  339. {
  340. av_freep(&ofilter->name);
  341. DESCRIBE_FILTER_LINK(ofilter, out, 0);
  342. switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
  343. case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, ofilter, out);
  344. case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, ofilter, out);
  345. default: av_assert0(0);
  346. }
  347. }
  348. static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
  349. AVFilterInOut *in)
  350. {
  351. AVFilterContext *first_filter = in->filter_ctx;
  352. AVFilter *filter = avfilter_get_by_name("buffer");
  353. InputStream *ist = ifilter->ist;
  354. AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :
  355. ist->st->time_base;
  356. AVRational sar;
  357. char args[255], name[255];
  358. int pad_idx = in->pad_idx;
  359. int ret;
  360. sar = ist->st->sample_aspect_ratio.num ?
  361. ist->st->sample_aspect_ratio :
  362. ist->st->codec->sample_aspect_ratio;
  363. snprintf(args, sizeof(args), "%d:%d:%d:%d:%d:%d:%d", ist->st->codec->width,
  364. ist->st->codec->height, ist->st->codec->pix_fmt,
  365. tb.num, tb.den, sar.num, sar.den);
  366. snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
  367. ist->file_index, ist->st->index);
  368. if ((ret = avfilter_graph_create_filter(&ifilter->filter, filter, name,
  369. args, NULL, fg->graph)) < 0)
  370. return ret;
  371. if (ist->framerate.num) {
  372. AVFilterContext *setpts;
  373. snprintf(name, sizeof(name), "force CFR for input from stream %d:%d",
  374. ist->file_index, ist->st->index);
  375. if ((ret = avfilter_graph_create_filter(&setpts,
  376. avfilter_get_by_name("setpts"),
  377. name, "N", NULL,
  378. fg->graph)) < 0)
  379. return ret;
  380. if ((ret = avfilter_link(setpts, 0, first_filter, pad_idx)) < 0)
  381. return ret;
  382. first_filter = setpts;
  383. pad_idx = 0;
  384. }
  385. if ((ret = avfilter_link(ifilter->filter, 0, first_filter, pad_idx)) < 0)
  386. return ret;
  387. return 0;
  388. }
  389. static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter,
  390. AVFilterInOut *in)
  391. {
  392. AVFilterContext *first_filter = in->filter_ctx;
  393. AVFilter *filter = avfilter_get_by_name("abuffer");
  394. InputStream *ist = ifilter->ist;
  395. int pad_idx = in->pad_idx;
  396. char args[255], name[255];
  397. int ret;
  398. snprintf(args, sizeof(args), "time_base=%d/%d:sample_rate=%d:sample_fmt=%s"
  399. ":channel_layout=0x%"PRIx64,
  400. 1, ist->st->codec->sample_rate,
  401. ist->st->codec->sample_rate,
  402. av_get_sample_fmt_name(ist->st->codec->sample_fmt),
  403. ist->st->codec->channel_layout);
  404. snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
  405. ist->file_index, ist->st->index);
  406. if ((ret = avfilter_graph_create_filter(&ifilter->filter, filter,
  407. name, args, NULL,
  408. fg->graph)) < 0)
  409. return ret;
  410. if (audio_sync_method > 0) {
  411. AVFilterContext *async;
  412. int len = 0;
  413. av_log(NULL, AV_LOG_WARNING, "-async has been deprecated. Used the "
  414. "asyncts audio filter instead.\n");
  415. if (audio_sync_method > 1)
  416. len += snprintf(args + len, sizeof(args) - len, "compensate=1:"
  417. "max_comp=%d:", audio_sync_method);
  418. snprintf(args + len, sizeof(args) - len, "min_delta=%f",
  419. audio_drift_threshold);
  420. snprintf(name, sizeof(name), "graph %d audio sync for input stream %d:%d",
  421. fg->index, ist->file_index, ist->st->index);
  422. ret = avfilter_graph_create_filter(&async,
  423. avfilter_get_by_name("asyncts"),
  424. name, args, NULL, fg->graph);
  425. if (ret < 0)
  426. return ret;
  427. ret = avfilter_link(async, 0, first_filter, pad_idx);
  428. if (ret < 0)
  429. return ret;
  430. first_filter = async;
  431. pad_idx = 0;
  432. }
  433. if (audio_volume != 256) {
  434. AVFilterContext *volume;
  435. av_log(NULL, AV_LOG_WARNING, "-vol has been deprecated. Use the volume "
  436. "audio filter instead.\n");
  437. snprintf(args, sizeof(args), "volume=%f", audio_volume / 256.0);
  438. snprintf(name, sizeof(name), "graph %d volume for input stream %d:%d",
  439. fg->index, ist->file_index, ist->st->index);
  440. ret = avfilter_graph_create_filter(&volume,
  441. avfilter_get_by_name("volume"),
  442. name, args, NULL, fg->graph);
  443. if (ret < 0)
  444. return ret;
  445. ret = avfilter_link(volume, 0, first_filter, pad_idx);
  446. if (ret < 0)
  447. return ret;
  448. first_filter = volume;
  449. pad_idx = 0;
  450. }
  451. if ((ret = avfilter_link(ifilter->filter, 0, first_filter, pad_idx)) < 0)
  452. return ret;
  453. return 0;
  454. }
  455. static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter,
  456. AVFilterInOut *in)
  457. {
  458. av_freep(&ifilter->name);
  459. DESCRIBE_FILTER_LINK(ifilter, in, 1);
  460. switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) {
  461. case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in);
  462. case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in);
  463. default: av_assert0(0);
  464. }
  465. }
  466. int configure_filtergraph(FilterGraph *fg)
  467. {
  468. AVFilterInOut *inputs, *outputs, *cur;
  469. int ret, i, init = !fg->graph, simple = !fg->graph_desc;
  470. const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
  471. fg->graph_desc;
  472. avfilter_graph_free(&fg->graph);
  473. if (!(fg->graph = avfilter_graph_alloc()))
  474. return AVERROR(ENOMEM);
  475. if (simple) {
  476. OutputStream *ost = fg->outputs[0]->ost;
  477. char args[512];
  478. AVDictionaryEntry *e = NULL;
  479. snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
  480. fg->graph->scale_sws_opts = av_strdup(args);
  481. args[0] = '\0';
  482. while ((e = av_dict_get(fg->outputs[0]->ost->resample_opts, "", e,
  483. AV_DICT_IGNORE_SUFFIX))) {
  484. av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
  485. }
  486. if (strlen(args))
  487. args[strlen(args) - 1] = '\0';
  488. fg->graph->resample_lavr_opts = av_strdup(args);
  489. }
  490. if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
  491. return ret;
  492. if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {
  493. av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' does not have "
  494. "exactly one input and output.\n", graph_desc);
  495. return AVERROR(EINVAL);
  496. }
  497. for (cur = inputs; !simple && init && cur; cur = cur->next)
  498. init_input_filter(fg, cur);
  499. for (cur = inputs, i = 0; cur; cur = cur->next, i++)
  500. if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0)
  501. return ret;
  502. avfilter_inout_free(&inputs);
  503. if (!init || simple) {
  504. /* we already know the mappings between lavfi outputs and output streams,
  505. * so we can finish the setup */
  506. for (cur = outputs, i = 0; cur; cur = cur->next, i++)
  507. configure_output_filter(fg, fg->outputs[i], cur);
  508. avfilter_inout_free(&outputs);
  509. if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
  510. return ret;
  511. } else {
  512. /* wait until output mappings are processed */
  513. for (cur = outputs; cur;) {
  514. GROW_ARRAY(fg->outputs, fg->nb_outputs);
  515. if (!(fg->outputs[fg->nb_outputs - 1] = av_mallocz(sizeof(*fg->outputs[0]))))
  516. exit(1);
  517. fg->outputs[fg->nb_outputs - 1]->graph = fg;
  518. fg->outputs[fg->nb_outputs - 1]->out_tmp = cur;
  519. cur = cur->next;
  520. fg->outputs[fg->nb_outputs - 1]->out_tmp->next = NULL;
  521. }
  522. }
  523. return 0;
  524. }
  525. int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)
  526. {
  527. int i;
  528. for (i = 0; i < fg->nb_inputs; i++)
  529. if (fg->inputs[i]->ist == ist)
  530. return 1;
  531. return 0;
  532. }