From 1d7342e943f780f489afd6382cb8b3e81335e5c5 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Wed, 30 Apr 2025 03:48:38 +0200 Subject: [PATCH 36/44] avcodec/svq1enc: Allocate buffers during init Signed-off-by: Andreas Rheinhardt --- libavcodec/svq1enc.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c index abb1dc9863..6dc7839a1b 100644 --- a/libavcodec/svq1enc.c +++ b/libavcodec/svq1enc.c @@ -594,6 +594,15 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx) if (!s->current_picture || !s->last_picture) { return AVERROR(ENOMEM); } + ret = ff_encode_alloc_frame(avctx, s->current_picture); + if (ret < 0) + return ret; + ret = ff_encode_alloc_frame(avctx, s->last_picture); + if (ret < 0) + return ret; + s->scratchbuf = av_malloc_array(s->current_picture->linesize[0], 16 * 3); + if (!s->scratchbuf) + return AVERROR(ENOMEM); s->frame_width = avctx->width; s->frame_height = avctx->height; @@ -648,22 +657,6 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt, if (ret < 0) return ret; - if (!s->current_picture->data[0]) { - if ((ret = ff_encode_alloc_frame(avctx, s->current_picture)) < 0) { - return ret; - } - } - if (!s->last_picture->data[0]) { - ret = ff_encode_alloc_frame(avctx, s->last_picture); - if (ret < 0) - return ret; - } - if (!s->scratchbuf) { - s->scratchbuf = av_malloc_array(s->current_picture->linesize[0], 16 * 3); - if (!s->scratchbuf) - return AVERROR(ENOMEM); - } - FFSWAP(AVFrame*, s->current_picture, s->last_picture); if (avctx->gop_size && (avctx->frame_num % avctx->gop_size)) -- 2.45.2