From 50777aae787ed4dd2bdbeace7cfba5268b1324aa Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 16 Oct 2022 17:52:34 +0200 Subject: Free test codec context --- src/main.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 1fc1afa..021d6e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -697,9 +697,12 @@ static const AVCodec* find_h264_encoder() { checked = true; // Do not use AV_PIX_FMT_CUDA because we dont want to do full check with hardware context AVCodecContext *codec_context = create_video_codec_context(AV_PIX_FMT_YUV420P, VideoQuality::VERY_HIGH, 1920, 1080, 60, codec, false); - if (avcodec_open2(codec_context, codec_context->codec, NULL) < 0) { + if(codec_context) { + if (avcodec_open2(codec_context, codec_context->codec, NULL) < 0) { + avcodec_free_context(&codec_context); + return nullptr; + } avcodec_free_context(&codec_context); - return nullptr; } } return codec; @@ -718,9 +721,12 @@ static const AVCodec* find_h265_encoder() { checked = true; // Do not use AV_PIX_FMT_CUDA because we dont want to do full check with hardware context AVCodecContext *codec_context = create_video_codec_context(AV_PIX_FMT_YUV420P, VideoQuality::VERY_HIGH, 1920, 1080, 60, codec, false); - if (avcodec_open2(codec_context, codec_context->codec, NULL) < 0) { + if(codec_context) { + if (avcodec_open2(codec_context, codec_context->codec, NULL) < 0) { + avcodec_free_context(&codec_context); + return nullptr; + } avcodec_free_context(&codec_context); - return nullptr; } } return codec; -- cgit v1.2.3