diff options
-rw-r--r-- | src/main.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
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; |