FFmpeg
src_movie.c
Go to the documentation of this file.
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 /**
23  * @file
24  * movie video source
25  *
26  * @todo use direct rendering (no allocation of a new frame)
27  * @todo support a PTS correction mechanism
28  */
29 
30 #include <float.h>
31 #include <stdint.h>
32 
33 #include "libavutil/attributes.h"
34 #include "libavutil/avstring.h"
35 #include "libavutil/avassert.h"
36 #include "libavutil/opt.h"
37 #include "libavutil/imgutils.h"
38 #include "libavutil/internal.h"
39 #include "libavutil/timestamp.h"
40 
41 #include "libavcodec/avcodec.h"
42 
43 #include "libavformat/avformat.h"
44 
45 #include "audio.h"
46 #include "avfilter.h"
47 #include "formats.h"
48 #include "internal.h"
49 #include "video.h"
50 
51 typedef struct MovieStream {
54  int done;
56  int64_t last_pts;
57 } MovieStream;
58 
59 typedef struct MovieContext {
60  /* common A/V fields */
61  const AVClass *class;
62  int64_t seek_point; ///< seekpoint in microseconds
63  double seek_point_d;
64  char *format_name;
65  char *file_name;
66  char *stream_specs; /**< user-provided list of streams, separated by + */
67  int stream_index; /**< for compatibility */
70  int64_t ts_offset;
71 
73  int eof;
75 
76  int max_stream_index; /**< max stream # actually used for output */
77  MovieStream *st; /**< array of all streams, one per output */
78  int *out_index; /**< stream number -> output number map, or -1 */
79 } MovieContext;
80 
81 #define OFFSET(x) offsetof(MovieContext, x)
82 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM
83 
84 static const AVOption movie_options[]= {
85  { "filename", NULL, OFFSET(file_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
86  { "format_name", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
87  { "f", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
88  { "stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
89  { "si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
90  { "seek_point", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, (INT64_MAX-1) / 1000000, FLAGS },
91  { "sp", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, (INT64_MAX-1) / 1000000, FLAGS },
92  { "streams", "set streams", OFFSET(stream_specs), AV_OPT_TYPE_STRING, {.str = 0}, CHAR_MAX, CHAR_MAX, FLAGS },
93  { "s", "set streams", OFFSET(stream_specs), AV_OPT_TYPE_STRING, {.str = 0}, CHAR_MAX, CHAR_MAX, FLAGS },
94  { "loop", "set loop count", OFFSET(loop_count), AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, FLAGS },
95  { "discontinuity", "set discontinuity threshold", OFFSET(discontinuity_threshold), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, FLAGS },
96  { NULL },
97 };
98 
99 static int movie_config_output_props(AVFilterLink *outlink);
100 static int movie_request_frame(AVFilterLink *outlink);
101 
102 static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec)
103 {
104  int i, ret, already = 0, stream_id = -1;
105  char type_char[2], dummy;
106  AVStream *found = NULL;
107  enum AVMediaType type;
108 
109  ret = sscanf(spec, "d%1[av]%d%c", type_char, &stream_id, &dummy);
110  if (ret >= 1 && ret <= 2) {
111  type = type_char[0] == 'v' ? AVMEDIA_TYPE_VIDEO : AVMEDIA_TYPE_AUDIO;
112  ret = av_find_best_stream(avf, type, stream_id, -1, NULL, 0);
113  if (ret < 0) {
114  av_log(log, AV_LOG_ERROR, "No %s stream with index '%d' found\n",
115  av_get_media_type_string(type), stream_id);
116  return NULL;
117  }
118  return avf->streams[ret];
119  }
120  for (i = 0; i < avf->nb_streams; i++) {
121  ret = avformat_match_stream_specifier(avf, avf->streams[i], spec);
122  if (ret < 0) {
123  av_log(log, AV_LOG_ERROR,
124  "Invalid stream specifier \"%s\"\n", spec);
125  return NULL;
126  }
127  if (!ret)
128  continue;
129  if (avf->streams[i]->discard != AVDISCARD_ALL) {
130  already++;
131  continue;
132  }
133  if (found) {
134  av_log(log, AV_LOG_WARNING,
135  "Ambiguous stream specifier \"%s\", using #%d\n", spec, i);
136  break;
137  }
138  found = avf->streams[i];
139  }
140  if (!found) {
141  av_log(log, AV_LOG_WARNING, "Stream specifier \"%s\" %s\n", spec,
142  already ? "matched only already used streams" :
143  "did not match any stream");
144  return NULL;
145  }
146  if (found->codecpar->codec_type != AVMEDIA_TYPE_VIDEO &&
148  av_log(log, AV_LOG_ERROR, "Stream specifier \"%s\" matched a %s stream,"
149  "currently unsupported by libavfilter\n", spec,
151  return NULL;
152  }
153  return found;
154 }
155 
156 static int open_stream(void *log, MovieStream *st)
157 {
158  AVCodec *codec;
159  int ret;
160 
161  codec = avcodec_find_decoder(st->st->codecpar->codec_id);
162  if (!codec) {
163  av_log(log, AV_LOG_ERROR, "Failed to find any codec\n");
164  return AVERROR(EINVAL);
165  }
166 
167  st->codec_ctx = avcodec_alloc_context3(codec);
168  if (!st->codec_ctx)
169  return AVERROR(ENOMEM);
170 
172  if (ret < 0)
173  return ret;
174 
175  st->codec_ctx->refcounted_frames = 1;
176 
177  if ((ret = avcodec_open2(st->codec_ctx, codec, NULL)) < 0) {
178  av_log(log, AV_LOG_ERROR, "Failed to open codec\n");
179  return ret;
180  }
181 
182  return 0;
183 }
184 
185 static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
186 {
187  AVCodecParameters *dec_par = st->st->codecpar;
188  char buf[256];
189  int64_t chl = av_get_default_channel_layout(dec_par->channels);
190 
191  if (!chl) {
192  av_log(log_ctx, AV_LOG_ERROR,
193  "Channel layout is not set in stream %d, and could not "
194  "be guessed from the number of channels (%d)\n",
195  st_index, dec_par->channels);
196  return AVERROR(EINVAL);
197  }
198 
199  av_get_channel_layout_string(buf, sizeof(buf), dec_par->channels, chl);
200  av_log(log_ctx, AV_LOG_WARNING,
201  "Channel layout is not set in output stream %d, "
202  "guessed channel layout is '%s'\n",
203  st_index, buf);
204  dec_par->channel_layout = chl;
205  return 0;
206 }
207 
209 {
210  MovieContext *movie = ctx->priv;
212  int64_t timestamp;
213  int nb_streams = 1, ret, i;
214  char default_streams[16], *stream_specs, *spec, *cursor;
215  char name[16];
216  AVStream *st;
217 
218  if (!movie->file_name) {
219  av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
220  return AVERROR(EINVAL);
221  }
222 
223  movie->seek_point = movie->seek_point_d * 1000000 + 0.5;
224 
225  stream_specs = movie->stream_specs;
226  if (!stream_specs) {
227  snprintf(default_streams, sizeof(default_streams), "d%c%d",
228  !strcmp(ctx->filter->name, "amovie") ? 'a' : 'v',
229  movie->stream_index);
230  stream_specs = default_streams;
231  }
232  for (cursor = stream_specs; *cursor; cursor++)
233  if (*cursor == '+')
234  nb_streams++;
235 
236  if (movie->loop_count != 1 && nb_streams != 1) {
238  "Loop with several streams is currently unsupported\n");
239  return AVERROR_PATCHWELCOME;
240  }
241 
242  // Try to find the movie format (container)
244 
245  movie->format_ctx = NULL;
246  if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, NULL)) < 0) {
248  "Failed to avformat_open_input '%s'\n", movie->file_name);
249  return ret;
250  }
251  if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0)
252  av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n");
253 
254  // if seeking requested, we execute it
255  if (movie->seek_point > 0) {
256  timestamp = movie->seek_point;
257  // add the stream start time, should it exist
258  if (movie->format_ctx->start_time != AV_NOPTS_VALUE) {
259  if (timestamp > 0 && movie->format_ctx->start_time > INT64_MAX - timestamp) {
261  "%s: seek value overflow with start_time:%"PRId64" seek_point:%"PRId64"\n",
262  movie->file_name, movie->format_ctx->start_time, movie->seek_point);
263  return AVERROR(EINVAL);
264  }
265  timestamp += movie->format_ctx->start_time;
266  }
267  if ((ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD)) < 0) {
268  av_log(ctx, AV_LOG_ERROR, "%s: could not seek to position %"PRId64"\n",
269  movie->file_name, timestamp);
270  return ret;
271  }
272  }
273 
274  for (i = 0; i < movie->format_ctx->nb_streams; i++)
276 
277  movie->st = av_calloc(nb_streams, sizeof(*movie->st));
278  if (!movie->st)
279  return AVERROR(ENOMEM);
280 
281  for (i = 0; i < nb_streams; i++) {
282  spec = av_strtok(stream_specs, "+", &cursor);
283  if (!spec)
284  return AVERROR_BUG;
285  stream_specs = NULL; /* for next strtok */
286  st = find_stream(ctx, movie->format_ctx, spec);
287  if (!st)
288  return AVERROR(EINVAL);
290  movie->st[i].st = st;
291  movie->max_stream_index = FFMAX(movie->max_stream_index, st->index);
292  movie->st[i].discontinuity_threshold =
294  }
295  if (av_strtok(NULL, "+", &cursor))
296  return AVERROR_BUG;
297 
298  movie->out_index = av_calloc(movie->max_stream_index + 1,
299  sizeof(*movie->out_index));
300  if (!movie->out_index)
301  return AVERROR(ENOMEM);
302  for (i = 0; i <= movie->max_stream_index; i++)
303  movie->out_index[i] = -1;
304  for (i = 0; i < nb_streams; i++) {
305  AVFilterPad pad = { 0 };
306  movie->out_index[movie->st[i].st->index] = i;
307  snprintf(name, sizeof(name), "out%d", i);
308  pad.type = movie->st[i].st->codecpar->codec_type;
309  pad.name = av_strdup(name);
310  if (!pad.name)
311  return AVERROR(ENOMEM);
314  if ((ret = ff_insert_outpad(ctx, i, &pad)) < 0) {
315  av_freep(&pad.name);
316  return ret;
317  }
318  if ( movie->st[i].st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
319  !movie->st[i].st->codecpar->channel_layout) {
320  ret = guess_channel_layout(&movie->st[i], i, ctx);
321  if (ret < 0)
322  return ret;
323  }
324  ret = open_stream(ctx, &movie->st[i]);
325  if (ret < 0)
326  return ret;
327  }
328 
329  av_log(ctx, AV_LOG_VERBOSE, "seek_point:%"PRIi64" format_name:%s file_name:%s stream_index:%d\n",
330  movie->seek_point, movie->format_name, movie->file_name,
331  movie->stream_index);
332 
333  return 0;
334 }
335 
337 {
338  MovieContext *movie = ctx->priv;
339  int i;
340 
341  for (i = 0; i < ctx->nb_outputs; i++) {
342  av_freep(&ctx->output_pads[i].name);
343  if (movie->st[i].st)
345  }
346  av_freep(&movie->st);
347  av_freep(&movie->out_index);
348  if (movie->format_ctx)
350 }
351 
353 {
354  MovieContext *movie = ctx->priv;
355  int list[] = { 0, -1 };
356  int64_t list64[] = { 0, -1 };
357  int i, ret;
358 
359  for (i = 0; i < ctx->nb_outputs; i++) {
360  MovieStream *st = &movie->st[i];
361  AVCodecParameters *c = st->st->codecpar;
362  AVFilterLink *outlink = ctx->outputs[i];
363 
364  switch (c->codec_type) {
365  case AVMEDIA_TYPE_VIDEO:
366  list[0] = c->format;
367  if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_formats)) < 0)
368  return ret;
369  break;
370  case AVMEDIA_TYPE_AUDIO:
371  list[0] = c->format;
372  if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_formats)) < 0)
373  return ret;
374  list[0] = c->sample_rate;
375  if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_samplerates)) < 0)
376  return ret;
377  list64[0] = c->channel_layout;
379  &outlink->in_channel_layouts)) < 0)
380  return ret;
381  break;
382  }
383  }
384 
385  return 0;
386 }
387 
389 {
390  AVFilterContext *ctx = outlink->src;
391  MovieContext *movie = ctx->priv;
392  unsigned out_id = FF_OUTLINK_IDX(outlink);
393  MovieStream *st = &movie->st[out_id];
394  AVCodecParameters *c = st->st->codecpar;
395 
396  outlink->time_base = st->st->time_base;
397 
398  switch (c->codec_type) {
399  case AVMEDIA_TYPE_VIDEO:
400  outlink->w = c->width;
401  outlink->h = c->height;
402  outlink->frame_rate = st->st->r_frame_rate;
403  break;
404  case AVMEDIA_TYPE_AUDIO:
405  break;
406  }
407 
408  return 0;
409 }
410 
411 static char *describe_frame_to_str(char *dst, size_t dst_size,
412  AVFrame *frame, enum AVMediaType frame_type,
414 {
415  switch (frame_type) {
416  case AVMEDIA_TYPE_VIDEO:
417  snprintf(dst, dst_size,
418  "video pts:%s time:%s size:%dx%d aspect:%d/%d",
419  av_ts2str(frame->pts), av_ts2timestr(frame->pts, &link->time_base),
420  frame->width, frame->height,
421  frame->sample_aspect_ratio.num,
422  frame->sample_aspect_ratio.den);
423  break;
424  case AVMEDIA_TYPE_AUDIO:
425  snprintf(dst, dst_size,
426  "audio pts:%s time:%s samples:%d",
427  av_ts2str(frame->pts), av_ts2timestr(frame->pts, &link->time_base),
428  frame->nb_samples);
429  break;
430  default:
431  snprintf(dst, dst_size, "%s BUG", av_get_media_type_string(frame_type));
432  break;
433  }
434  return dst;
435 }
436 
438 {
439  MovieContext *movie = ctx->priv;
440  int64_t timestamp = movie->seek_point;
441  int ret, i;
442 
443  if (movie->format_ctx->start_time != AV_NOPTS_VALUE)
444  timestamp += movie->format_ctx->start_time;
445  ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD);
446  if (ret < 0) {
447  av_log(ctx, AV_LOG_ERROR, "Unable to loop: %s\n", av_err2str(ret));
448  movie->loop_count = 1; /* do not try again */
449  return ret;
450  }
451 
452  for (i = 0; i < ctx->nb_outputs; i++) {
454  movie->st[i].done = 0;
455  }
456  movie->eof = 0;
457  return 0;
458 }
459 
460 /**
461  * Try to push a frame to the requested output.
462  *
463  * @param ctx filter context
464  * @param out_id number of output where a frame is wanted;
465  * if the frame is read from file, used to set the return value;
466  * if the codec is being flushed, flush the corresponding stream
467  * @return 1 if a frame was pushed on the requested output,
468  * 0 if another attempt is possible,
469  * <0 AVERROR code
470  */
471 static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
472 {
473  MovieContext *movie = ctx->priv;
474  AVPacket *pkt = &movie->pkt;
475  enum AVMediaType frame_type;
476  MovieStream *st;
477  int ret, got_frame = 0, pkt_out_id;
478  AVFilterLink *outlink;
479  AVFrame *frame;
480 
481  if (!pkt->size) {
482  if (movie->eof) {
483  if (movie->st[out_id].done) {
484  if (movie->loop_count != 1) {
485  ret = rewind_file(ctx);
486  if (ret < 0)
487  return ret;
488  movie->loop_count -= movie->loop_count > 1;
489  av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n");
490  return 0; /* retry */
491  }
492  return AVERROR_EOF;
493  }
494  pkt->stream_index = movie->st[out_id].st->index;
495  /* packet is already ready for flushing */
496  } else {
497  ret = av_read_frame(movie->format_ctx, &movie->pkt0);
498  if (ret < 0) {
499  av_init_packet(&movie->pkt0); /* ready for flushing */
500  *pkt = movie->pkt0;
501  if (ret == AVERROR_EOF) {
502  movie->eof = 1;
503  return 0; /* start flushing */
504  }
505  return ret;
506  }
507  *pkt = movie->pkt0;
508  }
509  }
510 
511  pkt_out_id = pkt->stream_index > movie->max_stream_index ? -1 :
512  movie->out_index[pkt->stream_index];
513  if (pkt_out_id < 0) {
514  av_packet_unref(&movie->pkt0);
515  pkt->size = 0; /* ready for next run */
516  pkt->data = NULL;
517  return 0;
518  }
519  st = &movie->st[pkt_out_id];
520  outlink = ctx->outputs[pkt_out_id];
521 
522  frame = av_frame_alloc();
523  if (!frame)
524  return AVERROR(ENOMEM);
525 
526  frame_type = st->st->codecpar->codec_type;
527  switch (frame_type) {
528  case AVMEDIA_TYPE_VIDEO:
529  ret = avcodec_decode_video2(st->codec_ctx, frame, &got_frame, pkt);
530  break;
531  case AVMEDIA_TYPE_AUDIO:
532  ret = avcodec_decode_audio4(st->codec_ctx, frame, &got_frame, pkt);
533  break;
534  default:
535  ret = AVERROR(ENOSYS);
536  break;
537  }
538  if (ret < 0) {
539  av_log(ctx, AV_LOG_WARNING, "Decode error: %s\n", av_err2str(ret));
541  av_packet_unref(&movie->pkt0);
542  movie->pkt.size = 0;
543  movie->pkt.data = NULL;
544  return 0;
545  }
546  if (!ret || st->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
547  ret = pkt->size;
548 
549  pkt->data += ret;
550  pkt->size -= ret;
551  if (pkt->size <= 0) {
552  av_packet_unref(&movie->pkt0);
553  pkt->size = 0; /* ready for next run */
554  pkt->data = NULL;
555  }
556  if (!got_frame) {
557  if (!ret)
558  st->done = 1;
560  return 0;
561  }
562 
563  frame->pts = frame->best_effort_timestamp;
564  if (frame->pts != AV_NOPTS_VALUE) {
565  if (movie->ts_offset)
567  if (st->discontinuity_threshold) {
568  if (st->last_pts != AV_NOPTS_VALUE) {
569  int64_t diff = frame->pts - st->last_pts;
570  if (diff < 0 || diff > st->discontinuity_threshold) {
571  av_log(ctx, AV_LOG_VERBOSE, "Discontinuity in stream:%d diff:%"PRId64"\n", pkt_out_id, diff);
573  frame->pts -= diff;
574  }
575  }
576  }
577  st->last_pts = frame->pts;
578  }
579  ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
580  describe_frame_to_str((char[1024]){0}, 1024, frame, frame_type, outlink));
581 
582  if (st->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
583  if (frame->format != outlink->format) {
584  av_log(ctx, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n",
585  av_get_pix_fmt_name(outlink->format),
586  av_get_pix_fmt_name(frame->format)
587  );
589  return 0;
590  }
591  }
592  ret = ff_filter_frame(outlink, frame);
593 
594  if (ret < 0)
595  return ret;
596  return pkt_out_id == out_id;
597 }
598 
599 static int movie_request_frame(AVFilterLink *outlink)
600 {
601  AVFilterContext *ctx = outlink->src;
602  unsigned out_id = FF_OUTLINK_IDX(outlink);
603  int ret;
604 
605  while (1) {
606  ret = movie_push_frame(ctx, out_id);
607  if (ret)
608  return FFMIN(ret, 0);
609  }
610 }
611 
612 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
613  char *res, int res_len, int flags)
614 {
615  MovieContext *movie = ctx->priv;
616  int ret = AVERROR(ENOSYS);
617 
618  if (!strcmp(cmd, "seek")) {
619  int idx, flags, i;
620  int64_t ts;
621  char tail[2];
622 
623  if (sscanf(args, "%i|%"SCNi64"|%i %1s", &idx, &ts, &flags, tail) != 3)
624  return AVERROR(EINVAL);
625 
626  ret = av_seek_frame(movie->format_ctx, idx, ts, flags);
627  if (ret < 0)
628  return ret;
629 
630  for (i = 0; i < ctx->nb_outputs; i++) {
632  movie->st[i].done = 0;
633  }
634  return ret;
635  } else if (!strcmp(cmd, "get_duration")) {
636  int print_len;
637  char tail[2];
638 
639  if (!res || res_len <= 0)
640  return AVERROR(EINVAL);
641 
642  if (args && sscanf(args, "%1s", tail) == 1)
643  return AVERROR(EINVAL);
644 
645  print_len = snprintf(res, res_len, "%"PRId64, movie->format_ctx->duration);
646  if (print_len < 0 || print_len >= res_len)
647  return AVERROR(EINVAL);
648 
649  return 0;
650  }
651 
652  return ret;
653 }
654 
655 #if CONFIG_MOVIE_FILTER
656 
657 AVFILTER_DEFINE_CLASS(movie);
658 
660  .name = "movie",
661  .description = NULL_IF_CONFIG_SMALL("Read from a movie source."),
662  .priv_size = sizeof(MovieContext),
663  .priv_class = &movie_class,
665  .uninit = movie_uninit,
667 
668  .inputs = NULL,
669  .outputs = NULL,
672 };
673 
674 #endif /* CONFIG_MOVIE_FILTER */
675 
676 #if CONFIG_AMOVIE_FILTER
677 
678 #define amovie_options movie_options
679 AVFILTER_DEFINE_CLASS(amovie);
680 
682  .name = "amovie",
683  .description = NULL_IF_CONFIG_SMALL("Read audio from a movie source."),
684  .priv_size = sizeof(MovieContext),
686  .uninit = movie_uninit,
688 
689  .inputs = NULL,
690  .outputs = NULL,
691  .priv_class = &amovie_class,
694 };
695 
696 #endif /* CONFIG_AMOVIE_FILTER */
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:599
AVCodec
AVCodec.
Definition: avcodec.h:3481
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
MovieStream::done
int done
Definition: src_movie.c:54
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3953
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3949
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
avcodec_decode_audio4
attribute_deprecated int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, const AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.
Definition: decode.c:905
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:435
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:925
MovieContext::eof
int eof
Definition: src_movie.c:73
describe_frame_to_str
static char * describe_frame_to_str(char *dst, size_t dst_size, AVFrame *frame, enum AVMediaType frame_type, AVFilterLink *link)
Definition: src_movie.c:411
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
MovieContext::stream_index
int stream_index
for compatibility
Definition: src_movie.c:67
FLAGS
#define FLAGS
Definition: src_movie.c:82
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
av_get_channel_layout_string
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
Definition: channel_layout.c:211
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1410
name
const char * name
Definition: avisynth_c.h:867
AVPacket::data
uint8_t * data
Definition: avcodec.h:1477
AVOption
AVOption.
Definition: opt.h:246
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Definition: opt.h:237
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
float.h
movie_options
static const AVOption movie_options[]
Definition: src_movie.c:84
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
av_read_frame
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: utils.c:1785
video.h
guess_channel_layout
static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
Definition: src_movie.c:185
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: src_movie.c:612
formats.h
MovieContext::out_index
int * out_index
stream number -> output number map, or -1
Definition: src_movie.c:78
avformat_close_input
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: utils.c:4452
MovieContext::file_name
char * file_name
Definition: src_movie.c:65
AVCodecParameters::channels
int channels
Audio only.
Definition: avcodec.h:4063
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AV_ROUND_UP
@ AV_ROUND_UP
Round toward +infinity.
Definition: mathematics.h:83
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:189
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
buf
void * buf
Definition: avisynth_c.h:766
AVInputFormat
Definition: avformat.h:640
AVFilterPad::request_frame
int(* request_frame)(AVFilterLink *link)
Frame request callback.
Definition: internal.h:113
av_cold
#define av_cold
Definition: attributes.h:84
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:156
av_seek_frame
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
Definition: utils.c:2525
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:225
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
FF_OUTLINK_IDX
#define FF_OUTLINK_IDX(link)
Definition: internal.h:349
av_strtok
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
Definition: avstring.c:184
MovieContext::ts_offset
int64_t ts_offset
Definition: src_movie.c:70
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
ctx
AVFormatContext * ctx
Definition: movenc.c:48
nb_streams
static int nb_streams
Definition: ffprobe.c:280
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
MovieContext::format_ctx
AVFormatContext * format_ctx
Definition: src_movie.c:72
MovieContext
Definition: src_movie.c:59
find_stream
static AVStream * find_stream(void *log, AVFormatContext *avf, const char *spec)
Definition: src_movie.c:102
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
MovieContext::pkt
AVPacket pkt
Definition: src_movie.c:74
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: avcodec.h:811
AVFormatContext
Format I/O context.
Definition: avformat.h:1342
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1017
AVSEEK_FLAG_BACKWARD
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:2495
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:899
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
movie_request_frame
static int movie_request_frame(AVFilterLink *outlink)
Definition: src_movie.c:599
MovieStream::discontinuity_threshold
int64_t discontinuity_threshold
Definition: src_movie.c:55
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:171
MovieContext::discontinuity_threshold
int64_t discontinuity_threshold
Definition: src_movie.c:69
MovieStream::last_pts
int64_t last_pts
Definition: src_movie.c:56
list
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
Definition: filter_design.txt:25
avcodec_open2
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:565
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
MovieStream::codec_ctx
AVCodecContext * codec_ctx
Definition: src_movie.c:53
MovieContext::format_name
char * format_name
Definition: src_movie.c:64
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
MovieStream::st
AVStream * st
Definition: src_movie.c:52
MovieContext::seek_point_d
double seek_point_d
Definition: src_movie.c:63
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
AVFILTER_FLAG_DYNAMIC_OUTPUTS
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition: avfilter.h:111
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1398
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:29
AVFilterPad::config_props
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:129
avformat_find_stream_info
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition: utils.c:3588
movie_common_init
static av_cold int movie_common_init(AVFilterContext *ctx)
Definition: src_movie.c:208
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:76
AVMediaType
AVMediaType
Definition: avutil.h:199
movie_query_formats
static int movie_query_formats(AVFilterContext *ctx)
Definition: src_movie.c:352
AVPacket::size
int size
Definition: avcodec.h:1478
movie_uninit
static av_cold void movie_uninit(AVFilterContext *ctx)
Definition: src_movie.c:336
avformat_match_stream_specifier
int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the stream st contained in s is matched by the stream specifier spec.
Definition: utils.c:5291
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
AVDISCARD_DEFAULT
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition: avcodec.h:806
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
MovieContext::loop_count
int loop_count
Definition: src_movie.c:68
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
avcodec_find_decoder
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:890
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
attributes.h
internal.h
AVFILTER_DEFINE_CLASS
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:334
av_find_input_format
ff_const59 AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition: format.c:118
avfilter_make_format64_list
AVFilterChannelLayouts * avfilter_make_format64_list(const int64_t *fmts)
Definition: formats.c:303
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
avformat_open_input
int avformat_open_input(AVFormatContext **ps, const char *url, ff_const59 AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: utils.c:540
rewind_file
static int rewind_file(AVFilterContext *ctx)
Definition: src_movie.c:437
internal.h
avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Definition: utils.c:2155
avcodec_decode_video2
attribute_deprecated int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
Definition: decode.c:898
args
const char AVS_Value args
Definition: avisynth_c.h:873
MovieContext::max_stream_index
int max_stream_index
max stream # actually used for output
Definition: src_movie.c:76
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
avcodec.h
AVFilter
Filter definition.
Definition: avfilter.h:144
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:870
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:65
avcodec_flush_buffers
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal decoder state / flush internal buffers.
Definition: decode.c:2028
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
movie_push_frame
static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
Try to push a frame to the requested output.
Definition: src_movie.c:471
avformat.h
iformat
static AVInputFormat * iformat
Definition: ffprobe.c:257
AVCodecContext::refcounted_frames
attribute_deprecated int refcounted_frames
If non-zero, the decoded audio and video frames returned from avcodec_decode_video2() and avcodec_dec...
Definition: avcodec.h:2396
movie_config_output_props
static int movie_config_output_props(AVFilterLink *outlink)
Definition: src_movie.c:388
MovieContext::pkt0
AVPacket pkt0
Definition: src_movie.c:74
av_get_media_type_string
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:76
AVCodecContext
main external API structure.
Definition: avcodec.h:1565
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:871
format_name
static int format_name(const char *buf, char **s, int index, const char *varname)
Definition: hlsenc.c:1833
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
ff_insert_outpad
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
Definition: internal.h:285
dummy
int dummy
Definition: motion.c:64
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
avfilter.h
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:994
MovieContext::stream_specs
char * stream_specs
user-provided list of streams, separated by +
Definition: src_movie.c:66
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1457
AVPacket::stream_index
int stream_index
Definition: avcodec.h:1479
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
MovieContext::st
MovieStream * st
array of all streams, one per output
Definition: src_movie.c:77
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:251
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
ff_avsrc_amovie
AVFilter ff_avsrc_amovie
audio.h
av_get_default_channel_layout
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
Definition: channel_layout.c:225
diff
static av_always_inline int diff(const uint32_t a, const uint32_t b)
Definition: vf_palettegen.c:136
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3957
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1454
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AVCodecParameters::channel_layout
uint64_t channel_layout
Audio only.
Definition: avcodec.h:4059
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
imgutils.h
timestamp.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
MovieContext::seek_point
int64_t seek_point
seekpoint in microseconds
Definition: src_movie.c:62
AVFormatContext::start_time
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1447
open_stream
static int open_stream(void *log, MovieStream *st)
Definition: src_movie.c:156
av_ts2str
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
ff_avsrc_movie
AVFilter ff_avsrc_movie
MovieStream
Definition: src_movie.c:51
snprintf
#define snprintf
Definition: snprintf.h:34
OFFSET
#define OFFSET(x)
Definition: src_movie.c:81
av_rescale_q_rnd
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
Definition: mathematics.c:134
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2438
av_init_packet
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:33
av_find_best_stream
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, AVCodec **decoder_ret, int flags)
Find the "best" stream in the file.
Definition: utils.c:4207