[FFmpeg-devel] [PATCH 22/41] avcodec/mpegvideo: Move gop_size to MPVMainEncContext

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sun Jan 30 08:27:30 EET 2022


Only used by the main encoding thread.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/mpegvideo.h     |  1 -
 libavcodec/mpegvideo_enc.c | 14 +++++++-------
 libavcodec/mpegvideoenc.h  |  2 ++
 libavcodec/ratecontrol.c   |  2 +-
 4 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 7089160765..c679b7e531 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -84,7 +84,6 @@ typedef struct MPVContext {
     void *private_ctx;
     /* the following parameters must be initialized before encoding */
     int width, height;///< picture size. must be a multiple of 16
-    int gop_size;
     int intra_only;   ///< if true, only intra pictures are generated
     int64_t bit_rate; ///< wanted bit rate
     enum OutputFormat out_format; ///< output format
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 4da765a617..785aeb2aee 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -350,7 +350,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
                avctx->gop_size, 600);
         avctx->gop_size = 600;
     }
-    s->gop_size     = avctx->gop_size;
+    m->gop_size     = avctx->gop_size;
     s->avctx        = avctx;
     if (avctx->max_b_frames > MAX_B_FRAMES) {
         av_log(avctx, AV_LOG_ERROR, "Too many B-frames requested, maximum "
@@ -392,9 +392,9 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
     }
     s->user_specified_pts = AV_NOPTS_VALUE;
 
-    if (s->gop_size <= 1) {
+    if (m->gop_size <= 1) {
         s->intra_only = 1;
-        s->gop_size   = 12;
+        m->gop_size   = 12;
     } else {
         s->intra_only = 0;
     }
@@ -1380,7 +1380,7 @@ static int select_input_picture(MPVMainEncContext *m)
     /* set next picture type & ordering */
     if (!s->reordered_input_picture[0] && s->input_picture[0]) {
         if (s->frame_skip_threshold || s->frame_skip_factor) {
-            if (s->picture_in_gop_number < s->gop_size &&
+            if (s->picture_in_gop_number < m->gop_size &&
                 s->next_picture_ptr &&
                 skip_check(m, s->input_picture[0], s->next_picture_ptr)) {
                 // FIXME check that the gop check above is +-1 correct
@@ -1464,10 +1464,10 @@ static int select_input_picture(MPVMainEncContext *m)
                        "warning, too many B-frames in a row\n");
             }
 
-            if (s->picture_in_gop_number + b_frames >= s->gop_size) {
+            if (s->picture_in_gop_number + b_frames >= m->gop_size) {
                 if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) &&
-                    s->gop_size > s->picture_in_gop_number) {
-                    b_frames = s->gop_size - s->picture_in_gop_number - 1;
+                    m->gop_size > s->picture_in_gop_number) {
+                    b_frames = m->gop_size - s->picture_in_gop_number - 1;
                 } else {
                     if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)
                         b_frames = 0;
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index d32e4372a7..1c101d01ac 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -40,6 +40,8 @@ typedef struct MPVMainEncContext {
     int me_penalty_compensation;
     int me_pre;                          ///< prepass for motion estimation
 
+    int gop_size;
+
     /* bit rate control */
     int64_t total_bits;
     int frame_bits;                ///< bits used for the current frame
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index b0f319680b..4e7bbe49a7 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -632,7 +632,7 @@ av_cold int ff_rate_control_init(MPVMainEncContext *m)
                 double bits = s->rc_initial_cplx * (i / 10000.0 + 1.0) * s->mb_num;
                 RateControlEntry rce;
 
-                if (i % ((s->gop_size + 3) / 4) == 0)
+                if (i % ((m->gop_size + 3) / 4) == 0)
                     rce.pict_type = AV_PICTURE_TYPE_I;
                 else if (i % (s->max_b_frames + 1))
                     rce.pict_type = AV_PICTURE_TYPE_B;
-- 
2.32.0



More information about the ffmpeg-devel mailing list