]> git.sesse.net Git - nageru/commitdiff
Remove the last use of the AVStream::codec parameter.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 27 Jul 2016 18:03:24 +0000 (20:03 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 27 Jul 2016 18:03:35 +0000 (20:03 +0200)
Fixes the last FFmpeg deprecation warnings.

image_input.cpp

index 8cd395ac7aca7d55c4947cb4509047cd7f909e04..c9f74f8847c4b5f297c512de57c6d9eed1f7201f 100644 (file)
@@ -136,6 +136,11 @@ av_frame_alloc_unique()
                frame, av_frame_free_unique);
 }
 
+void avcodec_free_context_unique(AVCodecContext *codec_ctx)
+{
+       avcodec_free_context(&codec_ctx);
+}
+
 }  // namespace
 
 shared_ptr<const ImageInput::Image> ImageInput::load_image_raw(const string &pathname)
@@ -173,8 +178,15 @@ shared_ptr<const ImageInput::Image> ImageInput::load_image_raw(const string &pat
                return nullptr;
        }
 
-       AVCodecContext *codec_ctx = format_ctx->streams[stream_index]->codec;
-       AVCodec *codec = avcodec_find_decoder(codec_ctx->codec_id);
+       const AVCodecParameters *codecpar = format_ctx->streams[stream_index]->codecpar;
+       AVCodecContext *codec_ctx = avcodec_alloc_context3(nullptr);
+       unique_ptr<AVCodecContext, decltype(avcodec_free_context_unique)*> codec_ctx_free(
+               codec_ctx, avcodec_free_context_unique);
+       if (avcodec_parameters_to_context(codec_ctx, codecpar) < 0) {
+               fprintf(stderr, "%s: Cannot fill codec parameters\n", pathname.c_str());
+               return nullptr;
+       }
+       AVCodec *codec = avcodec_find_decoder(codecpar->codec_id);
        if (codec == nullptr) {
                fprintf(stderr, "%s: Cannot find decoder\n", pathname.c_str());
                return nullptr;