From 1138eb5509d3db7f6d565cb45f137a786d22beb9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 10 Feb 2016 14:17:21 +0100 Subject: vsrc_movie: convert to codecpar --- libavfilter/vsrc_movie.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index 850788c..95ef4f1 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -86,6 +86,7 @@ static av_cold int movie_init(AVFilterContext *ctx) { MovieContext *movie = ctx->priv; AVInputFormat *iformat = NULL; + AVStream *st; AVCodec *codec; int ret; int64_t timestamp; @@ -132,18 +133,26 @@ static av_cold int movie_init(AVFilterContext *ctx) return ret; } movie->stream_index = ret; - movie->codec_ctx = movie->format_ctx->streams[movie->stream_index]->codec; + st = movie->format_ctx->streams[movie->stream_index]; /* * So now we've got a pointer to the so-called codec context for our video * stream, but we still have to find the actual codec and open it. */ - codec = avcodec_find_decoder(movie->codec_ctx->codec_id); + codec = avcodec_find_decoder(st->codecpar->codec_id); if (!codec) { av_log(ctx, AV_LOG_ERROR, "Failed to find any codec\n"); return AVERROR(EINVAL); } + movie->codec_ctx = avcodec_alloc_context3(codec); + if (!movie->codec_ctx) + return AVERROR(ENOMEM); + + ret = avcodec_parameters_to_context(movie->codec_ctx, st->codecpar); + if (ret < 0) + return ret; + movie->codec_ctx->refcounted_frames = 1; if ((ret = avcodec_open2(movie->codec_ctx, codec, NULL)) < 0) { @@ -174,8 +183,7 @@ static av_cold void uninit(AVFilterContext *ctx) { MovieContext *movie = ctx->priv; - if (movie->codec_ctx) - avcodec_close(movie->codec_ctx); + avcodec_free_context(&movie->codec_ctx); if (movie->format_ctx) avformat_close_input(&movie->format_ctx); av_frame_free(&movie->frame); -- cgit v1.1