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 "avfilter.h"
43 #include "formats.h"
44 #include "internal.h"
45 #include "video.h"
46 
47 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->codecpar->codec_type != AVMEDIA_TYPE_VIDEO &&
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->codecpar->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->codec_ctx = avcodec_alloc_context3(codec);
159  if (!st->codec_ctx)
160  return AVERROR(ENOMEM);
161 
163  if (ret < 0)
164  return ret;
165 
166  st->codec_ctx->refcounted_frames = 1;
167 
168  if ((ret = avcodec_open2(st->codec_ctx, codec, NULL)) < 0) {
169  av_log(log, AV_LOG_ERROR, "Failed to open codec\n");
170  return ret;
171  }
172 
173  return 0;
174 }
175 
176 static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
177 {
178  AVCodecParameters *dec_par = st->st->codecpar;
179  char buf[256];
180  int64_t chl = av_get_default_channel_layout(dec_par->channels);
181 
182  if (!chl) {
183  av_log(log_ctx, AV_LOG_ERROR,
184  "Channel layout is not set in stream %d, and could not "
185  "be guessed from the number of channels (%d)\n",
186  st_index, dec_par->channels);
187  return AVERROR(EINVAL);
188  }
189 
190  av_get_channel_layout_string(buf, sizeof(buf), dec_par->channels, chl);
191  av_log(log_ctx, AV_LOG_WARNING,
192  "Channel layout is not set in output stream %d, "
193  "guessed channel layout is '%s'\n",
194  st_index, buf);
195  dec_par->channel_layout = chl;
196  return 0;
197 }
198 
200 {
201  MovieContext *movie = ctx->priv;
203  int64_t timestamp;
204  int nb_streams = 1, ret, i;
205  char default_streams[16], *stream_specs, *spec, *cursor;
206  char name[16];
207  AVStream *st;
208 
209  if (!movie->file_name) {
210  av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
211  return AVERROR(EINVAL);
212  }
213 
214  movie->seek_point = movie->seek_point_d * 1000000 + 0.5;
215 
216  stream_specs = movie->stream_specs;
217  if (!stream_specs) {
218  snprintf(default_streams, sizeof(default_streams), "d%c%d",
219  !strcmp(ctx->filter->name, "amovie") ? 'a' : 'v',
220  movie->stream_index);
221  stream_specs = default_streams;
222  }
223  for (cursor = stream_specs; *cursor; cursor++)
224  if (*cursor == '+')
225  nb_streams++;
226 
227  if (movie->loop_count != 1 && nb_streams != 1) {
228  av_log(ctx, AV_LOG_ERROR,
229  "Loop with several streams is currently unsupported\n");
230  return AVERROR_PATCHWELCOME;
231  }
232 
233  av_register_all();
234 
235  // Try to find the movie format (container)
236  iformat = movie->format_name ? av_find_input_format(movie->format_name) : NULL;
237 
238  movie->format_ctx = NULL;
239  if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, NULL)) < 0) {
240  av_log(ctx, AV_LOG_ERROR,
241  "Failed to avformat_open_input '%s'\n", movie->file_name);
242  return ret;
243  }
244  if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0)
245  av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n");
246 
247  // if seeking requested, we execute it
248  if (movie->seek_point > 0) {
249  timestamp = movie->seek_point;
250  // add the stream start time, should it exist
251  if (movie->format_ctx->start_time != AV_NOPTS_VALUE) {
252  if (timestamp > 0 && movie->format_ctx->start_time > INT64_MAX - timestamp) {
253  av_log(ctx, AV_LOG_ERROR,
254  "%s: seek value overflow with start_time:%"PRId64" seek_point:%"PRId64"\n",
255  movie->file_name, movie->format_ctx->start_time, movie->seek_point);
256  return AVERROR(EINVAL);
257  }
258  timestamp += movie->format_ctx->start_time;
259  }
260  if ((ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD)) < 0) {
261  av_log(ctx, AV_LOG_ERROR, "%s: could not seek to position %"PRId64"\n",
262  movie->file_name, timestamp);
263  return ret;
264  }
265  }
266 
267  for (i = 0; i < movie->format_ctx->nb_streams; i++)
268  movie->format_ctx->streams[i]->discard = AVDISCARD_ALL;
269 
270  movie->st = av_calloc(nb_streams, sizeof(*movie->st));
271  if (!movie->st)
272  return AVERROR(ENOMEM);
273 
274  for (i = 0; i < nb_streams; i++) {
275  spec = av_strtok(stream_specs, "+", &cursor);
276  if (!spec)
277  return AVERROR_BUG;
278  stream_specs = NULL; /* for next strtok */
279  st = find_stream(ctx, movie->format_ctx, spec);
280  if (!st)
281  return AVERROR(EINVAL);
283  movie->st[i].st = st;
284  movie->max_stream_index = FFMAX(movie->max_stream_index, st->index);
285  }
286  if (av_strtok(NULL, "+", &cursor))
287  return AVERROR_BUG;
288 
289  movie->out_index = av_calloc(movie->max_stream_index + 1,
290  sizeof(*movie->out_index));
291  if (!movie->out_index)
292  return AVERROR(ENOMEM);
293  for (i = 0; i <= movie->max_stream_index; i++)
294  movie->out_index[i] = -1;
295  for (i = 0; i < nb_streams; i++) {
296  AVFilterPad pad = { 0 };
297  movie->out_index[movie->st[i].st->index] = i;
298  snprintf(name, sizeof(name), "out%d", i);
299  pad.type = movie->st[i].st->codecpar->codec_type;
300  pad.name = av_strdup(name);
301  if (!pad.name)
302  return AVERROR(ENOMEM);
305  ff_insert_outpad(ctx, i, &pad);
306  ret = open_stream(ctx, &movie->st[i]);
307  if (ret < 0)
308  return ret;
309  if ( movie->st[i].st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
310  !movie->st[i].st->codecpar->channel_layout) {
311  ret = guess_channel_layout(&movie->st[i], i, ctx);
312  if (ret < 0)
313  return ret;
314  }
315  }
316 
317  av_log(ctx, AV_LOG_VERBOSE, "seek_point:%"PRIi64" format_name:%s file_name:%s stream_index:%d\n",
318  movie->seek_point, movie->format_name, movie->file_name,
319  movie->stream_index);
320 
321  return 0;
322 }
323 
325 {
326  MovieContext *movie = ctx->priv;
327  int i;
328 
329  for (i = 0; i < ctx->nb_outputs; i++) {
330  av_freep(&ctx->output_pads[i].name);
331  if (movie->st[i].st)
332  avcodec_free_context(&movie->st[i].codec_ctx);
333  }
334  av_freep(&movie->st);
335  av_freep(&movie->out_index);
336  if (movie->format_ctx)
338 }
339 
341 {
342  MovieContext *movie = ctx->priv;
343  int list[] = { 0, -1 };
344  int64_t list64[] = { 0, -1 };
345  int i, ret;
346 
347  for (i = 0; i < ctx->nb_outputs; i++) {
348  MovieStream *st = &movie->st[i];
349  AVCodecParameters *c = st->st->codecpar;
350  AVFilterLink *outlink = ctx->outputs[i];
351 
352  switch (c->codec_type) {
353  case AVMEDIA_TYPE_VIDEO:
354  list[0] = c->format;
355  if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_formats)) < 0)
356  return ret;
357  break;
358  case AVMEDIA_TYPE_AUDIO:
359  list[0] = c->format;
360  if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_formats)) < 0)
361  return ret;
362  list[0] = c->sample_rate;
363  if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_samplerates)) < 0)
364  return ret;
365  list64[0] = c->channel_layout;
367  &outlink->in_channel_layouts)) < 0)
368  return ret;
369  break;
370  }
371  }
372 
373  return 0;
374 }
375 
377 {
378  AVFilterContext *ctx = outlink->src;
379  MovieContext *movie = ctx->priv;
380  unsigned out_id = FF_OUTLINK_IDX(outlink);
381  MovieStream *st = &movie->st[out_id];
382  AVCodecParameters *c = st->st->codecpar;
383 
384  outlink->time_base = st->st->time_base;
385 
386  switch (c->codec_type) {
387  case AVMEDIA_TYPE_VIDEO:
388  outlink->w = c->width;
389  outlink->h = c->height;
390  outlink->frame_rate = st->st->r_frame_rate;
391  break;
392  case AVMEDIA_TYPE_AUDIO:
393  break;
394  }
395 
396  return 0;
397 }
398 
399 static char *describe_frame_to_str(char *dst, size_t dst_size,
400  AVFrame *frame, enum AVMediaType frame_type,
401  AVFilterLink *link)
402 {
403  switch (frame_type) {
404  case AVMEDIA_TYPE_VIDEO:
405  snprintf(dst, dst_size,
406  "video pts:%s time:%s size:%dx%d aspect:%d/%d",
407  av_ts2str(frame->pts), av_ts2timestr(frame->pts, &link->time_base),
408  frame->width, frame->height,
409  frame->sample_aspect_ratio.num,
410  frame->sample_aspect_ratio.den);
411  break;
412  case AVMEDIA_TYPE_AUDIO:
413  snprintf(dst, dst_size,
414  "audio pts:%s time:%s samples:%d",
415  av_ts2str(frame->pts), av_ts2timestr(frame->pts, &link->time_base),
416  frame->nb_samples);
417  break;
418  default:
419  snprintf(dst, dst_size, "%s BUG", av_get_media_type_string(frame_type));
420  break;
421  }
422  return dst;
423 }
424 
426 {
427  MovieContext *movie = ctx->priv;
428  int64_t timestamp = movie->seek_point;
429  int ret, i;
430 
431  if (movie->format_ctx->start_time != AV_NOPTS_VALUE)
432  timestamp += movie->format_ctx->start_time;
433  ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD);
434  if (ret < 0) {
435  av_log(ctx, AV_LOG_ERROR, "Unable to loop: %s\n", av_err2str(ret));
436  movie->loop_count = 1; /* do not try again */
437  return ret;
438  }
439 
440  for (i = 0; i < ctx->nb_outputs; i++) {
442  movie->st[i].done = 0;
443  }
444  movie->eof = 0;
445  return 0;
446 }
447 
448 /**
449  * Try to push a frame to the requested output.
450  *
451  * @param ctx filter context
452  * @param out_id number of output where a frame is wanted;
453  * if the frame is read from file, used to set the return value;
454  * if the codec is being flushed, flush the corresponding stream
455  * @return 1 if a frame was pushed on the requested output,
456  * 0 if another attempt is possible,
457  * <0 AVERROR code
458  */
459 static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
460 {
461  MovieContext *movie = ctx->priv;
462  AVPacket *pkt = &movie->pkt;
463  enum AVMediaType frame_type;
464  MovieStream *st;
465  int ret, got_frame = 0, pkt_out_id;
466  AVFilterLink *outlink;
467  AVFrame *frame;
468 
469  if (!pkt->size) {
470  if (movie->eof) {
471  if (movie->st[out_id].done) {
472  if (movie->loop_count != 1) {
473  ret = rewind_file(ctx);
474  if (ret < 0)
475  return ret;
476  movie->loop_count -= movie->loop_count > 1;
477  av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n");
478  return 0; /* retry */
479  }
480  return AVERROR_EOF;
481  }
482  pkt->stream_index = movie->st[out_id].st->index;
483  /* packet is already ready for flushing */
484  } else {
485  ret = av_read_frame(movie->format_ctx, &movie->pkt0);
486  if (ret < 0) {
487  av_init_packet(&movie->pkt0); /* ready for flushing */
488  *pkt = movie->pkt0;
489  if (ret == AVERROR_EOF) {
490  movie->eof = 1;
491  return 0; /* start flushing */
492  }
493  return ret;
494  }
495  *pkt = movie->pkt0;
496  }
497  }
498 
499  pkt_out_id = pkt->stream_index > movie->max_stream_index ? -1 :
500  movie->out_index[pkt->stream_index];
501  if (pkt_out_id < 0) {
502  av_packet_unref(&movie->pkt0);
503  pkt->size = 0; /* ready for next run */
504  pkt->data = NULL;
505  return 0;
506  }
507  st = &movie->st[pkt_out_id];
508  outlink = ctx->outputs[pkt_out_id];
509 
510  frame = av_frame_alloc();
511  if (!frame)
512  return AVERROR(ENOMEM);
513 
514  frame_type = st->st->codecpar->codec_type;
515  switch (frame_type) {
516  case AVMEDIA_TYPE_VIDEO:
517  ret = avcodec_decode_video2(st->codec_ctx, frame, &got_frame, pkt);
518  break;
519  case AVMEDIA_TYPE_AUDIO:
520  ret = avcodec_decode_audio4(st->codec_ctx, frame, &got_frame, pkt);
521  break;
522  default:
523  ret = AVERROR(ENOSYS);
524  break;
525  }
526  if (ret < 0) {
527  av_log(ctx, AV_LOG_WARNING, "Decode error: %s\n", av_err2str(ret));
528  av_frame_free(&frame);
529  av_packet_unref(&movie->pkt0);
530  movie->pkt.size = 0;
531  movie->pkt.data = NULL;
532  return 0;
533  }
534  if (!ret || st->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
535  ret = pkt->size;
536 
537  pkt->data += ret;
538  pkt->size -= ret;
539  if (pkt->size <= 0) {
540  av_packet_unref(&movie->pkt0);
541  pkt->size = 0; /* ready for next run */
542  pkt->data = NULL;
543  }
544  if (!got_frame) {
545  if (!ret)
546  st->done = 1;
547  av_frame_free(&frame);
548  return 0;
549  }
550 
551  frame->pts = av_frame_get_best_effort_timestamp(frame);
552  ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
553  describe_frame_to_str((char[1024]){0}, 1024, frame, frame_type, outlink));
554 
555  if (st->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
556  if (frame->format != outlink->format) {
557  av_log(ctx, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n",
558  av_get_pix_fmt_name(outlink->format),
560  );
561  av_frame_free(&frame);
562  return 0;
563  }
564  }
565  ret = ff_filter_frame(outlink, frame);
566 
567  if (ret < 0)
568  return ret;
569  return pkt_out_id == out_id;
570 }
571 
572 static int movie_request_frame(AVFilterLink *outlink)
573 {
574  AVFilterContext *ctx = outlink->src;
575  unsigned out_id = FF_OUTLINK_IDX(outlink);
576  int ret;
577 
578  while (1) {
579  ret = movie_push_frame(ctx, out_id);
580  if (ret)
581  return FFMIN(ret, 0);
582  }
583 }
584 
585 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
586  char *res, int res_len, int flags)
587 {
588  MovieContext *movie = ctx->priv;
589  int ret = AVERROR(ENOSYS);
590 
591  if (!strcmp(cmd, "seek")) {
592  int idx, flags, i;
593  int64_t ts;
594  char tail[2];
595 
596  if (sscanf(args, "%i|%"SCNi64"|%i %1s", &idx, &ts, &flags, tail) != 3)
597  return AVERROR(EINVAL);
598 
599  ret = av_seek_frame(movie->format_ctx, idx, ts, flags);
600  if (ret < 0)
601  return ret;
602 
603  for (i = 0; i < ctx->nb_outputs; i++) {
605  movie->st[i].done = 0;
606  }
607  return ret;
608  } else if (!strcmp(cmd, "get_duration")) {
609  int print_len;
610  char tail[2];
611 
612  if (!res || res_len <= 0)
613  return AVERROR(EINVAL);
614 
615  if (args && sscanf(args, "%1s", tail) == 1)
616  return AVERROR(EINVAL);
617 
618  print_len = snprintf(res, res_len, "%"PRId64, movie->format_ctx->duration);
619  if (print_len < 0 || print_len >= res_len)
620  return AVERROR(EINVAL);
621 
622  return 0;
623  }
624 
625  return ret;
626 }
627 
628 #if CONFIG_MOVIE_FILTER
629 
630 AVFILTER_DEFINE_CLASS(movie);
631 
632 AVFilter ff_avsrc_movie = {
633  .name = "movie",
634  .description = NULL_IF_CONFIG_SMALL("Read from a movie source."),
635  .priv_size = sizeof(MovieContext),
636  .priv_class = &movie_class,
638  .uninit = movie_uninit,
640 
641  .inputs = NULL,
642  .outputs = NULL,
645 };
646 
647 #endif /* CONFIG_MOVIE_FILTER */
648 
649 #if CONFIG_AMOVIE_FILTER
650 
651 #define amovie_options movie_options
652 AVFILTER_DEFINE_CLASS(amovie);
653 
654 AVFilter ff_avsrc_amovie = {
655  .name = "amovie",
656  .description = NULL_IF_CONFIG_SMALL("Read audio from a movie source."),
657  .priv_size = sizeof(MovieContext),
659  .uninit = movie_uninit,
661 
662  .inputs = NULL,
663  .outputs = NULL,
664  .priv_class = &amovie_class,
667 };
668 
669 #endif /* CONFIG_AMOVIE_FILTER */
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:2360
#define NULL
Definition: coverity.c:32
static AVStream * find_stream(void *log, AVFormatContext *avf, const char *spec)
Definition: src_movie.c:93
This structure describes decoded (raw) audio or video data.
Definition: frame.h:180
AVOption.
Definition: opt.h:245
AVFormatContext * ctx
Definition: movenc-test.c:48
static av_cold void movie_uninit(AVFilterContext *ctx)
Definition: src_movie.c:324
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
Main libavfilter public API header.
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
AVStream * st
Definition: src_movie.c:48
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3915
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:877
int size
Definition: avcodec.h:1578
static const AVOption movie_options[]
Definition: src_movie.c:76
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: utils.c:2274
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:64
#define FF_OUTLINK_IDX(link)
Definition: internal.h:354
discard all
Definition: avcodec.h:781
static AVPacket pkt
char * stream_specs
user-provided list of streams, separated by +
Definition: src_movie.c:60
AVCodec.
Definition: avcodec.h:3535
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3907
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:1319
double seek_point_d
Definition: src_movie.c:57
const char * name
Pad name.
Definition: internal.h:59
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:435
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1180
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:316
static int nb_streams
Definition: ffprobe.c:253
#define av_cold
Definition: attributes.h:82
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:140
int(* request_frame)(AVFilterLink *link)
Frame request callback.
Definition: internal.h:112
int width
Video only.
Definition: avcodec.h:3981
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:337
AVOptions.
timestamp utils, mostly useful for debugging/logging purposes
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:4623
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:264
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1387
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:4126
static AVFrame * frame
uint8_t * data
Definition: avcodec.h:1577
#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:109
int64_t av_frame_get_best_effort_timestamp(const AVFrame *frame)
Accessors for some AVFrame fields.
uint64_t channel_layout
Audio only.
Definition: avcodec.h:4017
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:53
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:3844
int width
width and height of the video frame
Definition: frame.h:232
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#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:153
#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:318
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
void * priv
private data for use by the filter
Definition: avfilter.h:320
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3911
simple assert() macros that are a bit more flexible than ISO C assert().
#define FFMAX(a, b)
Definition: common.h:94
static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
Definition: src_movie.c:176
#define FLAGS
Definition: src_movie.c:74
common internal API header
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1375
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:96
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:149
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
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:376
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:2573
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:386
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:199
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:876
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal decoder state / flush internal buffers.
Definition: utils.c:3342
#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:244
int * out_index
stream number -> output number map, or -1
Definition: src_movie.c:70
static AVInputFormat * iformat
Definition: ffprobe.c:230
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:376
AVFilterChannelLayouts * avfilter_make_format64_list(const int64_t *fmts)
Definition: formats.c:303
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: utils.c:2173
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
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:267
main external API structure.
Definition: avcodec.h:1642
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:3056
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:549
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: src_movie.c:585
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:259
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:142
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:459
AVMediaType
Definition: avutil.h:191
discard useless packets like 0 size packets in avi
Definition: avcodec.h:776
const char * name
Filter name.
Definition: avfilter.h:146
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:1208
#define snprintf
Definition: snprintf.h:34
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:317
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: utils.c:1631
static char * describe_frame_to_str(char *dst, size_t dst_size, AVFrame *frame, enum AVMediaType frame_type, AVFilterLink *link)
Definition: src_movie.c:399
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:1404
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:2357
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
int sample_rate
Audio only.
Definition: avcodec.h:4025
#define OFFSET(x)
Definition: src_movie.c:73
static int movie_request_frame(AVFilterLink *outlink)
Definition: src_movie.c:572
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:3266
static double c[64]
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:33
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:4014
static int movie_query_formats(AVFilterContext *ctx)
Definition: src_movie.c:340
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:339
static int rewind_file(AVFilterContext *ctx)
Definition: src_movie.c:425
AVCodecContext * codec_ctx
Definition: src_movie.c:49
AVFormatContext * format_ctx
Definition: src_movie.c:64
int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: utils.c:471
int channels
Audio only.
Definition: avcodec.h:4021
An instance of a filter.
Definition: avfilter.h:305
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1414
int height
Definition: frame.h:232
#define av_freep(p)
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:128
AVCodecParameters * codecpar
Definition: avformat.h:1006
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:2109
int stream_index
Definition: avcodec.h:1579
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:913
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:936
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:1101
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
Definition: internal.h:291
This structure stores compressed data.
Definition: avcodec.h:1554
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
Definition: allformats.c:44
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:237
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:308
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