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 "config_components.h"
31 
32 #include <float.h>
33 #include <stdint.h>
34 
35 #include "libavutil/attributes.h"
36 #include "libavutil/avstring.h"
38 #include "libavutil/opt.h"
39 #include "libavutil/imgutils.h"
40 #include "libavutil/internal.h"
41 #include "libavutil/timestamp.h"
42 
43 #include "libavcodec/avcodec.h"
44 
45 #include "libavformat/avformat.h"
46 
47 #include "audio.h"
48 #include "avfilter.h"
49 #include "formats.h"
50 #include "internal.h"
51 #include "video.h"
52 
53 typedef struct MovieStream {
57  int64_t last_pts;
58 } MovieStream;
59 
60 typedef struct MovieContext {
61  /* common A/V fields */
62  const AVClass *class;
63  int64_t seek_point; ///< seekpoint in microseconds
64  double seek_point_d;
65  char *format_name;
66  char *file_name;
67  char *stream_specs; /**< user-provided list of streams, separated by + */
68  int stream_index; /**< for compatibility */
71  int64_t ts_offset;
73 
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 */
80 } MovieContext;
81 
82 #define OFFSET(x) offsetof(MovieContext, x)
83 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM
84 
85 static const AVOption movie_options[]= {
86  { "filename", NULL, OFFSET(file_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
87  { "format_name", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
88  { "f", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
89  { "stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
90  { "si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
91  { "seek_point", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, (INT64_MAX-1) / 1000000, FLAGS },
92  { "sp", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, (INT64_MAX-1) / 1000000, FLAGS },
93  { "streams", "set streams", OFFSET(stream_specs), AV_OPT_TYPE_STRING, {.str = 0}, 0, 0, FLAGS },
94  { "s", "set streams", OFFSET(stream_specs), AV_OPT_TYPE_STRING, {.str = 0}, 0, 0, FLAGS },
95  { "loop", "set loop count", OFFSET(loop_count), AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, FLAGS },
96  { "discontinuity", "set discontinuity threshold", OFFSET(discontinuity_threshold), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, FLAGS },
97  { "dec_threads", "set the number of threads for decoding", OFFSET(dec_threads), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS },
98  { "format_opts", "set format options for the opened file", OFFSET(format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
99  { NULL },
100 };
101 
102 static int movie_config_output_props(AVFilterLink *outlink);
103 static int movie_request_frame(AVFilterLink *outlink);
104 
105 static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec)
106 {
107  int i, ret, already = 0, stream_id = -1;
108  char type_char[2], dummy;
109  AVStream *found = NULL;
110  enum AVMediaType type;
111 
112  ret = sscanf(spec, "d%1[av]%d%c", type_char, &stream_id, &dummy);
113  if (ret >= 1 && ret <= 2) {
114  type = type_char[0] == 'v' ? AVMEDIA_TYPE_VIDEO : AVMEDIA_TYPE_AUDIO;
115  ret = av_find_best_stream(avf, type, stream_id, -1, NULL, 0);
116  if (ret < 0) {
117  av_log(log, AV_LOG_ERROR, "No %s stream with index '%d' found\n",
118  av_get_media_type_string(type), stream_id);
119  return NULL;
120  }
121  return avf->streams[ret];
122  }
123  for (i = 0; i < avf->nb_streams; i++) {
124  ret = avformat_match_stream_specifier(avf, avf->streams[i], spec);
125  if (ret < 0) {
126  av_log(log, AV_LOG_ERROR,
127  "Invalid stream specifier \"%s\"\n", spec);
128  return NULL;
129  }
130  if (!ret)
131  continue;
132  if (avf->streams[i]->discard != AVDISCARD_ALL) {
133  already++;
134  continue;
135  }
136  if (found) {
137  av_log(log, AV_LOG_WARNING,
138  "Ambiguous stream specifier \"%s\", using #%d\n", spec, i);
139  break;
140  }
141  found = avf->streams[i];
142  }
143  if (!found) {
144  av_log(log, AV_LOG_WARNING, "Stream specifier \"%s\" %s\n", spec,
145  already ? "matched only already used streams" :
146  "did not match any stream");
147  return NULL;
148  }
149  if (found->codecpar->codec_type != AVMEDIA_TYPE_VIDEO &&
151  av_log(log, AV_LOG_ERROR, "Stream specifier \"%s\" matched a %s stream,"
152  "currently unsupported by libavfilter\n", spec,
154  return NULL;
155  }
156  return found;
157 }
158 
159 static int open_stream(AVFilterContext *ctx, MovieStream *st, int dec_threads)
160 {
161  const AVCodec *codec;
162  int ret;
163 
164  codec = avcodec_find_decoder(st->st->codecpar->codec_id);
165  if (!codec) {
166  av_log(ctx, AV_LOG_ERROR, "Failed to find any codec\n");
167  return AVERROR(EINVAL);
168  }
169 
170  st->codec_ctx = avcodec_alloc_context3(codec);
171  if (!st->codec_ctx)
172  return AVERROR(ENOMEM);
173 
175  if (ret < 0)
176  return ret;
177 
178  if (!dec_threads)
179  dec_threads = ff_filter_get_nb_threads(ctx);
180  st->codec_ctx->thread_count = dec_threads;
181 
182  if ((ret = avcodec_open2(st->codec_ctx, codec, NULL)) < 0) {
183  av_log(ctx, AV_LOG_ERROR, "Failed to open codec\n");
184  return ret;
185  }
186 
187  return 0;
188 }
189 
190 static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
191 {
192  AVCodecParameters *dec_par = st->st->codecpar;
193  char buf[256];
194  AVChannelLayout chl = { 0 };
195 
197 
198  if (!KNOWN(&chl)) {
199  av_log(log_ctx, AV_LOG_ERROR,
200  "Channel layout is not set in stream %d, and could not "
201  "be guessed from the number of channels (%d)\n",
202  st_index, dec_par->ch_layout.nb_channels);
203  return AVERROR(EINVAL);
204  }
205 
206  av_channel_layout_describe(&chl, buf, sizeof(buf));
207  av_log(log_ctx, AV_LOG_WARNING,
208  "Channel layout is not set in output stream %d, "
209  "guessed channel layout is '%s'\n",
210  st_index, buf);
211  return av_channel_layout_copy(&dec_par->ch_layout, &chl);
212 }
213 
215 {
216  MovieContext *movie = ctx->priv;
217  const AVInputFormat *iformat = NULL;
218  int64_t timestamp;
219  int nb_streams = 1, ret, i;
220  char default_streams[16], *stream_specs, *spec, *cursor;
221  AVStream *st;
222 
223  if (!movie->file_name) {
224  av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
225  return AVERROR(EINVAL);
226  }
227 
228  movie->seek_point = movie->seek_point_d * 1000000 + 0.5;
229 
230  stream_specs = movie->stream_specs;
231  if (!stream_specs) {
232  snprintf(default_streams, sizeof(default_streams), "d%c%d",
233  !strcmp(ctx->filter->name, "amovie") ? 'a' : 'v',
234  movie->stream_index);
235  stream_specs = default_streams;
236  }
237  for (cursor = stream_specs; *cursor; cursor++)
238  if (*cursor == '+')
239  nb_streams++;
240 
241  if (movie->loop_count != 1 && nb_streams != 1) {
243  "Loop with several streams is currently unsupported\n");
244  return AVERROR_PATCHWELCOME;
245  }
246 
247  // Try to find the movie format (container)
249 
250  movie->format_ctx = NULL;
251  if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, &movie->format_opts)) < 0) {
253  "Failed to avformat_open_input '%s'\n", movie->file_name);
254  return ret;
255  }
256  if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0)
257  av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n");
258 
259  // if seeking requested, we execute it
260  if (movie->seek_point > 0) {
261  timestamp = movie->seek_point;
262  // add the stream start time, should it exist
263  if (movie->format_ctx->start_time != AV_NOPTS_VALUE) {
264  if (timestamp > 0 && movie->format_ctx->start_time > INT64_MAX - timestamp) {
266  "%s: seek value overflow with start_time:%"PRId64" seek_point:%"PRId64"\n",
267  movie->file_name, movie->format_ctx->start_time, movie->seek_point);
268  return AVERROR(EINVAL);
269  }
270  timestamp += movie->format_ctx->start_time;
271  }
272  if ((ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD)) < 0) {
273  av_log(ctx, AV_LOG_ERROR, "%s: could not seek to position %"PRId64"\n",
274  movie->file_name, timestamp);
275  return ret;
276  }
277  }
278 
279  for (i = 0; i < movie->format_ctx->nb_streams; i++)
281 
282  movie->st = av_calloc(nb_streams, sizeof(*movie->st));
283  if (!movie->st)
284  return AVERROR(ENOMEM);
285 
286  for (i = 0; i < nb_streams; i++) {
287  spec = av_strtok(stream_specs, "+", &cursor);
288  if (!spec)
289  return AVERROR_BUG;
290  stream_specs = NULL; /* for next strtok */
291  st = find_stream(ctx, movie->format_ctx, spec);
292  if (!st)
293  return AVERROR(EINVAL);
295  movie->st[i].st = st;
296  movie->max_stream_index = FFMAX(movie->max_stream_index, st->index);
297  movie->st[i].discontinuity_threshold =
299  }
300  if (av_strtok(NULL, "+", &cursor))
301  return AVERROR_BUG;
302 
303  movie->out_index = av_calloc(movie->max_stream_index + 1,
304  sizeof(*movie->out_index));
305  if (!movie->out_index)
306  return AVERROR(ENOMEM);
307  for (i = 0; i <= movie->max_stream_index; i++)
308  movie->out_index[i] = -1;
309  for (i = 0; i < nb_streams; i++) {
310  AVFilterPad pad = { 0 };
311  movie->out_index[movie->st[i].st->index] = i;
312  pad.type = movie->st[i].st->codecpar->codec_type;
313  pad.name = av_asprintf("out%d", i);
314  if (!pad.name)
315  return AVERROR(ENOMEM);
318  if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0)
319  return ret;
320  if ( movie->st[i].st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
321  !KNOWN(&movie->st[i].st->codecpar->ch_layout)) {
322  ret = guess_channel_layout(&movie->st[i], i, ctx);
323  if (ret < 0)
324  return ret;
325  }
326  ret = open_stream(ctx, &movie->st[i], movie->dec_threads);
327  if (ret < 0)
328  return ret;
329  }
330 
331  av_log(ctx, AV_LOG_VERBOSE, "seek_point:%"PRIi64" format_name:%s file_name:%s stream_index:%d\n",
332  movie->seek_point, movie->format_name, movie->file_name,
333  movie->stream_index);
334 
335  return 0;
336 }
337 
339 {
340  MovieContext *movie = ctx->priv;
341  int i;
342 
343  for (i = 0; i < ctx->nb_outputs; i++) {
344  if (movie->st[i].st)
346  }
347  av_freep(&movie->st);
348  av_freep(&movie->out_index);
349  if (movie->format_ctx)
351 }
352 
354 {
355  MovieContext *movie = ctx->priv;
356  int list[] = { 0, -1 };
357  AVChannelLayout list64[] = { { 0 }, { 0 } };
358  int i, ret;
359 
360  for (i = 0; i < ctx->nb_outputs; i++) {
361  MovieStream *st = &movie->st[i];
362  AVCodecParameters *c = st->st->codecpar;
363  AVFilterLink *outlink = ctx->outputs[i];
364 
365  switch (c->codec_type) {
366  case AVMEDIA_TYPE_VIDEO:
367  list[0] = c->format;
368  if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->incfg.formats)) < 0)
369  return ret;
370  break;
371  case AVMEDIA_TYPE_AUDIO:
372  list[0] = c->format;
373  if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->incfg.formats)) < 0)
374  return ret;
375  list[0] = c->sample_rate;
376  if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->incfg.samplerates)) < 0)
377  return ret;
378  list64[0] = c->ch_layout;
380  &outlink->incfg.channel_layouts)) < 0)
381  return ret;
382  break;
383  }
384  }
385 
386  return 0;
387 }
388 
390 {
391  AVFilterContext *ctx = outlink->src;
392  MovieContext *movie = ctx->priv;
393  unsigned out_id = FF_OUTLINK_IDX(outlink);
394  MovieStream *st = &movie->st[out_id];
395  AVCodecParameters *c = st->st->codecpar;
396 
397  outlink->time_base = st->st->time_base;
398 
399  switch (c->codec_type) {
400  case AVMEDIA_TYPE_VIDEO:
401  outlink->w = c->width;
402  outlink->h = c->height;
403  outlink->frame_rate = st->st->r_frame_rate;
404  break;
405  case AVMEDIA_TYPE_AUDIO:
406  break;
407  }
408 
409  return 0;
410 }
411 
412 static char *describe_frame_to_str(char *dst, size_t dst_size,
415 {
416  switch (frame_type) {
417  case AVMEDIA_TYPE_VIDEO:
418  snprintf(dst, dst_size,
419  "video pts:%s time:%s size:%dx%d aspect:%d/%d",
421  frame->width, frame->height,
422  frame->sample_aspect_ratio.num,
423  frame->sample_aspect_ratio.den);
424  break;
425  case AVMEDIA_TYPE_AUDIO:
426  snprintf(dst, dst_size,
427  "audio pts:%s time:%s samples:%d",
429  frame->nb_samples);
430  break;
431  default:
432  snprintf(dst, dst_size, "%s BUG", av_get_media_type_string(frame_type));
433  break;
434  }
435  return dst;
436 }
437 
439 {
440  MovieContext *movie = ctx->priv;
441  int64_t timestamp = movie->seek_point;
442  int ret, i;
443 
444  if (movie->format_ctx->start_time != AV_NOPTS_VALUE)
445  timestamp += movie->format_ctx->start_time;
446  ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD);
447  if (ret < 0) {
448  av_log(ctx, AV_LOG_ERROR, "Unable to loop: %s\n", av_err2str(ret));
449  movie->loop_count = 1; /* do not try again */
450  return ret;
451  }
452 
453  for (i = 0; i < ctx->nb_outputs; i++) {
455  }
456  return 0;
457 }
458 
460 {
461  MovieContext *movie = ctx->priv;
462  AVPacket pkt = { 0 };
463  int pkt_out_id, ret;
464 
465  /* read a new packet from input stream */
466  ret = av_read_frame(movie->format_ctx, &pkt);
467  if (ret == AVERROR_EOF) {
468  /* EOF -> set all decoders for flushing */
469  for (int i = 0; i < ctx->nb_outputs; i++) {
471  if (ret < 0 && ret != AVERROR_EOF)
472  return ret;
473  }
474 
475  return 0;
476  } else if (ret < 0)
477  return ret;
478 
479  /* send the packet to its decoder, if any */
480  pkt_out_id = pkt.stream_index > movie->max_stream_index ? -1 :
481  movie->out_index[pkt.stream_index];
482  if (pkt_out_id >= 0)
483  ret = avcodec_send_packet(movie->st[pkt_out_id].codec_ctx, &pkt);
485 
486  return ret;
487 }
488 
489 /**
490  * Try to push a frame to the requested output.
491  *
492  * @param ctx filter context
493  * @param out_id number of output where a frame is wanted;
494  * @return 0 if a frame was pushed on the requested output,
495  * AVERROR(EAGAIN) if the decoder requires more input
496  * AVERROR(EOF) if the decoder has been completely flushed
497  * <0 AVERROR code
498  */
499 static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
500 {
501  MovieContext *movie = ctx->priv;
502  MovieStream *st = &movie->st[out_id];
503  AVFilterLink *outlink = ctx->outputs[out_id];
504  AVFrame *frame;
505  int ret;
506 
507  frame = av_frame_alloc();
508  if (!frame)
509  return AVERROR(ENOMEM);
510 
512  if (ret < 0) {
513  if (ret != AVERROR_EOF && ret != AVERROR(EAGAIN))
514  av_log(ctx, AV_LOG_WARNING, "Decode error: %s\n", av_err2str(ret));
515 
517  return ret;
518  }
519 
520  frame->pts = frame->best_effort_timestamp;
521  if (frame->pts != AV_NOPTS_VALUE) {
522  if (movie->ts_offset)
524  if (st->discontinuity_threshold) {
525  if (st->last_pts != AV_NOPTS_VALUE) {
526  int64_t diff = frame->pts - st->last_pts;
527  if (diff < 0 || diff > st->discontinuity_threshold) {
528  av_log(ctx, AV_LOG_VERBOSE, "Discontinuity in stream:%d diff:%"PRId64"\n", out_id, diff);
530  frame->pts -= diff;
531  }
532  }
533  }
534  st->last_pts = frame->pts;
535  }
536  ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
537  describe_frame_to_str((char[1024]){0}, 1024, frame,
538  st->st->codecpar->codec_type, outlink));
539 
540  if (st->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
541  if (frame->format != outlink->format) {
542  av_log(ctx, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n",
543  av_get_pix_fmt_name(outlink->format),
544  av_get_pix_fmt_name(frame->format)
545  );
547  return 0;
548  }
549  }
550  ret = ff_filter_frame(outlink, frame);
551 
552  if (ret < 0)
553  return ret;
554  return 0;
555 }
556 
557 static int movie_request_frame(AVFilterLink *outlink)
558 {
559  AVFilterContext *ctx = outlink->src;
560  MovieContext *movie = ctx->priv;
561  unsigned out_id = FF_OUTLINK_IDX(outlink);
562 
563  while (1) {
564  int got_eagain = 0, got_eof = 0;
565  int ret = 0;
566 
567  /* check all decoders for available output */
568  for (int i = 0; i < ctx->nb_outputs; i++) {
570  if (ret == AVERROR(EAGAIN))
571  got_eagain++;
572  else if (ret == AVERROR_EOF)
573  got_eof++;
574  else if (ret < 0)
575  return ret;
576  else if (i == out_id)
577  return 0;
578  }
579 
580  if (got_eagain) {
581  /* all decoders require more input -> read a new packet */
583  if (ret < 0)
584  return ret;
585  } else if (got_eof) {
586  /* all decoders flushed */
587  if (movie->loop_count != 1) {
588  ret = rewind_file(ctx);
589  if (ret < 0)
590  return ret;
591  movie->loop_count -= movie->loop_count > 1;
592  av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n");
593  continue;
594  }
595  return AVERROR_EOF;
596  }
597  }
598 }
599 
600 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
601  char *res, int res_len, int flags)
602 {
603  MovieContext *movie = ctx->priv;
604  int ret = AVERROR(ENOSYS);
605 
606  if (!strcmp(cmd, "seek")) {
607  int idx, flags, i;
608  int64_t ts;
609  char tail[2];
610 
611  if (sscanf(args, "%i|%"SCNi64"|%i %1s", &idx, &ts, &flags, tail) != 3)
612  return AVERROR(EINVAL);
613 
614  ret = av_seek_frame(movie->format_ctx, idx, ts, flags);
615  if (ret < 0)
616  return ret;
617 
618  for (i = 0; i < ctx->nb_outputs; i++) {
620  }
621  return ret;
622  } else if (!strcmp(cmd, "get_duration")) {
623  int print_len;
624  char tail[2];
625 
626  if (!res || res_len <= 0)
627  return AVERROR(EINVAL);
628 
629  if (args && sscanf(args, "%1s", tail) == 1)
630  return AVERROR(EINVAL);
631 
632  print_len = snprintf(res, res_len, "%"PRId64, movie->format_ctx->duration);
633  if (print_len < 0 || print_len >= res_len)
634  return AVERROR(EINVAL);
635 
636  return 0;
637  }
638 
639  return ret;
640 }
641 
642 AVFILTER_DEFINE_CLASS_EXT(movie, "(a)movie", movie_options);
643 
644 #if CONFIG_MOVIE_FILTER
645 
646 const AVFilter ff_avsrc_movie = {
647  .name = "movie",
648  .description = NULL_IF_CONFIG_SMALL("Read from a movie source."),
649  .priv_size = sizeof(MovieContext),
650  .priv_class = &movie_class,
652  .uninit = movie_uninit,
654 
655  .inputs = NULL,
656  .outputs = NULL,
658  .process_command = process_command
659 };
660 
661 #endif /* CONFIG_MOVIE_FILTER */
662 
663 #if CONFIG_AMOVIE_FILTER
664 
665 const AVFilter ff_avsrc_amovie = {
666  .name = "amovie",
667  .description = NULL_IF_CONFIG_SMALL("Read audio from a movie source."),
668  .priv_class = &movie_class,
669  .priv_size = sizeof(MovieContext),
671  .uninit = movie_uninit,
673 
674  .inputs = NULL,
675  .outputs = NULL,
677  .process_command = process_command,
678 };
679 
680 #endif /* CONFIG_AMOVIE_FILTER */
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:422
AVCodec
AVCodec.
Definition: codec.h:196
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVFilterFormatsConfig::samplerates
AVFilterFormats * samplerates
Lists of supported sample rates, only for audio.
Definition: avfilter.h:517
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: codec_par.h:57
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:380
movie_decode_packet
static int movie_decode_packet(AVFilterContext *ctx)
Definition: src_movie.c:459
AVFilterFormatsConfig::channel_layouts
AVFilterChannelLayouts * channel_layouts
Lists of supported channel layouts, only for audio.
Definition: avfilter.h:522
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:53
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:999
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:591
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:1010
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:412
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:68
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:116
FLAGS
#define FLAGS
Definition: src_movie.c:83
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:111
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1281
AVOption
AVOption.
Definition: opt.h:251
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:167
format_opts
AVDictionary * format_opts
Definition: cmdutils.c:60
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Definition: opt.h:239
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
float.h
movie_options
static const AVOption movie_options[]
Definition: src_movie.c:85
AVDictionary
Definition: dict.c:30
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:175
av_read_frame
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: demux.c:1438
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:300
video.h
guess_channel_layout
static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
Definition: src_movie.c:190
ff_avsrc_movie
const AVFilter ff_avsrc_movie
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:637
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:600
formats.h
init
static int init
Definition: av_tx.c:47
av_find_best_stream
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, const AVCodec **decoder_ret, int flags)
Find the "best" stream in the file.
Definition: avformat.c:347
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: demux.c:368
got_eagain
static int got_eagain(void)
Definition: ffmpeg.c:3791
MovieContext::file_name
char * file_name
Definition: src_movie.c:66
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1463
dummy
int dummy
Definition: motion.c:65
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
ff_avsrc_amovie
const AVFilter ff_avsrc_amovie
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:99
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVInputFormat
Definition: avformat.h:656
AVFilterPad::request_frame
int(* request_frame)(AVFilterLink *link)
Frame request callback.
Definition: internal.h:113
av_cold
#define av_cold
Definition: attributes.h:90
avformat_open_input
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: demux.c:220
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:149
av_seek_frame
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
Definition: seek.c:634
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
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:596
FF_OUTLINK_IDX
#define FF_OUTLINK_IDX(link)
Definition: internal.h:334
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:189
avcodec_receive_frame
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder.
Definition: decode.c:639
MovieContext::ts_offset
int64_t ts_offset
Definition: src_movie.c:71
ctx
AVFormatContext * ctx
Definition: movenc.c:48
nb_streams
static int nb_streams
Definition: ffprobe.c:307
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:74
MovieContext
Definition: src_movie.c:60
find_stream
static AVStream * find_stream(void *log, AVFormatContext *avf, const char *spec)
Definition: src_movie.c:105
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
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:54
AVFormatContext
Format I/O context.
Definition: avformat.h:1213
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1108
AVSEEK_FLAG_BACKWARD
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:2289
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
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:978
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
movie_request_frame
static int movie_request_frame(AVFilterLink *outlink)
Definition: src_movie.c:557
MovieStream::discontinuity_threshold
int64_t discontinuity_threshold
Definition: src_movie.c:56
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:164
MovieContext::discontinuity_threshold
int64_t discontinuity_threshold
Definition: src_movie.c:70
AVFILTER_DEFINE_CLASS_EXT
AVFILTER_DEFINE_CLASS_EXT(movie, "(a)movie", movie_options)
AV_OPT_TYPE_DICT
@ AV_OPT_TYPE_DICT
Definition: opt.h:232
MovieStream::last_pts
int64_t last_pts
Definition: src_movie.c:57
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
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:960
avcodec_open2
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: avcodec.c:115
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:212
MovieStream::codec_ctx
AVCodecContext * codec_ctx
Definition: src_movie.c:55
MovieContext::format_name
char * format_name
Definition: src_movie.c:65
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:54
MovieContext::seek_point_d
double seek_point_d
Definition: src_movie.c:64
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:935
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:122
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1269
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
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: demux.c:2415
movie_common_init
static av_cold int movie_common_init(AVFilterContext *ctx)
Definition: src_movie.c:214
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:353
movie_uninit
static av_cold void movie_uninit(AVFilterContext *ctx)
Definition: src_movie.c:338
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: avformat.c:545
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:117
AVDISCARD_DEFAULT
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition: defs.h:49
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:290
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:121
MovieContext::loop_count
int loop_count
Definition: src_movie.c:69
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVFrame::time_base
AVRational time_base
Time base for the timestamps in this frame.
Definition: frame.h:447
attributes.h
MovieContext::format_opts
AVDictionary * format_opts
Definition: src_movie.c:79
internal.h
iformat
static const AVInputFormat * iformat
Definition: ffprobe.c:283
avcodec_send_packet
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition: decode.c:576
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
frame_type
frame_type
Definition: jpeg2000_parser.c:31
rewind_file
static int rewind_file(AVFilterContext *ctx)
Definition: src_movie.c:438
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: codec_par.c:182
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:783
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:55
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:272
avcodec.h
AVFilter
Filter definition.
Definition: avfilter.h:171
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:948
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:60
avcodec_flush_buffers
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal codec state / flush internal buffers.
Definition: avcodec.c:377
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:499
avformat.h
movie_config_output_props
static int movie_config_output_props(AVFilterLink *outlink)
Definition: src_movie.c:389
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:28
AVCodecContext
main external API structure.
Definition: avcodec.h:389
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:956
format_name
static int format_name(const char *buf, char **s, int index, const char *varname)
Definition: hlsenc.c:1930
channel_layout.h
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:1097
KNOWN
#define KNOWN(l)
Definition: formats.h:111
av_channel_layout_describe
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
Definition: channel_layout.c:776
av_find_input_format
const AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition: format.c:120
MovieContext::stream_specs
char * stream_specs
user-provided list of streams, separated by +
Definition: src_movie.c:67
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1315
AVPacket::stream_index
int stream_index
Definition: packet.h:376
AVFilterContext
An instance of a filter.
Definition: avfilter.h:408
MovieContext::st
MovieStream * st
array of all streams, one per output
Definition: src_movie.c:77
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
audio.h
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:512
MovieContext::dec_threads
int dec_threads
Definition: src_movie.c:72
diff
static av_always_inline int diff(const uint32_t a, const uint32_t b)
Definition: vf_palettegen.c:139
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:61
AVPacket
This structure stores compressed data.
Definition: packet.h:351
ff_append_outpad_free_name
int ff_append_outpad_free_name(AVFilterContext *f, AVFilterPad *p)
Definition: avfilter.c:134
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
ff_make_channel_layout_list
AVFilterChannelLayouts * ff_make_channel_layout_list(const AVChannelLayout *fmts)
Definition: formats.c:389
imgutils.h
timestamp.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
MovieContext::seek_point
int64_t seek_point
seekpoint in microseconds
Definition: src_movie.c:63
AVFormatContext::start_time
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1305
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:285
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
MovieStream
Definition: src_movie.c:53
snprintf
#define snprintf
Definition: snprintf.h:34
OFFSET
#define OFFSET(x)
Definition: src_movie.c:82
open_stream
static int open_stream(AVFilterContext *ctx, MovieStream *st, int dec_threads)
Definition: src_movie.c:159
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:2582