FFmpeg
Loading...
Searching...
No Matches
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 support a PTS correction mechanism
27 */
28
29#include "config_components.h"
30
31#include <stdint.h>
32
34#include "libavutil/avstring.h"
36#include "libavutil/mem.h"
37#include "libavutil/opt.h"
38#include "libavutil/internal.h"
39
40#include "libavcodec/avcodec.h"
41
43
44#include "audio.h"
45#include "avfilter.h"
46#include "filters.h"
47#include "formats.h"
48#include "video.h"
49
59
60typedef struct MovieContext {
61 /* common A/V fields */
62 const AVClass *class;
63 int64_t seek_point; ///< seekpoint in microseconds
66 char *file_name;
67 char *stream_specs; /**< user-provided list of streams, separated by + */
68 int stream_index; /**< for compatibility */
73
76
77 int eof;
78 int max_stream_index; /**< max stream # actually used for output */
79 MovieStream *st; /**< array of all streams, one per output */
80 int *out_index; /**< stream number -> output number map, or -1 */
83
84#define OFFSET(x) offsetof(MovieContext, x)
85#define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM
86
87static const AVOption movie_options[]= {
88 { "filename", NULL, OFFSET(file_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
89 { "format_name", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
90 { "f", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
91 { "stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
92 { "si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
93 { "seek_point", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, (INT64_MAX-1) / 1000000, FLAGS },
94 { "sp", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, (INT64_MAX-1) / 1000000, FLAGS },
95 { "streams", "set streams", OFFSET(stream_specs), AV_OPT_TYPE_STRING, {.str = 0}, 0, 0, FLAGS },
96 { "s", "set streams", OFFSET(stream_specs), AV_OPT_TYPE_STRING, {.str = 0}, 0, 0, FLAGS },
97 { "loop", "set loop count", OFFSET(loop_count), AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, FLAGS },
98 { "discontinuity", "set discontinuity threshold", OFFSET(discontinuity_threshold), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, FLAGS },
99 { "dec_threads", "set the number of threads for decoding", OFFSET(dec_threads), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS },
100 { "format_opts", "set format options for the opened file", OFFSET(format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
101 { NULL },
102};
103
104static int movie_config_output_props(AVFilterLink *outlink);
105
106static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec)
107{
108 int i, ret, already = 0, stream_id = -1;
109 char type_char[2], dummy;
110 AVStream *found = NULL;
111 enum AVMediaType type;
112
113 ret = sscanf(spec, "d%1[av]%d%c", type_char, &stream_id, &dummy);
114 if (ret >= 1 && ret <= 2) {
115 type = type_char[0] == 'v' ? AVMEDIA_TYPE_VIDEO : AVMEDIA_TYPE_AUDIO;
116 ret = av_find_best_stream(avf, type, stream_id, -1, NULL, 0);
117 if (ret < 0) {
118 av_log(log, AV_LOG_ERROR, "No %s stream with index '%d' found\n",
119 av_get_media_type_string(type), stream_id);
120 return NULL;
121 }
122 return avf->streams[ret];
123 }
124 for (i = 0; i < avf->nb_streams; i++) {
125 ret = avformat_match_stream_specifier(avf, avf->streams[i], spec);
126 if (ret < 0) {
127 av_log(log, AV_LOG_ERROR,
128 "Invalid stream specifier \"%s\"\n", spec);
129 return NULL;
130 }
131 if (!ret)
132 continue;
133 if (avf->streams[i]->discard != AVDISCARD_ALL) {
134 already++;
135 continue;
136 }
137 if (found) {
139 "Ambiguous stream specifier \"%s\", using #%d\n", spec, i);
140 break;
141 }
142 found = avf->streams[i];
143 }
144 if (!found) {
145 av_log(log, AV_LOG_WARNING, "Stream specifier \"%s\" %s\n", spec,
146 already ? "matched only already used streams" :
147 "did not match any stream");
148 return NULL;
149 }
150 if (found->codecpar->codec_type != AVMEDIA_TYPE_VIDEO &&
152 av_log(log, AV_LOG_ERROR, "Stream specifier \"%s\" matched a %s stream,"
153 "currently unsupported by libavfilter\n", spec,
155 return NULL;
156 }
157 return found;
158}
159
160static int get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
161{
162 int linesize_align[AV_NUM_DATA_POINTERS];
163 MovieStream *st = avctx->opaque;
164 AVFilterLink *outlink = st->link;
165 int w, h, ow, oh, copy = 0;
166 AVFrame *new;
167
168 h = oh = frame->height;
169 w = ow = frame->width;
170
171 copy = frame->format != outlink->format;
172 switch (avctx->codec_type) {
174 if (w != outlink->w || h != outlink->h)
175 copy |= 1;
176 break;
178 if (outlink->sample_rate != frame->sample_rate ||
179 av_channel_layout_compare(&outlink->ch_layout, &frame->ch_layout))
180 copy |= 1;
181 break;
182 }
183
184 if (copy || !(avctx->codec->capabilities & AV_CODEC_CAP_DR1))
186
187 switch (avctx->codec_type) {
189 avcodec_align_dimensions2(avctx, &w, &h, linesize_align);
190 new = ff_default_get_video_buffer(outlink, w, h);
191 break;
193 new = ff_default_get_audio_buffer(outlink, frame->nb_samples);
194 break;
195 default:
196 return -1;
197 }
198
202 av_frame_free(&new);
203
204 frame->width = ow;
205 frame->height = oh;
206
207 return 0;
208}
209
210static int open_stream(AVFilterContext *ctx, MovieStream *st, int dec_threads)
211{
212 const AVCodec *codec;
213 int ret;
214
216 if (!codec) {
217 av_log(ctx, AV_LOG_ERROR, "Failed to find any codec\n");
218 return AVERROR(EINVAL);
219 }
220
222 if (!st->codec_ctx)
223 return AVERROR(ENOMEM);
224
225 st->codec_ctx->opaque = st;
228 if (ret < 0)
229 return ret;
231
232 if (!dec_threads)
233 dec_threads = ff_filter_get_nb_threads(ctx);
234 st->codec_ctx->thread_count = dec_threads;
235
236 if ((ret = avcodec_open2(st->codec_ctx, codec, NULL)) < 0) {
237 av_log(ctx, AV_LOG_ERROR, "Failed to open codec\n");
238 return ret;
239 }
240
241 return 0;
242}
243
244static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
245{
246 AVCodecParameters *dec_par = st->st->codecpar;
247 char buf[256];
248 AVChannelLayout chl = { 0 };
249
251
252 if (!KNOWN(&chl)) {
253 av_log(log_ctx, AV_LOG_WARNING,
254 "Channel layout is not set in stream %d, and could not "
255 "be guessed from the number of channels (%d)\n",
256 st_index, dec_par->ch_layout.nb_channels);
257 return av_channel_layout_copy(&dec_par->ch_layout, &chl);
258 }
259
260 av_channel_layout_describe(&chl, buf, sizeof(buf));
261 av_log(log_ctx, AV_LOG_WARNING,
262 "Channel layout is not set in output stream %d, "
263 "guessed channel layout is '%s'\n",
264 st_index, buf);
265 return av_channel_layout_copy(&dec_par->ch_layout, &chl);
266}
267
269{
270 MovieContext *movie = ctx->priv;
271 const AVInputFormat *iformat = NULL;
272 int64_t timestamp;
273 int nb_streams = 1, ret, i;
274 char default_streams[16], *stream_specs, *spec, *cursor;
275 AVStream *st;
276
277 if (!movie->file_name) {
278 av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
279 return AVERROR(EINVAL);
280 }
281
282 movie->seek_point = movie->seek_point_d * 1000000 + 0.5;
283
284 stream_specs = movie->stream_specs;
285 if (!stream_specs) {
286 snprintf(default_streams, sizeof(default_streams), "d%c%d",
287 !strcmp(ctx->filter->name, "amovie") ? 'a' : 'v',
288 movie->stream_index);
289 stream_specs = default_streams;
290 }
291 for (cursor = stream_specs; *cursor; cursor++)
292 if (*cursor == '+')
293 nb_streams++;
294
295 if (movie->loop_count != 1 && nb_streams != 1) {
297 "Loop with several streams is currently unsupported\n");
299 }
300
301 // Try to find the movie format (container)
303
304 movie->format_ctx = NULL;
305 if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, &movie->format_opts)) < 0) {
307 "Failed to avformat_open_input '%s'\n", movie->file_name);
308 return ret;
309 }
310 if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0)
311 av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n");
312
313 // if seeking requested, we execute it
314 if (movie->seek_point > 0) {
315 timestamp = movie->seek_point;
316 // add the stream start time, should it exist
317 if (movie->format_ctx->start_time != AV_NOPTS_VALUE) {
318 if (timestamp > 0 && movie->format_ctx->start_time > INT64_MAX - timestamp) {
320 "%s: seek value overflow with start_time:%"PRId64" seek_point:%"PRId64"\n",
321 movie->file_name, movie->format_ctx->start_time, movie->seek_point);
322 return AVERROR(EINVAL);
323 }
324 timestamp += movie->format_ctx->start_time;
325 }
326 if ((ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD)) < 0) {
327 av_log(ctx, AV_LOG_ERROR, "%s: could not seek to position %"PRId64"\n",
328 movie->file_name, timestamp);
329 return ret;
330 }
331 }
332
333 for (i = 0; i < movie->format_ctx->nb_streams; i++)
335
336 movie->pkt = av_packet_alloc();
337 if (!movie->pkt)
338 return AVERROR(ENOMEM);
339 movie->st = av_calloc(nb_streams, sizeof(*movie->st));
340 if (!movie->st)
341 return AVERROR(ENOMEM);
342
343 for (i = 0; i < nb_streams; i++) {
344 spec = av_strtok(stream_specs, "+", &cursor);
345 if (!spec)
346 return AVERROR_BUG;
347 stream_specs = NULL; /* for next strtok */
348 st = find_stream(ctx, movie->format_ctx, spec);
349 if (!st)
350 return AVERROR(EINVAL);
352 movie->st[i].st = st;
353 movie->max_stream_index = FFMAX(movie->max_stream_index, st->index);
356
357 movie->st[i].frame = av_frame_alloc();
358 if (!movie->st[i].frame)
359 return AVERROR(ENOMEM);
360 }
361 if (av_strtok(NULL, "+", &cursor))
362 return AVERROR_BUG;
363
364 movie->out_index = av_calloc(movie->max_stream_index + 1,
365 sizeof(*movie->out_index));
366 if (!movie->out_index)
367 return AVERROR(ENOMEM);
368 for (i = 0; i <= movie->max_stream_index; i++)
369 movie->out_index[i] = -1;
370 for (i = 0; i < nb_streams; i++) {
371 AVFilterPad pad = { 0 };
372 movie->out_index[movie->st[i].st->index] = i;
373 pad.type = movie->st[i].st->codecpar->codec_type;
374 pad.name = av_asprintf("out%d", i);
375 if (!pad.name)
376 return AVERROR(ENOMEM);
378 if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0)
379 return ret;
380 if ( movie->st[i].st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
381 !KNOWN(&movie->st[i].st->codecpar->ch_layout)) {
382 ret = guess_channel_layout(&movie->st[i], i, ctx);
383 if (ret < 0)
384 return ret;
385 }
386 ret = open_stream(ctx, &movie->st[i], movie->dec_threads);
387 if (ret < 0)
388 return ret;
389 }
390
391 av_log(ctx, AV_LOG_VERBOSE, "seek_point:%"PRIi64" format_name:%s file_name:%s stream_index:%d\n",
392 movie->seek_point, movie->format_name, movie->file_name,
393 movie->stream_index);
394
395 return 0;
396}
397
399{
400 MovieContext *movie = ctx->priv;
401 int i;
402
403 for (i = 0; i < ctx->nb_outputs; i++) {
404 if (movie->st[i].st)
406 av_frame_free(&movie->st[i].frame);
407 }
408 av_packet_free(&movie->pkt);
409 av_freep(&movie->st);
410 av_freep(&movie->out_index);
411 if (movie->format_ctx)
413}
414
416 AVFilterFormatsConfig **cfg_in,
417 AVFilterFormatsConfig **cfg_out)
418{
419 const MovieContext *movie = ctx->priv;
420 int list[] = { 0, -1 };
421 AVChannelLayout list64[] = { { 0 }, { 0 } };
422 int i, ret;
423
424 for (i = 0; i < ctx->nb_outputs; i++) {
425 const MovieStream *st = &movie->st[i];
426 const AVCodecParameters *c = st->st->codecpar;
427 AVFilterFormatsConfig *cfg = cfg_out[i];
428
429 switch (c->codec_type) {
431 list[0] = c->format;
432 if ((ret = ff_formats_ref(ff_make_format_list(list), &cfg->formats)) < 0)
433 return ret;
434 list[0] = c->color_space;
435 if ((ret = ff_formats_ref(ff_make_format_list(list), &cfg->color_spaces)) < 0)
436 return ret;
437 list[0] = c->color_range;
438 if ((ret = ff_formats_ref(ff_make_format_list(list), &cfg->color_ranges)) < 0)
439 return ret;
440 break;
442 list[0] = c->format;
443 if ((ret = ff_formats_ref(ff_make_format_list(list), &cfg->formats)) < 0)
444 return ret;
445 list[0] = c->sample_rate;
446 if ((ret = ff_formats_ref(ff_make_format_list(list), &cfg->samplerates)) < 0)
447 return ret;
448 list64[0] = c->ch_layout;
450 &cfg->channel_layouts)) < 0)
451 return ret;
452 break;
453 }
454 }
455
456 return 0;
457}
458
460{
461 FilterLink *l = ff_filter_link(outlink);
462 AVFilterContext *ctx = outlink->src;
463 MovieContext *movie = ctx->priv;
464 unsigned out_id = FF_OUTLINK_IDX(outlink);
465 MovieStream *st = &movie->st[out_id];
467
468 outlink->time_base = st->st->time_base;
469
470 switch (c->codec_type) {
472 outlink->w = c->width;
473 outlink->h = c->height;
474 l->frame_rate = st->st->r_frame_rate;
475 break;
477 break;
478 }
479
480 st->link = outlink;
481
482 return 0;
483}
484
486{
487 MovieContext *movie = ctx->priv;
488 int64_t timestamp = movie->seek_point;
489 int ret, i;
490
491 if (movie->format_ctx->start_time != AV_NOPTS_VALUE)
492 timestamp += movie->format_ctx->start_time;
493 ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD);
494 if (ret < 0) {
495 av_log(ctx, AV_LOG_ERROR, "Unable to loop: %s\n", av_err2str(ret));
496 movie->loop_count = 1; /* do not try again */
497 return ret;
498 }
499
500 for (i = 0; i < ctx->nb_outputs; i++) {
502 }
503 return 0;
504}
505
507{
508 MovieContext *movie = ctx->priv;
509 AVCodecContext *dec = movie->st[i].codec_ctx;
510
511 return avcodec_send_packet(dec, NULL);
512}
513
515{
516 AVFilterLink *outlink = ctx->outputs[i];
517 MovieContext *movie = ctx->priv;
518 MovieStream *st = &movie->st[i];
519 AVCodecContext *dec = movie->st[i].codec_ctx;
520 AVFrame *frame = movie->st[i].frame;
521 AVPacket *pkt = movie->pkt;
522 int ret = 0;
523
524 // do not output more than 1 frame per iteration,
525 // so try to receive_frame first
526 ret = avcodec_receive_frame(dec, frame);
527 if (!movie->eof && ret == AVERROR(EAGAIN)) {
528 ret = avcodec_send_packet(dec, pkt);
530 if (ret < 0)
531 return ret;
532 ret = avcodec_receive_frame(dec, frame);
533 }
534 if (ret < 0) {
535 // those two return values are special and mean there is no output
536 // frame available, but there were no errors during decoding
537 if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN))
538 return 0;
539 return ret;
540 }
541
542 // output a single frame
543 if (ret >= 0) {
544 frame->pts = frame->best_effort_timestamp;
545 if (frame->pts != AV_NOPTS_VALUE) {
546 if (movie->ts_offset)
548 if (st->discontinuity_threshold) {
549 if (st->last_pts != AV_NOPTS_VALUE) {
550 int64_t diff = frame->pts - st->last_pts;
552 av_log(ctx, AV_LOG_VERBOSE, "Discontinuity in stream:%d diff:%"PRId64"\n", i, diff);
554 frame->pts -= diff;
555 }
556 }
557 }
558 st->last_pts = frame->pts;
559 }
560 ret = ff_filter_frame(outlink, av_frame_clone(frame));
561 if (ret < 0)
562 return ret;
563 if (ret == 0)
564 return 1;
565 }
566
567 return 0;
568}
569
571{
572 MovieContext *movie = ctx->priv;
573 int wanted = 0, ret = 0;
574
575 for (int i = 0; i < ctx->nb_outputs; i++) {
576 if (ff_outlink_frame_wanted(ctx->outputs[i]))
577 wanted++;
578 }
579
580 if (wanted == 0)
581 return FFERROR_NOT_READY;
582
583 if (!movie->eof) {
584 if (!movie->pkt->buf)
585 ret = av_read_frame(movie->format_ctx, movie->pkt);
586 if (ret < 0) {
587 movie->eof = 1;
588 for (int i = 0; i < ctx->nb_outputs; i++)
591 return 0;
592 } else {
593 int pkt_out_id = movie->pkt->stream_index > movie->max_stream_index ? -1 :
594 movie->out_index[movie->pkt->stream_index];
595
596 if (pkt_out_id >= 0) {
597 ret = decode_packet(ctx, pkt_out_id);
598 } else {
599 av_packet_unref(movie->pkt);
600 }
602 return (ret <= 0) ? ret : 0;
603 }
604 } else {
605 int nb_eofs = 0;
606
607 for (int i = 0; i < ctx->nb_outputs; i++) {
608 if (!movie->st[i].eof) {
609 ret = decode_packet(ctx, i);
610 if (ret <= 0)
611 movie->st[i].eof = 1;
612 }
613 nb_eofs += movie->st[i].eof == 1;
614 }
615 if (nb_eofs == ctx->nb_outputs && movie->loop_count != 1) {
616 ret = rewind_file(ctx);
617 if (ret < 0)
618 return ret;
619 movie->loop_count -= movie->loop_count > 1;
620 av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n");
622 for (int i = 0; i < ctx->nb_outputs; i++)
623 movie->st[i].eof = 0;
624 movie->eof = 0;
625 return 0;
626 } else {
627 for (int i = 0; i < ctx->nb_outputs; i++) {
628 if (movie->st[i].eof) {
629 ff_outlink_set_status(ctx->outputs[i], AVERROR_EOF, movie->st[i].last_pts);
630 nb_eofs++;
631 }
632 }
633 }
634
635 if (nb_eofs < ctx->nb_outputs)
637 return 0;
638 }
639
640 return FFERROR_NOT_READY;
641}
642
643static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
644 char *res, int res_len, int flags)
645{
646 MovieContext *movie = ctx->priv;
647 int ret = AVERROR(ENOSYS);
648
649 if (!strcmp(cmd, "seek")) {
650 int idx, flags, i;
651 int64_t ts;
652 char tail[2];
653
654 if (sscanf(args, "%i|%"SCNi64"|%i %1s", &idx, &ts, &flags, tail) != 3)
655 return AVERROR(EINVAL);
656
657 ret = av_seek_frame(movie->format_ctx, idx, ts, flags);
658 if (ret < 0)
659 return ret;
660
661 for (i = 0; i < ctx->nb_outputs; i++) {
663 }
664 return ret;
665 } else if (!strcmp(cmd, "get_duration")) {
666 int print_len;
667 char tail[2];
668
669 if (!res || res_len <= 0)
670 return AVERROR(EINVAL);
671
672 if (args && sscanf(args, "%1s", tail) == 1)
673 return AVERROR(EINVAL);
674
675 print_len = snprintf(res, res_len, "%"PRId64, movie->format_ctx->duration);
676 if (print_len < 0 || print_len >= res_len)
677 return AVERROR(EINVAL);
678
679 return 0;
680 }
681
682 return ret;
683}
684
686
687#if CONFIG_MOVIE_FILTER
688
689const FFFilter ff_avsrc_movie = {
690 .p.name = "movie",
691 .p.description = NULL_IF_CONFIG_SMALL("Read from a movie source."),
692 .p.priv_class = &movie_class,
694 .priv_size = sizeof(MovieContext),
699
700 .process_command = process_command
701};
702
703#endif /* CONFIG_MOVIE_FILTER */
704
705#if CONFIG_AMOVIE_FILTER
706
708 .p.name = "amovie",
709 .p.description = NULL_IF_CONFIG_SMALL("Read audio from a movie source."),
710 .p.priv_class = &movie_class,
712 .priv_size = sizeof(MovieContext),
717
718 .process_command = process_command,
719};
720
721#endif /* CONFIG_AMOVIE_FILTER */
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
const FFFilter ff_avsrc_amovie
const FFFilter ff_avsrc_movie
AVFrame * ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
default handler for get_audio_buffer() for audio inputs
Definition audio.c:46
Libavcodec external API header.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
Definition avfilter.c:1690
int ff_append_outpad_free_name(AVFilterContext *f, AVFilterPad *p)
Definition avfilter.c:143
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition avfilter.c:846
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition avfilter.c:229
Main libavfilter public API header.
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, const AVCodec **decoder_ret, int flags)
Definition avformat.c:505
Main libavformat public API header.
#define AVSEEK_FLAG_BACKWARD
seek backward
Definition avformat.h:2616
char * av_asprintf(const char *fmt,...)
Definition avstring.c:115
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
Public libavutil channel layout APIs header.
#define FLAGS
Definition cmdutils.c:598
AVDictionary * format_opts
Definition cmdutils.c:58
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Definition codec_par.c:206
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
static AVFrame * frame
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static CheckasmConfig cfg
Definition checkasm.c:74
static int get_buffer(AVCodecContext *dec_ctx, AVFrame *frame, int flags)
static int dummy
Definition ffplay.c:3754
static const AVInputFormat * iformat
Definition ffprobe.c:345
static unsigned int nb_streams
Definition ffprobe.c:352
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add ref as a new reference to formats.
Definition formats.c:756
AVFilterChannelLayouts * ff_make_channel_layout_list(const AVChannelLayout *fmts)
Definition formats.c:511
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition formats.c:751
av_warn_unused_result AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
#define KNOWN(l)
Definition formats.h:111
#define AV_NUM_DATA_POINTERS
Definition frame.h:473
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
Definition opt.h:318
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition opt.h:266
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
Definition opt.h:289
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition avcodec.c:144
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition options.c:149
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition allcodecs.c:990
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
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
Definition get_buffer.c:253
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Alias for avcodec_receive_frame_flags(avctx, frame, 0).
Definition avcodec.c:720
void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[AV_NUM_DATA_POINTERS])
Modify width and height values so that they will result in a memory buffer that is acceptable for the...
Definition utils.c:141
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition decode.c:730
@ AVDISCARD_ALL
discard all
Definition defs.h:232
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition defs.h:227
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal codec state / flush internal buffers.
Definition avcodec.c:389
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition packet.c:74
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:434
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition packet.c:63
const AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition format.c:146
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition demux.c:1588
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
Definition seek.c:641
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition demux.c:231
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition demux.c:2606
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition demux.c:377
int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the stream st contained in s is matched by the stream specifier spec.
Definition avformat.c:742
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition avfilter.h:161
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition error.h:52
#define AVERROR_EOF
End of file.
Definition error.h:57
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:496
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition frame.c:523
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition frame.c:483
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_ROUND_UP
Round toward +infinity.
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition utils.c:28
AVMediaType
Definition avutil.h:198
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
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:179
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition avutil.h:263
static int format_name(const char *buf, char **s, int index, const char *varname)
Definition hlsenc.c:1947
cl_device_type type
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition filters.h:629
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
Definition filters.h:34
#define AVFILTER_DEFINE_CLASS_EXT(name, desc, options)
Definition filters.h:470
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
#define FF_OUTLINK_IDX(link)
Definition filters.h:216
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
uint8_t w
Definition llvidencdsp.c:39
#define FFMAX(a, b)
Definition macros.h:47
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:264
Memory handling functions.
AVOptions.
#define snprintf
Definition snprintf.h:34
static int open_stream(AVFilterContext *ctx, MovieStream *st, int dec_threads)
Definition src_movie.c:210
static int movie_query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition src_movie.c:415
static AVStream * find_stream(void *log, AVFormatContext *avf, const char *spec)
Definition src_movie.c:106
static av_cold int movie_common_init(AVFilterContext *ctx)
Definition src_movie.c:268
static av_cold void movie_uninit(AVFilterContext *ctx)
Definition src_movie.c:398
static int get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Definition src_movie.c:160
static int movie_config_output_props(AVFilterLink *outlink)
Definition src_movie.c:459
static int rewind_file(AVFilterContext *ctx)
Definition src_movie.c:485
static const AVOption movie_options[]
Definition src_movie.c:87
static int flush_decoder(AVFilterContext *ctx, int i)
Definition src_movie.c:506
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition src_movie.c:643
static int activate(AVFilterContext *ctx)
Definition src_movie.c:570
static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
Definition src_movie.c:244
#define OFFSET(x)
Definition src_movie.c:84
static int decode_packet(AVFilterContext *ctx, int i)
Definition src_movie.c:514
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition avcodec.h:554
enum AVMediaType codec_type
Definition avcodec.h:451
const struct AVCodec * codec
Definition avcodec.h:452
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition avcodec.h:1579
void * opaque
Private data of the user, can be used to carry app specific stuff.
Definition avcodec.h:485
int(* get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags)
This callback is called at the beginning of each frame to get data buffer(s) for it.
Definition avcodec.h:1218
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
AVCodec.
Definition codec.h:175
int capabilities
Codec capabilities.
Definition codec.h:194
An instance of a filter.
Definition avfilter.h:273
Lists of formats / etc.
Definition avfilter.h:120
A filter pad used for either input or output.
Definition filters.h:40
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition filters.h:120
enum AVMediaType type
AVFilterPad type.
Definition filters.h:51
const char * name
Pad name.
Definition filters.h:46
Format I/O context.
Definition avformat.h:1333
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition avformat.h:1389
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds.
Definition avformat.h:1458
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1401
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition avformat.h:1468
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
int stream_index
Definition packet.h:605
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition packet.h:586
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition avformat.h:837
int index
stream index in AVFormatContext
Definition avformat.h:772
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:805
AVRational r_frame_rate
Real base framerate of the stream.
Definition avformat.h:900
AVDictionary * format_opts
Definition src_movie.c:81
int64_t seek_point
seekpoint in microseconds
Definition src_movie.c:63
int stream_index
for compatibility
Definition src_movie.c:68
AVFormatContext * format_ctx
Definition src_movie.c:75
int max_stream_index
max stream # actually used for output
Definition src_movie.c:78
AVPacket * pkt
Definition src_movie.c:74
double seek_point_d
Definition src_movie.c:64
char * file_name
Definition src_movie.c:66
char * format_name
Definition src_movie.c:65
char * stream_specs
user-provided list of streams, separated by +
Definition src_movie.c:67
int * out_index
stream number -> output number map, or -1
Definition src_movie.c:80
MovieStream * st
array of all streams, one per output
Definition src_movie.c:79
int64_t discontinuity_threshold
Definition src_movie.c:70
int64_t ts_offset
Definition src_movie.c:71
int dec_threads
Definition src_movie.c:72
int64_t last_pts
Definition src_movie.c:55
AVFilterLink * link
Definition src_movie.c:51
AVFrame * frame
Definition src_movie.c:56
AVStream * st
Definition src_movie.c:52
int64_t discontinuity_threshold
Definition src_movie.c:54
AVCodecContext * codec_ctx
Definition src_movie.c:53
#define av_freep(p)
#define av_log(a,...)
static AVFormatContext * ctx
Definition movenc.c:49
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
static void copy(const float *p1, float *p2, const int length)
AVFrame * ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
Definition video.c:84
static double c[64]