From: Steinar H. Gunderson Date: Wed, 27 Jul 2016 18:03:24 +0000 (+0200) Subject: Remove the last use of the AVStream::codec parameter. X-Git-Tag: 1.3.3~7 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=41e14ef76d447d31cccc2ec607d3a244baf65c46;p=nageru Remove the last use of the AVStream::codec parameter. Fixes the last FFmpeg deprecation warnings. --- diff --git a/image_input.cpp b/image_input.cpp index 8cd395a..c9f74f8 100644 --- a/image_input.cpp +++ b/image_input.cpp @@ -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 ImageInput::load_image_raw(const string &pathname) @@ -173,8 +178,15 @@ shared_ptr 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 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;