[FFmpeg-cvslog] vsrc_movie: convert to codecpar

Anton Khirnov git at videolan.org
Mon Apr 11 15:42:46 CEST 2016


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Feb 10 14:17:21 2016 +0100| [1138eb5509d3db7f6d565cb45f137a786d22beb9] | committer: Anton Khirnov

vsrc_movie: convert to codecpar

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1138eb5509d3db7f6d565cb45f137a786d22beb9
---

 libavfilter/vsrc_movie.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

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);



More information about the ffmpeg-cvslog mailing list