@@ -1802,18 +1802,21 @@ AVBufferRef *ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx,
const AVHWAccel *hwaccel)
{
AVBufferRef *ref;
- AVHWFramesContext *frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
- uint8_t *data = av_mallocz(hwaccel->frame_priv_data_size);
- if (!data)
- return NULL;
-
- ref = av_buffer_create(data, hwaccel->frame_priv_data_size,
- hwaccel->free_frame_priv,
- frames_ctx->device_ctx, 0);
- if (!ref) {
- av_free(data);
- return NULL;
- }
+ if (avctx->hw_frames_ctx) {
+ AVHWFramesContext *frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
+ uint8_t *data = av_mallocz(hwaccel->frame_priv_data_size);
+ if (!data)
+ return NULL;
+
+ ref = av_buffer_create(data, hwaccel->frame_priv_data_size,
+ hwaccel->free_frame_priv,
+ frames_ctx->device_ctx, 0);
+ if (!ref) {
+ av_free(data);
+ return NULL;
+ }
+ } else
+ ref = av_buffer_allocz(hwaccel->frame_priv_data_size);
return ref;
}
From 0fe666c4e3d10a689f4c6854a58eec3e7ff3c922 Mon Sep 17 00:00:00 2001 From: Aleksoid <Aleksoid1978@mail.ru> Date: Mon, 17 Jul 2023 17:04:43 +1000 Subject: [PATCH] Fixed crash when using hardware acceleration in third party projects without using hw_frames_ctx. --- libavcodec/decode.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)