[FFmpeg-cvslog] avcodec/mpegvideo_enc: Call ff_mpv_common_init() later

Andreas Rheinhardt git at videolan.org
Wed Mar 26 06:10:32 EET 2025


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Tue Mar 18 16:29:07 2025 +0100| [8397351221d64fb9305a5af1860993efdc2822e6] | committer: Andreas Rheinhardt

avcodec/mpegvideo_enc: Call ff_mpv_common_init() later

Namely after the main slice context has already been initialized,
so that this initialized state is directly copied to the newly
created slice contexts without relying on it being copied
by ff_update_duplicate_context(). This is in preparation for further
commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8397351221d64fb9305a5af1860993efdc2822e6
---

 libavcodec/mpegvideo_enc.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 9f44c37b3d..f9b8d96c83 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1011,9 +1011,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 
     /* init */
     ff_mpv_idct_init(s);
-    if ((ret = ff_mpv_common_init(s)) < 0)
-        return ret;
-
     ff_fdctdsp_init(&s->fdsp, avctx);
     ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx);
     ff_pixblockdsp_init(&s->pdsp, avctx);
@@ -1030,10 +1027,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
     if (ret < 0)
         return ret;
 
-    ret = init_buffers(m, avctx);
-    if (ret < 0)
-        return ret;
-
     ff_dct_encode_init(s);
 
     if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
@@ -1047,13 +1040,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
     }
 
-    if (s->slice_context_count > 1) {
-        s->rtp_mode = 1;
-
-        if (avctx->codec_id == AV_CODEC_ID_H263P)
-            s->h263_slice_structured = 1;
-    }
-
     if (CONFIG_H263_ENCODER && s->out_format == FMT_H263) {
         ff_h263_encode_init(m);
 #if CONFIG_MSMPEG4ENC
@@ -1062,6 +1048,23 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 #endif
     }
 
+    ret = ff_mpv_common_init(s);
+    if (ret < 0)
+        return ret;
+
+    if (s->slice_context_count > 1) {
+        for (int i = 0; i < s->slice_context_count; ++i) {
+            s->thread_context[i]->rtp_mode = 1;
+
+            if (avctx->codec_id == AV_CODEC_ID_H263P)
+                s->thread_context[i]->h263_slice_structured = 1;
+        }
+    }
+
+    ret = init_buffers(m, avctx);
+    if (ret < 0)
+        return ret;
+
     ret = ff_rate_control_init(m);
     if (ret < 0)
         return ret;



More information about the ffmpeg-cvslog mailing list