]> git.sesse.net Git - ffmpeg/commitdiff
vsrc_movie: convert to codecpar
authorAnton Khirnov <anton@khirnov.net>
Wed, 10 Feb 2016 13:17:21 +0000 (14:17 +0100)
committerAnton Khirnov <anton@khirnov.net>
Wed, 24 Feb 2016 09:08:37 +0000 (10:08 +0100)
libavfilter/vsrc_movie.c

index 850788c12be42ad0f2b6bcf58490a4cb352e1c88..95ef4f1e9c89256de2e82a8c612742d533415943 100644 (file)
@@ -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);