FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 #include "libavformat/avformat.h"
41 #include "audio.h"
42 #include "avcodec.h"
43 #include "avfilter.h"
44 #include "formats.h"
45 #include "internal.h"
46 #include "video.h"
47 
48 typedef struct MovieStream {
50  int done;
51 } MovieStream;
52 
53 typedef struct MovieContext {
54  /* common A/V fields */
55  const AVClass *class;
56  int64_t seek_point; ///< seekpoint in microseconds
57  double seek_point_d;
58  char *format_name;
59  char *file_name;
60  char *stream_specs; /**< user-provided list of streams, separated by + */
61  int stream_index; /**< for compatibility */
63 
65  int eof;
67 
68  int max_stream_index; /**< max stream # actually used for output */
69  MovieStream *st; /**< array of all streams, one per output */
70  int *out_index; /**< stream number -> output number map, or -1 */
71 } MovieContext;
72 
73 #define OFFSET(x) offsetof(MovieContext, x)
74 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM
75 
76 static const AVOption movie_options[]= {
77  { "filename", NULL, OFFSET(file_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
78  { "format_name", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
79  { "f", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
80  { "stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
81  { "si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
82  { "seek_point", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, (INT64_MAX-1) / 1000000, FLAGS },
83  { "sp", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, (INT64_MAX-1) / 1000000, FLAGS },
84  { "streams", "set streams", OFFSET(stream_specs), AV_OPT_TYPE_STRING, {.str = 0}, CHAR_MAX, CHAR_MAX, FLAGS },
85  { "s", "set streams", OFFSET(stream_specs), AV_OPT_TYPE_STRING, {.str = 0}, CHAR_MAX, CHAR_MAX, FLAGS },
86  { "loop", "set loop count", OFFSET(loop_count), AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, FLAGS },
87  { NULL },
88 };
89 
90 static int movie_config_output_props(AVFilterLink *outlink);
91 static int movie_request_frame(AVFilterLink *outlink);
92 
93 static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec)
94 {
95  int i, ret, already = 0, stream_id = -1;
96  char type_char[2], dummy;
97  AVStream *found = NULL;
98  enum AVMediaType type;
99 
100  ret = sscanf(spec, "d%1[av]%d%c", type_char, &stream_id, &dummy);
101  if (ret >= 1 && ret <= 2) {
102  type = type_char[0] == 'v' ? AVMEDIA_TYPE_VIDEO : AVMEDIA_TYPE_AUDIO;
103  ret = av_find_best_stream(avf, type, stream_id, -1, NULL, 0);
104  if (ret < 0) {
105  av_log(log, AV_LOG_ERROR, "No %s stream with index '%d' found\n",
106  av_get_media_type_string(type), stream_id);
107  return NULL;
108  }
109  return avf->streams[ret];
110  }
111  for (i = 0; i < avf->nb_streams; i++) {
112  ret = avformat_match_stream_specifier(avf, avf->streams[i], spec);
113  if (ret < 0) {
114  av_log(log, AV_LOG_ERROR,
115  "Invalid stream specifier \"%s\"\n", spec);
116  return NULL;
117  }
118  if (!ret)
119  continue;
120  if (avf->streams[i]->discard != AVDISCARD_ALL) {
121  already++;
122  continue;
123  }
124  if (found) {
125  av_log(log, AV_LOG_WARNING,
126  "Ambiguous stream specifier \"%s\", using #%d\n", spec, i);
127  break;
128  }
129  found = avf->streams[i];
130  }
131  if (!found) {
132  av_log(log, AV_LOG_WARNING, "Stream specifier \"%s\" %s\n", spec,
133  already ? "matched only already used streams" :
134  "did not match any stream");
135  return NULL;
136  }
137  if (found->codec->codec_type != AVMEDIA_TYPE_VIDEO &&
138  found->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
139  av_log(log, AV_LOG_ERROR, "Stream specifier \"%s\" matched a %s stream,"
140  "currently unsupported by libavfilter\n", spec,
142  return NULL;
143  }
144  return found;
145 }
146 
147 static int open_stream(void *log, MovieStream *st)
148 {
149  AVCodec *codec;
150  int ret;
151 
152  codec = avcodec_find_decoder(st->st->codec->codec_id);
153  if (!codec) {
154  av_log(log, AV_LOG_ERROR, "Failed to find any codec\n");
155  return AVERROR(EINVAL);
156  }
157 
158  st->st->codec->refcounted_frames = 1;
159 
160  if ((ret = avcodec_open2(st->st->codec, codec, NULL)) < 0) {
161  av_log(log, AV_LOG_ERROR, "Failed to open codec\n");
162  return ret;
163  }
164 
165  return 0;
166 }
167 
168 static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
169 {
170  AVCodecContext *dec_ctx = st->st->codec;
171  char buf[256];
172  int64_t chl = av_get_default_channel_layout(dec_ctx->channels);
173 
174  if (!chl) {
175  av_log(log_ctx, AV_LOG_ERROR,
176  "Channel layout is not set in stream %d, and could not "
177  "be guessed from the number of channels (%d)\n",
178  st_index, dec_ctx->channels);
179  return AVERROR(EINVAL);
180  }
181 
182  av_get_channel_layout_string(buf, sizeof(buf), dec_ctx->channels, chl);
183  av_log(log_ctx, AV_LOG_WARNING,
184  "Channel layout is not set in output stream %d, "
185  "guessed channel layout is '%s'\n",
186  st_index, buf);
187  dec_ctx->channel_layout = chl;
188  return 0;
189 }
190 
192 {
193  MovieContext *movie = ctx->priv;
195  int64_t timestamp;
196  int nb_streams = 1, ret, i;
197  char default_streams[16], *stream_specs, *spec, *cursor;
198  char name[16];
199  AVStream *st;
200 
201  if (!movie->file_name) {
202  av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
203  return AVERROR(EINVAL);
204  }
205 
206  movie->seek_point = movie->seek_point_d * 1000000 + 0.5;
207 
208  stream_specs = movie->stream_specs;
209  if (!stream_specs) {
210  snprintf(default_streams, sizeof(default_streams), "d%c%d",
211  !strcmp(ctx->filter->name, "amovie") ? 'a' : 'v',
212  movie->stream_index);
213  stream_specs = default_streams;
214  }
215  for (cursor = stream_specs; *cursor; cursor++)
216  if (*cursor == '+')
217  nb_streams++;
218 
219  if (movie->loop_count != 1 && nb_streams != 1) {
220  av_log(ctx, AV_LOG_ERROR,
221  "Loop with several streams is currently unsupported\n");
222  return AVERROR_PATCHWELCOME;
223  }
224 
225  av_register_all();
226 
227  // Try to find the movie format (container)
228  iformat = movie->format_name ? av_find_input_format(movie->format_name) : NULL;
229 
230  movie->format_ctx = NULL;
231  if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, NULL)) < 0) {
232  av_log(ctx, AV_LOG_ERROR,
233  "Failed to avformat_open_input '%s'\n", movie->file_name);
234  return ret;
235  }
236  if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0)
237  av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n");
238 
239  // if seeking requested, we execute it
240  if (movie->seek_point > 0) {
241  timestamp = movie->seek_point;
242  // add the stream start time, should it exist
243  if (movie->format_ctx->start_time != AV_NOPTS_VALUE) {
244  if (timestamp > INT64_MAX - movie->format_ctx->start_time) {
245  av_log(ctx, AV_LOG_ERROR,
246  "%s: seek value overflow with start_time:%"PRId64" seek_point:%"PRId64"\n",
247  movie->file_name, movie->format_ctx->start_time, movie->seek_point);
248  return AVERROR(EINVAL);
249  }
250  timestamp += movie->format_ctx->start_time;
251  }
252  if ((ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD)) < 0) {
253  av_log(ctx, AV_LOG_ERROR, "%s: could not seek to position %"PRId64"\n",
254  movie->file_name, timestamp);
255  return ret;
256  }
257  }
258 
259  for (i = 0; i < movie->format_ctx->nb_streams; i++)
260  movie->format_ctx->streams[i]->discard = AVDISCARD_ALL;
261 
262  movie->st = av_calloc(nb_streams, sizeof(*movie->st));
263  if (!movie->st)
264  return AVERROR(ENOMEM);
265 
266  for (i = 0; i < nb_streams; i++) {
267  spec = av_strtok(stream_specs, "+", &cursor);
268  if (!spec)
269  return AVERROR_BUG;
270  stream_specs = NULL; /* for next strtok */
271  st = find_stream(ctx, movie->format_ctx, spec);
272  if (!st)
273  return AVERROR(EINVAL);
275  movie->st[i].st = st;
276  movie->max_stream_index = FFMAX(movie->max_stream_index, st->index);
277  }
278  if (av_strtok(NULL, "+", &cursor))
279  return AVERROR_BUG;
280 
281  movie->out_index = av_calloc(movie->max_stream_index + 1,
282  sizeof(*movie->out_index));
283  if (!movie->out_index)
284  return AVERROR(ENOMEM);
285  for (i = 0; i <= movie->max_stream_index; i++)
286  movie->out_index[i] = -1;
287  for (i = 0; i < nb_streams; i++) {
288  AVFilterPad pad = { 0 };
289  movie->out_index[movie->st[i].st->index] = i;
290  snprintf(name, sizeof(name), "out%d", i);
291  pad.type = movie->st[i].st->codec->codec_type;
292  pad.name = av_strdup(name);
293  if (!pad.name)
294  return AVERROR(ENOMEM);
297  ff_insert_outpad(ctx, i, &pad);
298  ret = open_stream(ctx, &movie->st[i]);
299  if (ret < 0)
300  return ret;
301  if ( movie->st[i].st->codec->codec->type == AVMEDIA_TYPE_AUDIO &&
302  !movie->st[i].st->codec->channel_layout) {
303  ret = guess_channel_layout(&movie->st[i], i, ctx);
304  if (ret < 0)
305  return ret;
306  }
307  }
308 
309  av_log(ctx, AV_LOG_VERBOSE, "seek_point:%"PRIi64" format_name:%s file_name:%s stream_index:%d\n",
310  movie->seek_point, movie->format_name, movie->file_name,
311  movie->stream_index);
312 
313  return 0;
314 }
315 
317 {
318  MovieContext *movie = ctx->priv;
319  int i;
320 
321  for (i = 0; i < ctx->nb_outputs; i++) {
322  av_freep(&ctx->output_pads[i].name);
323  if (movie->st[i].st)
324  avcodec_close(movie->st[i].st->codec);
325  }
326  av_freep(&movie->st);
327  av_freep(&movie->out_index);
328  if (movie->format_ctx)
330 }
331 
333 {
334  MovieContext *movie = ctx->priv;
335  int list[] = { 0, -1 };
336  int64_t list64[] = { 0, -1 };
337  int i;
338 
339  for (i = 0; i < ctx->nb_outputs; i++) {
340  MovieStream *st = &movie->st[i];
341  AVCodecContext *c = st->st->codec;
342  AVFilterLink *outlink = ctx->outputs[i];
343 
344  switch (c->codec_type) {
345  case AVMEDIA_TYPE_VIDEO:
346  list[0] = c->pix_fmt;
348  break;
349  case AVMEDIA_TYPE_AUDIO:
350  list[0] = c->sample_fmt;
352  list[0] = c->sample_rate;
354  list64[0] = c->channel_layout;
356  &outlink->in_channel_layouts);
357  break;
358  }
359  }
360 
361  return 0;
362 }
363 
365 {
366  AVFilterContext *ctx = outlink->src;
367  MovieContext *movie = ctx->priv;
368  unsigned out_id = FF_OUTLINK_IDX(outlink);
369  MovieStream *st = &movie->st[out_id];
370  AVCodecContext *c = st->st->codec;
371 
372  outlink->time_base = st->st->time_base;
373 
374  switch (c->codec_type) {
375  case AVMEDIA_TYPE_VIDEO:
376  outlink->w = c->width;
377  outlink->h = c->height;
378  outlink->frame_rate = st->st->r_frame_rate;
379  break;
380  case AVMEDIA_TYPE_AUDIO:
381  break;
382  }
383 
384  return 0;
385 }
386 
387 static char *describe_frame_to_str(char *dst, size_t dst_size,
388  AVFrame *frame, enum AVMediaType frame_type,
389  AVFilterLink *link)
390 {
391  switch (frame_type) {
392  case AVMEDIA_TYPE_VIDEO:
393  snprintf(dst, dst_size,
394  "video pts:%s time:%s size:%dx%d aspect:%d/%d",
395  av_ts2str(frame->pts), av_ts2timestr(frame->pts, &link->time_base),
396  frame->width, frame->height,
397  frame->sample_aspect_ratio.num,
398  frame->sample_aspect_ratio.den);
399  break;
400  case AVMEDIA_TYPE_AUDIO:
401  snprintf(dst, dst_size,
402  "audio pts:%s time:%s samples:%d",
403  av_ts2str(frame->pts), av_ts2timestr(frame->pts, &link->time_base),
404  frame->nb_samples);
405  break;
406  default:
407  snprintf(dst, dst_size, "%s BUG", av_get_media_type_string(frame_type));
408  break;
409  }
410  return dst;
411 }
412 
413 static int rewind_file(AVFilterContext *ctx)
414 {
415  MovieContext *movie = ctx->priv;
416  int64_t timestamp = movie->seek_point;
417  int ret, i;
418 
419  if (movie->format_ctx->start_time != AV_NOPTS_VALUE)
420  timestamp += movie->format_ctx->start_time;
421  ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD);
422  if (ret < 0) {
423  av_log(ctx, AV_LOG_ERROR, "Unable to loop: %s\n", av_err2str(ret));
424  movie->loop_count = 1; /* do not try again */
425  return ret;
426  }
427 
428  for (i = 0; i < ctx->nb_outputs; i++) {
429  avcodec_flush_buffers(movie->st[i].st->codec);
430  movie->st[i].done = 0;
431  }
432  movie->eof = 0;
433  return 0;
434 }
435 
436 /**
437  * Try to push a frame to the requested output.
438  *
439  * @param ctx filter context
440  * @param out_id number of output where a frame is wanted;
441  * if the frame is read from file, used to set the return value;
442  * if the codec is being flushed, flush the corresponding stream
443  * @return 1 if a frame was pushed on the requested output,
444  * 0 if another attempt is possible,
445  * <0 AVERROR code
446  */
447 static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
448 {
449  MovieContext *movie = ctx->priv;
450  AVPacket *pkt = &movie->pkt;
451  enum AVMediaType frame_type;
452  MovieStream *st;
453  int ret, got_frame = 0, pkt_out_id;
454  AVFilterLink *outlink;
455  AVFrame *frame;
456 
457  if (!pkt->size) {
458  if (movie->eof) {
459  if (movie->st[out_id].done) {
460  if (movie->loop_count != 1) {
461  ret = rewind_file(ctx);
462  if (ret < 0)
463  return ret;
464  movie->loop_count -= movie->loop_count > 1;
465  av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n");
466  return 0; /* retry */
467  }
468  return AVERROR_EOF;
469  }
470  pkt->stream_index = movie->st[out_id].st->index;
471  /* packet is already ready for flushing */
472  } else {
473  ret = av_read_frame(movie->format_ctx, &movie->pkt0);
474  if (ret < 0) {
475  av_init_packet(&movie->pkt0); /* ready for flushing */
476  *pkt = movie->pkt0;
477  if (ret == AVERROR_EOF) {
478  movie->eof = 1;
479  return 0; /* start flushing */
480  }
481  return ret;
482  }
483  *pkt = movie->pkt0;
484  }
485  }
486 
487  pkt_out_id = pkt->stream_index > movie->max_stream_index ? -1 :
488  movie->out_index[pkt->stream_index];
489  if (pkt_out_id < 0) {
490  av_free_packet(&movie->pkt0);
491  pkt->size = 0; /* ready for next run */
492  pkt->data = NULL;
493  return 0;
494  }
495  st = &movie->st[pkt_out_id];
496  outlink = ctx->outputs[pkt_out_id];
497 
498  frame = av_frame_alloc();
499  if (!frame)
500  return AVERROR(ENOMEM);
501 
502  frame_type = st->st->codec->codec_type;
503  switch (frame_type) {
504  case AVMEDIA_TYPE_VIDEO:
505  ret = avcodec_decode_video2(st->st->codec, frame, &got_frame, pkt);
506  break;
507  case AVMEDIA_TYPE_AUDIO:
508  ret = avcodec_decode_audio4(st->st->codec, frame, &got_frame, pkt);
509  break;
510  default:
511  ret = AVERROR(ENOSYS);
512  break;
513  }
514  if (ret < 0) {
515  av_log(ctx, AV_LOG_WARNING, "Decode error: %s\n", av_err2str(ret));
516  av_frame_free(&frame);
517  av_free_packet(&movie->pkt0);
518  movie->pkt.size = 0;
519  movie->pkt.data = NULL;
520  return 0;
521  }
522  if (!ret || st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
523  ret = pkt->size;
524 
525  pkt->data += ret;
526  pkt->size -= ret;
527  if (pkt->size <= 0) {
528  av_free_packet(&movie->pkt0);
529  pkt->size = 0; /* ready for next run */
530  pkt->data = NULL;
531  }
532  if (!got_frame) {
533  if (!ret)
534  st->done = 1;
535  av_frame_free(&frame);
536  return 0;
537  }
538 
539  frame->pts = av_frame_get_best_effort_timestamp(frame);
540  ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
541  describe_frame_to_str((char[1024]){0}, 1024, frame, frame_type, outlink));
542 
543  if (st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
544  if (frame->format != outlink->format) {
545  av_log(ctx, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n",
546  av_get_pix_fmt_name(outlink->format),
548  );
549  av_frame_free(&frame);
550  return 0;
551  }
552  }
553  ret = ff_filter_frame(outlink, frame);
554 
555  if (ret < 0)
556  return ret;
557  return pkt_out_id == out_id;
558 }
559 
560 static int movie_request_frame(AVFilterLink *outlink)
561 {
562  AVFilterContext *ctx = outlink->src;
563  unsigned out_id = FF_OUTLINK_IDX(outlink);
564  int ret;
565 
566  while (1) {
567  ret = movie_push_frame(ctx, out_id);
568  if (ret)
569  return FFMIN(ret, 0);
570  }
571 }
572 
573 #if CONFIG_MOVIE_FILTER
574 
575 AVFILTER_DEFINE_CLASS(movie);
576 
577 AVFilter ff_avsrc_movie = {
578  .name = "movie",
579  .description = NULL_IF_CONFIG_SMALL("Read from a movie source."),
580  .priv_size = sizeof(MovieContext),
581  .priv_class = &movie_class,
583  .uninit = movie_uninit,
585 
586  .inputs = NULL,
587  .outputs = NULL,
589 };
590 
591 #endif /* CONFIG_MOVIE_FILTER */
592 
593 #if CONFIG_AMOVIE_FILTER
594 
595 #define amovie_options movie_options
596 AVFILTER_DEFINE_CLASS(amovie);
597 
598 AVFilter ff_avsrc_amovie = {
599  .name = "amovie",
600  .description = NULL_IF_CONFIG_SMALL("Read audio from a movie source."),
601  .priv_size = sizeof(MovieContext),
603  .uninit = movie_uninit,
605 
606  .inputs = NULL,
607  .outputs = NULL,
608  .priv_class = &amovie_class,
610 };
611 
612 #endif /* CONFIG_AMOVIE_FILTER */
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:2277
#define NULL
Definition: coverity.c:32
static AVStream * find_stream(void *log, AVFormatContext *avf, const char *spec)
Definition: src_movie.c:93
const struct AVCodec * codec
Definition: avcodec.h:1511
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:280
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
AVOption.
Definition: opt.h:255
static av_cold void movie_uninit(AVFilterContext *ctx)
Definition: src_movie.c:316
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
Main libavfilter public API header.
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: utils.c:405
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
AVStream * st
Definition: src_movie.c:49
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:843
int size
Definition: avcodec.h:1424
static const AVOption movie_options[]
Definition: src_movie.c:76
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1722
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:74
#define FF_OUTLINK_IDX(link)
Definition: internal.h:349
enum AVMediaType type
Definition: avcodec.h:3485
discard all
Definition: avcodec.h:689
static AVPacket pkt
char * stream_specs
user-provided list of streams, separated by +
Definition: src_movie.c:60
AVCodec.
Definition: avcodec.h:3472
char * file_name
Definition: src_movie.c:59
Macro definitions for various function/variable attributes.
AVPacket pkt0
Definition: src_movie.c:66
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
Format I/O context.
Definition: avformat.h:1273
double seek_point_d
Definition: src_movie.c:57
const char * name
Pad name.
Definition: internal.h:69
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:417
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1158
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:647
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2270
static int nb_streams
Definition: ffprobe.c:226
#define av_cold
Definition: attributes.h:74
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:135
int(* request_frame)(AVFilterLink *link)
Frame request callback.
Definition: internal.h:122
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:337
AVOptions.
timestamp utils, mostly useful for debugging/logging purposes
libavcodec/libavfilter gluing utilities
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:4309
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:257
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1341
static AVFrame * frame
uint8_t * data
Definition: avcodec.h:1423
#define ff_dlog(a,...)
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition: avfilter.h:437
int64_t av_frame_get_best_effort_timestamp(const AVFrame *frame)
Accessors for some AVFrame fields.
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:63
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:3572
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
Definition: utils.c:2902
int width
width and height of the video frame
Definition: frame.h:220
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
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: utils.c:2408
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
#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
unsigned nb_outputs
number of output pads
Definition: avfilter.h:652
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
void * priv
private data for use by the filter
Definition: avfilter.h:654
simple assert() macros that are a bit more flexible than ISO C assert().
#define FFMAX(a, b)
Definition: common.h:79
static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
Definition: src_movie.c:168
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2323
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:861
#define FLAGS
Definition: src_movie.c:74
common internal API header
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1329
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition: format.c:160
#define FFMIN(a, b)
Definition: common.h:81
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:422
int width
picture width / height.
Definition: avcodec.h:1681
int loop_count
Definition: src_movie.c:62
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
static int movie_config_output_props(AVFilterLink *outlink)
Definition: src_movie.c:364
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: utils.c:2558
char * format_name
Definition: src_movie.c:58
int refcounted_frames
If non-zero, the decoded audio and video frames returned from avcodec_decode_video2() and avcodec_dec...
Definition: avcodec.h:2536
int max_stream_index
max stream # actually used for output
Definition: src_movie.c:68
static av_cold int movie_common_init(AVFilterContext *ctx)
Definition: src_movie.c:191
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.
Stream structure.
Definition: avformat.h:842
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal decoder state / flush internal buffers.
Definition: utils.c:3303
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:232
int * out_index
stream number -> output number map, or -1
Definition: src_movie.c:70
static AVInputFormat * iformat
Definition: ffprobe.c:214
enum AVMediaType codec_type
Definition: avcodec.h:1510
AVFilterChannelLayouts * avfilter_make_format64_list(const int64_t *fmts)
Definition: formats.c:292
enum AVCodecID codec_id
Definition: avcodec.h:1519
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:267
int sample_rate
samples per second
Definition: avcodec.h:2262
main external API structure.
Definition: avcodec.h:1502
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:3016
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:252
void * buf
Definition: avisynth_c.h:553
GLint GLenum type
Definition: opengl_enc.c:105
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
int64_t seek_point
seekpoint in microseconds
Definition: src_movie.c:56
static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
Try to push a frame to the requested output.
Definition: src_movie.c:447
AVMediaType
Definition: avutil.h:191
discard useless packets like 0 size packets in avi
Definition: avcodec.h:684
const char * name
Filter name.
Definition: avfilter.h:474
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:1349
#define snprintf
Definition: snprintf.h:34
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: utils.c:1478
static char * describe_frame_to_str(char *dst, size_t dst_size, AVFrame *frame, enum AVMediaType frame_type, AVFilterLink *link)
Definition: src_movie.c:387
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
Definition: mem.c:260
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:79
static int flags
Definition: cpu.c:47
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds. ...
Definition: avformat.h:1358
int stream_index
for compatibility
Definition: src_movie.c:61
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
Definition: utils.c:2199
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
#define OFFSET(x)
Definition: src_movie.c:73
static int movie_request_frame(AVFilterLink *outlink)
Definition: src_movie.c:560
Main libavformat public API header.
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
static int open_stream(void *log, MovieStream *st)
Definition: src_movie.c:147
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition: utils.c:3084
static double c[64]
static AVCodecContext * dec_ctx
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:49
int den
denominator
Definition: rational.h:45
AVPacket pkt
Definition: src_movie.c:66
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: utils.c:3721
static int movie_query_formats(AVFilterContext *ctx)
Definition: src_movie.c:332
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
int channels
number of audio channels
Definition: avcodec.h:2263
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:334
static int rewind_file(AVFilterContext *ctx)
Definition: src_movie.c:413
AVFormatContext * format_ctx
Definition: src_movie.c:64
An instance of a filter.
Definition: avfilter.h:633
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
int height
Definition: frame.h:220
#define av_freep(p)
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:138
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:2050
int stream_index
Definition: avcodec.h:1425
internal API functions
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:884
int dummy
Definition: motion-test.c:64
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:907
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:1061
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
Definition: internal.h:285
This structure stores compressed data.
Definition: avcodec.h:1400
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
Definition: allformats.c:51
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:225
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:636
for(j=16;j >0;--j)
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:240
const char * name
Definition: opengl_enc.c:103
MovieStream * st
array of all streams, one per output
Definition: src_movie.c:69