[FFmpeg-devel] [PATCH 4/8] lavc/snow: only allocate mconly_picture for decoding

Anton Khirnov anton at khirnov.net
Wed Mar 23 17:57:16 EET 2022


It is not used in the encoder.
---
 libavcodec/snow.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index 0a500695ce..1224b95491 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -513,20 +513,23 @@ int ff_snow_common_init_after_header(AVCodecContext *avctx) {
     int ret, emu_buf_size;
 
     if(!s->scratchbuf) {
-        if ((ret = ff_get_buffer(s->avctx, s->mconly_picture,
-                                 AV_GET_BUFFER_FLAG_REF)) < 0)
-            return ret;
+        if (av_codec_is_decoder(avctx->codec)) {
+            if ((ret = ff_get_buffer(s->avctx, s->mconly_picture,
+                                     AV_GET_BUFFER_FLAG_REF)) < 0)
+                return ret;
+
+            if (s->mconly_picture->format != avctx->pix_fmt) {
+                av_log(avctx, AV_LOG_ERROR, "pixel format changed\n");
+                return AVERROR_INVALIDDATA;
+            }
+        }
+
         emu_buf_size = FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * (2 * MB_SIZE + HTAPS_MAX - 1);
         if (!FF_ALLOCZ_TYPED_ARRAY(s->scratchbuf,      FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * 7 * MB_SIZE) ||
             !FF_ALLOCZ_TYPED_ARRAY(s->emu_edge_buffer, emu_buf_size))
             return AVERROR(ENOMEM);
     }
 
-    if(s->mconly_picture->format != avctx->pix_fmt) {
-        av_log(avctx, AV_LOG_ERROR, "pixel format changed\n");
-        return AVERROR_INVALIDDATA;
-    }
-
     for(plane_index=0; plane_index < s->nb_planes; plane_index++){
         int w= s->avctx->width;
         int h= s->avctx->height;
-- 
2.34.1



More information about the ffmpeg-devel mailing list