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