[FFmpeg-devel] [PATCH v2 32/69] avcodec/mpegvideo: Move gop_size to MPVMainEncContext

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Feb 1 15:06:29 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 c59d4848a8..50c0fa42c4 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -81,7 +81,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 b67f706504..77825e5b82 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -352,7 +352,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 > MPVENC_MAX_B_FRAMES) {
         av_log(avctx, AV_LOG_ERROR, "Too many B-frames requested, maximum "
@@ -394,9 +394,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;
     }
@@ -1382,7 +1382,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
@@ -1466,10 +1466,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 06e14ad11f..09dabee223 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -42,6 +42,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