[FFmpeg-devel] [PATCH] avcodec: uninit hwaccel in case of software decoder

Thomas Guillem thomas at gllm.fr
Fri Nov 29 12:44:21 EET 2024


avcodec_get_hw_frames_parameters(), called by the user from get_format,
is allocating ctx->internal->hwaccel_priv_data. But the hardware
decoding setup may fail on the user side and it may fallback to software
decoding. In that case, ctx->internal->hwaccel_priv_data is still
allocated but not used anymore.

Fixes the following assert:

Assertion p_dst->hwaccel_threadsafe || (!dst->hwaccel && !dst->internal->hwaccel_priv_data) failed at src/libavcodec/pthread_frame.c:426
---
 libavcodec/decode.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index d1e10223f2..365fed68e5 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1346,6 +1346,8 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
         if (!hw_config) {
             // No config available, so no extra setup required.
             ret = user_choice;
+            // Remove a potential failed hwaccel context
+            ff_hwaccel_uninit(avctx);
             break;
         }
         config = &hw_config->public;
-- 
2.45.2



More information about the ffmpeg-devel mailing list