[FFmpeg-devel] [PATCH 14/14] avcodec/mpegvideo: Only allocate cbp_table, pred_dir_table when needed

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Mon Apr 29 03:35:35 EEST 2024


Namely for the MPEG-4 decoder.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/mpegvideo.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index ca6e637920..2ef69a5224 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -593,13 +593,12 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
                 tmp += mv_table_size;
             }
         }
-    }
-
-    if (s->out_format == FMT_H263) {
-        /* cbp, ac_pred, pred_dir */
-        if (!(s->cbp_table        = av_mallocz(mb_array_size)) ||
-            !(s->pred_dir_table   = av_mallocz(mb_array_size)))
-            return AVERROR(ENOMEM);
+        if (s->codec_id == AV_CODEC_ID_MPEG4 && !s->encoding) {
+            /* cbp, pred_dir */
+            if (!(s->cbp_table      = av_mallocz(mb_array_size)) ||
+                !(s->pred_dir_table = av_mallocz(mb_array_size)))
+                return AVERROR(ENOMEM);
+        }
     }
 
     if (s->msmpeg4_version >= 3) {
-- 
2.40.1



More information about the ffmpeg-devel mailing list