src_movie.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /*
  2. * Copyright (c) 2010 Stefano Sabatini
  3. * Copyright (c) 2008 Victor Paesa
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * movie video source
  24. *
  25. * @todo use direct rendering (no allocation of a new frame)
  26. * @todo support a PTS correction mechanism
  27. */
  28. #include <float.h>
  29. #include <stdint.h>
  30. #include "libavutil/attributes.h"
  31. #include "libavutil/avstring.h"
  32. #include "libavutil/avassert.h"
  33. #include "libavutil/opt.h"
  34. #include "libavutil/imgutils.h"
  35. #include "libavutil/timestamp.h"
  36. #include "libavformat/avformat.h"
  37. #include "audio.h"
  38. #include "avcodec.h"
  39. #include "avfilter.h"
  40. #include "formats.h"
  41. #include "internal.h"
  42. #include "video.h"
  43. typedef struct MovieStream {
  44. AVStream *st;
  45. int done;
  46. } MovieStream;
  47. typedef struct MovieContext {
  48. /* common A/V fields */
  49. const AVClass *class;
  50. int64_t seek_point; ///< seekpoint in microseconds
  51. double seek_point_d;
  52. char *format_name;
  53. char *file_name;
  54. char *stream_specs; /**< user-provided list of streams, separated by + */
  55. int stream_index; /**< for compatibility */
  56. int loop_count;
  57. AVFormatContext *format_ctx;
  58. int eof;
  59. AVPacket pkt, pkt0;
  60. int max_stream_index; /**< max stream # actually used for output */
  61. MovieStream *st; /**< array of all streams, one per output */
  62. int *out_index; /**< stream number -> output number map, or -1 */
  63. } MovieContext;
  64. #define OFFSET(x) offsetof(MovieContext, x)
  65. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM
  66. static const AVOption movie_options[]= {
  67. { "filename", NULL, OFFSET(file_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
  68. { "format_name", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
  69. { "f", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
  70. { "stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
  71. { "si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
  72. { "seek_point", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, (INT64_MAX-1) / 1000000, FLAGS },
  73. { "sp", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, (INT64_MAX-1) / 1000000, FLAGS },
  74. { "streams", "set streams", OFFSET(stream_specs), AV_OPT_TYPE_STRING, {.str = 0}, CHAR_MAX, CHAR_MAX, FLAGS },
  75. { "s", "set streams", OFFSET(stream_specs), AV_OPT_TYPE_STRING, {.str = 0}, CHAR_MAX, CHAR_MAX, FLAGS },
  76. { "loop", "set loop count", OFFSET(loop_count), AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, FLAGS },
  77. { NULL },
  78. };
  79. static int movie_config_output_props(AVFilterLink *outlink);
  80. static int movie_request_frame(AVFilterLink *outlink);
  81. static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec)
  82. {
  83. int i, ret, already = 0, stream_id = -1;
  84. char type_char[2], dummy;
  85. AVStream *found = NULL;
  86. enum AVMediaType type;
  87. ret = sscanf(spec, "d%1[av]%d%c", type_char, &stream_id, &dummy);
  88. if (ret >= 1 && ret <= 2) {
  89. type = type_char[0] == 'v' ? AVMEDIA_TYPE_VIDEO : AVMEDIA_TYPE_AUDIO;
  90. ret = av_find_best_stream(avf, type, stream_id, -1, NULL, 0);
  91. if (ret < 0) {
  92. av_log(log, AV_LOG_ERROR, "No %s stream with index '%d' found\n",
  93. av_get_media_type_string(type), stream_id);
  94. return NULL;
  95. }
  96. return avf->streams[ret];
  97. }
  98. for (i = 0; i < avf->nb_streams; i++) {
  99. ret = avformat_match_stream_specifier(avf, avf->streams[i], spec);
  100. if (ret < 0) {
  101. av_log(log, AV_LOG_ERROR,
  102. "Invalid stream specifier \"%s\"\n", spec);
  103. return NULL;
  104. }
  105. if (!ret)
  106. continue;
  107. if (avf->streams[i]->discard != AVDISCARD_ALL) {
  108. already++;
  109. continue;
  110. }
  111. if (found) {
  112. av_log(log, AV_LOG_WARNING,
  113. "Ambiguous stream specifier \"%s\", using #%d\n", spec, i);
  114. break;
  115. }
  116. found = avf->streams[i];
  117. }
  118. if (!found) {
  119. av_log(log, AV_LOG_WARNING, "Stream specifier \"%s\" %s\n", spec,
  120. already ? "matched only already used streams" :
  121. "did not match any stream");
  122. return NULL;
  123. }
  124. if (found->codec->codec_type != AVMEDIA_TYPE_VIDEO &&
  125. found->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
  126. av_log(log, AV_LOG_ERROR, "Stream specifier \"%s\" matched a %s stream,"
  127. "currently unsupported by libavfilter\n", spec,
  128. av_get_media_type_string(found->codec->codec_type));
  129. return NULL;
  130. }
  131. return found;
  132. }
  133. static int open_stream(void *log, MovieStream *st)
  134. {
  135. AVCodec *codec;
  136. int ret;
  137. codec = avcodec_find_decoder(st->st->codec->codec_id);
  138. if (!codec) {
  139. av_log(log, AV_LOG_ERROR, "Failed to find any codec\n");
  140. return AVERROR(EINVAL);
  141. }
  142. st->st->codec->refcounted_frames = 1;
  143. if ((ret = avcodec_open2(st->st->codec, codec, NULL)) < 0) {
  144. av_log(log, AV_LOG_ERROR, "Failed to open codec\n");
  145. return ret;
  146. }
  147. return 0;
  148. }
  149. static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
  150. {
  151. AVCodecContext *dec_ctx = st->st->codec;
  152. char buf[256];
  153. int64_t chl = av_get_default_channel_layout(dec_ctx->channels);
  154. if (!chl) {
  155. av_log(log_ctx, AV_LOG_ERROR,
  156. "Channel layout is not set in stream %d, and could not "
  157. "be guessed from the number of channels (%d)\n",
  158. st_index, dec_ctx->channels);
  159. return AVERROR(EINVAL);
  160. }
  161. av_get_channel_layout_string(buf, sizeof(buf), dec_ctx->channels, chl);
  162. av_log(log_ctx, AV_LOG_WARNING,
  163. "Channel layout is not set in output stream %d, "
  164. "guessed channel layout is '%s'\n",
  165. st_index, buf);
  166. dec_ctx->channel_layout = chl;
  167. return 0;
  168. }
  169. static av_cold int movie_common_init(AVFilterContext *ctx)
  170. {
  171. MovieContext *movie = ctx->priv;
  172. AVInputFormat *iformat = NULL;
  173. int64_t timestamp;
  174. int nb_streams = 1, ret, i;
  175. char default_streams[16], *stream_specs, *spec, *cursor;
  176. char name[16];
  177. AVStream *st;
  178. if (!movie->file_name) {
  179. av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
  180. return AVERROR(EINVAL);
  181. }
  182. movie->seek_point = movie->seek_point_d * 1000000 + 0.5;
  183. stream_specs = movie->stream_specs;
  184. if (!stream_specs) {
  185. snprintf(default_streams, sizeof(default_streams), "d%c%d",
  186. !strcmp(ctx->filter->name, "amovie") ? 'a' : 'v',
  187. movie->stream_index);
  188. stream_specs = default_streams;
  189. }
  190. for (cursor = stream_specs; *cursor; cursor++)
  191. if (*cursor == '+')
  192. nb_streams++;
  193. if (movie->loop_count != 1 && nb_streams != 1) {
  194. av_log(ctx, AV_LOG_ERROR,
  195. "Loop with several streams is currently unsupported\n");
  196. return AVERROR_PATCHWELCOME;
  197. }
  198. av_register_all();
  199. // Try to find the movie format (container)
  200. iformat = movie->format_name ? av_find_input_format(movie->format_name) : NULL;
  201. movie->format_ctx = NULL;
  202. if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, NULL)) < 0) {
  203. av_log(ctx, AV_LOG_ERROR,
  204. "Failed to avformat_open_input '%s'\n", movie->file_name);
  205. return ret;
  206. }
  207. if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0)
  208. av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n");
  209. // if seeking requested, we execute it
  210. if (movie->seek_point > 0) {
  211. timestamp = movie->seek_point;
  212. // add the stream start time, should it exist
  213. if (movie->format_ctx->start_time != AV_NOPTS_VALUE) {
  214. if (timestamp > 0 && movie->format_ctx->start_time > INT64_MAX - timestamp) {
  215. av_log(ctx, AV_LOG_ERROR,
  216. "%s: seek value overflow with start_time:%"PRId64" seek_point:%"PRId64"\n",
  217. movie->file_name, movie->format_ctx->start_time, movie->seek_point);
  218. return AVERROR(EINVAL);
  219. }
  220. timestamp += movie->format_ctx->start_time;
  221. }
  222. if ((ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD)) < 0) {
  223. av_log(ctx, AV_LOG_ERROR, "%s: could not seek to position %"PRId64"\n",
  224. movie->file_name, timestamp);
  225. return ret;
  226. }
  227. }
  228. for (i = 0; i < movie->format_ctx->nb_streams; i++)
  229. movie->format_ctx->streams[i]->discard = AVDISCARD_ALL;
  230. movie->st = av_calloc(nb_streams, sizeof(*movie->st));
  231. if (!movie->st)
  232. return AVERROR(ENOMEM);
  233. for (i = 0; i < nb_streams; i++) {
  234. spec = av_strtok(stream_specs, "+", &cursor);
  235. if (!spec)
  236. return AVERROR_BUG;
  237. stream_specs = NULL; /* for next strtok */
  238. st = find_stream(ctx, movie->format_ctx, spec);
  239. if (!st)
  240. return AVERROR(EINVAL);
  241. st->discard = AVDISCARD_DEFAULT;
  242. movie->st[i].st = st;
  243. movie->max_stream_index = FFMAX(movie->max_stream_index, st->index);
  244. }
  245. if (av_strtok(NULL, "+", &cursor))
  246. return AVERROR_BUG;
  247. movie->out_index = av_calloc(movie->max_stream_index + 1,
  248. sizeof(*movie->out_index));
  249. if (!movie->out_index)
  250. return AVERROR(ENOMEM);
  251. for (i = 0; i <= movie->max_stream_index; i++)
  252. movie->out_index[i] = -1;
  253. for (i = 0; i < nb_streams; i++) {
  254. AVFilterPad pad = { 0 };
  255. movie->out_index[movie->st[i].st->index] = i;
  256. snprintf(name, sizeof(name), "out%d", i);
  257. pad.type = movie->st[i].st->codec->codec_type;
  258. pad.name = av_strdup(name);
  259. if (!pad.name)
  260. return AVERROR(ENOMEM);
  261. pad.config_props = movie_config_output_props;
  262. pad.request_frame = movie_request_frame;
  263. ff_insert_outpad(ctx, i, &pad);
  264. ret = open_stream(ctx, &movie->st[i]);
  265. if (ret < 0)
  266. return ret;
  267. if ( movie->st[i].st->codec->codec->type == AVMEDIA_TYPE_AUDIO &&
  268. !movie->st[i].st->codec->channel_layout) {
  269. ret = guess_channel_layout(&movie->st[i], i, ctx);
  270. if (ret < 0)
  271. return ret;
  272. }
  273. }
  274. av_log(ctx, AV_LOG_VERBOSE, "seek_point:%"PRIi64" format_name:%s file_name:%s stream_index:%d\n",
  275. movie->seek_point, movie->format_name, movie->file_name,
  276. movie->stream_index);
  277. return 0;
  278. }
  279. static av_cold void movie_uninit(AVFilterContext *ctx)
  280. {
  281. MovieContext *movie = ctx->priv;
  282. int i;
  283. for (i = 0; i < ctx->nb_outputs; i++) {
  284. av_freep(&ctx->output_pads[i].name);
  285. if (movie->st[i].st)
  286. avcodec_close(movie->st[i].st->codec);
  287. }
  288. av_freep(&movie->st);
  289. av_freep(&movie->out_index);
  290. if (movie->format_ctx)
  291. avformat_close_input(&movie->format_ctx);
  292. }
  293. static int movie_query_formats(AVFilterContext *ctx)
  294. {
  295. MovieContext *movie = ctx->priv;
  296. int list[] = { 0, -1 };
  297. int64_t list64[] = { 0, -1 };
  298. int i;
  299. for (i = 0; i < ctx->nb_outputs; i++) {
  300. MovieStream *st = &movie->st[i];
  301. AVCodecContext *c = st->st->codec;
  302. AVFilterLink *outlink = ctx->outputs[i];
  303. switch (c->codec_type) {
  304. case AVMEDIA_TYPE_VIDEO:
  305. list[0] = c->pix_fmt;
  306. ff_formats_ref(ff_make_format_list(list), &outlink->in_formats);
  307. break;
  308. case AVMEDIA_TYPE_AUDIO:
  309. list[0] = c->sample_fmt;
  310. ff_formats_ref(ff_make_format_list(list), &outlink->in_formats);
  311. list[0] = c->sample_rate;
  312. ff_formats_ref(ff_make_format_list(list), &outlink->in_samplerates);
  313. list64[0] = c->channel_layout;
  314. ff_channel_layouts_ref(avfilter_make_format64_list(list64),
  315. &outlink->in_channel_layouts);
  316. break;
  317. }
  318. }
  319. return 0;
  320. }
  321. static int movie_config_output_props(AVFilterLink *outlink)
  322. {
  323. AVFilterContext *ctx = outlink->src;
  324. MovieContext *movie = ctx->priv;
  325. unsigned out_id = FF_OUTLINK_IDX(outlink);
  326. MovieStream *st = &movie->st[out_id];
  327. AVCodecContext *c = st->st->codec;
  328. outlink->time_base = st->st->time_base;
  329. switch (c->codec_type) {
  330. case AVMEDIA_TYPE_VIDEO:
  331. outlink->w = c->width;
  332. outlink->h = c->height;
  333. outlink->frame_rate = st->st->r_frame_rate;
  334. break;
  335. case AVMEDIA_TYPE_AUDIO:
  336. break;
  337. }
  338. return 0;
  339. }
  340. static char *describe_frame_to_str(char *dst, size_t dst_size,
  341. AVFrame *frame, enum AVMediaType frame_type,
  342. AVFilterLink *link)
  343. {
  344. switch (frame_type) {
  345. case AVMEDIA_TYPE_VIDEO:
  346. snprintf(dst, dst_size,
  347. "video pts:%s time:%s size:%dx%d aspect:%d/%d",
  348. av_ts2str(frame->pts), av_ts2timestr(frame->pts, &link->time_base),
  349. frame->width, frame->height,
  350. frame->sample_aspect_ratio.num,
  351. frame->sample_aspect_ratio.den);
  352. break;
  353. case AVMEDIA_TYPE_AUDIO:
  354. snprintf(dst, dst_size,
  355. "audio pts:%s time:%s samples:%d",
  356. av_ts2str(frame->pts), av_ts2timestr(frame->pts, &link->time_base),
  357. frame->nb_samples);
  358. break;
  359. default:
  360. snprintf(dst, dst_size, "%s BUG", av_get_media_type_string(frame_type));
  361. break;
  362. }
  363. return dst;
  364. }
  365. static int rewind_file(AVFilterContext *ctx)
  366. {
  367. MovieContext *movie = ctx->priv;
  368. int64_t timestamp = movie->seek_point;
  369. int ret, i;
  370. if (movie->format_ctx->start_time != AV_NOPTS_VALUE)
  371. timestamp += movie->format_ctx->start_time;
  372. ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD);
  373. if (ret < 0) {
  374. av_log(ctx, AV_LOG_ERROR, "Unable to loop: %s\n", av_err2str(ret));
  375. movie->loop_count = 1; /* do not try again */
  376. return ret;
  377. }
  378. for (i = 0; i < ctx->nb_outputs; i++) {
  379. avcodec_flush_buffers(movie->st[i].st->codec);
  380. movie->st[i].done = 0;
  381. }
  382. movie->eof = 0;
  383. return 0;
  384. }
  385. /**
  386. * Try to push a frame to the requested output.
  387. *
  388. * @param ctx filter context
  389. * @param out_id number of output where a frame is wanted;
  390. * if the frame is read from file, used to set the return value;
  391. * if the codec is being flushed, flush the corresponding stream
  392. * @return 1 if a frame was pushed on the requested output,
  393. * 0 if another attempt is possible,
  394. * <0 AVERROR code
  395. */
  396. static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
  397. {
  398. MovieContext *movie = ctx->priv;
  399. AVPacket *pkt = &movie->pkt;
  400. enum AVMediaType frame_type;
  401. MovieStream *st;
  402. int ret, got_frame = 0, pkt_out_id;
  403. AVFilterLink *outlink;
  404. AVFrame *frame;
  405. if (!pkt->size) {
  406. if (movie->eof) {
  407. if (movie->st[out_id].done) {
  408. if (movie->loop_count != 1) {
  409. ret = rewind_file(ctx);
  410. if (ret < 0)
  411. return ret;
  412. movie->loop_count -= movie->loop_count > 1;
  413. av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n");
  414. return 0; /* retry */
  415. }
  416. return AVERROR_EOF;
  417. }
  418. pkt->stream_index = movie->st[out_id].st->index;
  419. /* packet is already ready for flushing */
  420. } else {
  421. ret = av_read_frame(movie->format_ctx, &movie->pkt0);
  422. if (ret < 0) {
  423. av_init_packet(&movie->pkt0); /* ready for flushing */
  424. *pkt = movie->pkt0;
  425. if (ret == AVERROR_EOF) {
  426. movie->eof = 1;
  427. return 0; /* start flushing */
  428. }
  429. return ret;
  430. }
  431. *pkt = movie->pkt0;
  432. }
  433. }
  434. pkt_out_id = pkt->stream_index > movie->max_stream_index ? -1 :
  435. movie->out_index[pkt->stream_index];
  436. if (pkt_out_id < 0) {
  437. av_free_packet(&movie->pkt0);
  438. pkt->size = 0; /* ready for next run */
  439. pkt->data = NULL;
  440. return 0;
  441. }
  442. st = &movie->st[pkt_out_id];
  443. outlink = ctx->outputs[pkt_out_id];
  444. frame = av_frame_alloc();
  445. if (!frame)
  446. return AVERROR(ENOMEM);
  447. frame_type = st->st->codec->codec_type;
  448. switch (frame_type) {
  449. case AVMEDIA_TYPE_VIDEO:
  450. ret = avcodec_decode_video2(st->st->codec, frame, &got_frame, pkt);
  451. break;
  452. case AVMEDIA_TYPE_AUDIO:
  453. ret = avcodec_decode_audio4(st->st->codec, frame, &got_frame, pkt);
  454. break;
  455. default:
  456. ret = AVERROR(ENOSYS);
  457. break;
  458. }
  459. if (ret < 0) {
  460. av_log(ctx, AV_LOG_WARNING, "Decode error: %s\n", av_err2str(ret));
  461. av_frame_free(&frame);
  462. av_free_packet(&movie->pkt0);
  463. movie->pkt.size = 0;
  464. movie->pkt.data = NULL;
  465. return 0;
  466. }
  467. if (!ret || st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
  468. ret = pkt->size;
  469. pkt->data += ret;
  470. pkt->size -= ret;
  471. if (pkt->size <= 0) {
  472. av_free_packet(&movie->pkt0);
  473. pkt->size = 0; /* ready for next run */
  474. pkt->data = NULL;
  475. }
  476. if (!got_frame) {
  477. if (!ret)
  478. st->done = 1;
  479. av_frame_free(&frame);
  480. return 0;
  481. }
  482. frame->pts = av_frame_get_best_effort_timestamp(frame);
  483. av_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
  484. describe_frame_to_str((char[1024]){0}, 1024, frame, frame_type, outlink));
  485. if (st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
  486. if (frame->format != outlink->format) {
  487. av_log(ctx, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n",
  488. av_get_pix_fmt_name(outlink->format),
  489. av_get_pix_fmt_name(frame->format)
  490. );
  491. av_frame_free(&frame);
  492. return 0;
  493. }
  494. }
  495. ret = ff_filter_frame(outlink, frame);
  496. if (ret < 0)
  497. return ret;
  498. return pkt_out_id == out_id;
  499. }
  500. static int movie_request_frame(AVFilterLink *outlink)
  501. {
  502. AVFilterContext *ctx = outlink->src;
  503. unsigned out_id = FF_OUTLINK_IDX(outlink);
  504. int ret;
  505. while (1) {
  506. ret = movie_push_frame(ctx, out_id);
  507. if (ret)
  508. return FFMIN(ret, 0);
  509. }
  510. }
  511. #if CONFIG_MOVIE_FILTER
  512. AVFILTER_DEFINE_CLASS(movie);
  513. AVFilter ff_avsrc_movie = {
  514. .name = "movie",
  515. .description = NULL_IF_CONFIG_SMALL("Read from a movie source."),
  516. .priv_size = sizeof(MovieContext),
  517. .priv_class = &movie_class,
  518. .init = movie_common_init,
  519. .uninit = movie_uninit,
  520. .query_formats = movie_query_formats,
  521. .inputs = NULL,
  522. .outputs = NULL,
  523. .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS,
  524. };
  525. #endif /* CONFIG_MOVIE_FILTER */
  526. #if CONFIG_AMOVIE_FILTER
  527. #define amovie_options movie_options
  528. AVFILTER_DEFINE_CLASS(amovie);
  529. AVFilter ff_avsrc_amovie = {
  530. .name = "amovie",
  531. .description = NULL_IF_CONFIG_SMALL("Read audio from a movie source."),
  532. .priv_size = sizeof(MovieContext),
  533. .init = movie_common_init,
  534. .uninit = movie_uninit,
  535. .query_formats = movie_query_formats,
  536. .inputs = NULL,
  537. .outputs = NULL,
  538. .priv_class = &amovie_class,
  539. .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS,
  540. };
  541. #endif /* CONFIG_AMOVIE_FILTER */