From 2b035ddf491f68a574fbf0fc6ab92e45e68d1d9a Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Mon, 1 Nov 2021 16:23:12 +0100 Subject: [PATCH] get_format should not be set after calling avcodec_open2() --- src/ffmpeg/avcodec.cpp | 4 +--- src/ffmpeg/decoder.cpp | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ffmpeg/avcodec.cpp b/src/ffmpeg/avcodec.cpp index b2e32ac..f1d4fdf 100644 --- a/src/ffmpeg/avcodec.cpp +++ b/src/ffmpeg/avcodec.cpp @@ -27,9 +27,7 @@ Decoder AVCodec::make_decoder (unsigned int width, unsigned int height, ::AVPixe context->width = width; context->height = height; - - if (::avcodec_open2(context.get(), codec, nullptr) < 0) - throw std::runtime_error("Could not open codec"); + context->codec = codec; return {std::move(context), dst_format}; } diff --git a/src/ffmpeg/decoder.cpp b/src/ffmpeg/decoder.cpp index 65378b9..288bd72 100644 --- a/src/ffmpeg/decoder.cpp +++ b/src/ffmpeg/decoder.cpp @@ -36,8 +36,12 @@ Decoder::Decoder (UniqueAVCodecContext&& context, ::AVPixelFormat dst_format) : m_dst_format(dst_format) { assert(not m_context->opaque); + assert(m_context->codec); m_context->opaque = this; m_context->get_format = &get_favourite_format_ifp; + + if (::avcodec_open2(m_context.get(), m_context->codec, nullptr) < 0) + throw std::runtime_error("Could not open codec"); } Decoder::~Decoder() noexcept = default;