[FFmpeg-devel] [PATCH v2 34/69] avcodec/mpegvideo: Move picture_in_gop_number to MPVMainEncContext

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Feb 1 15:06:31 EET 2022


Only ever 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  |  1 +
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 50c0fa42c4..08c795ba17 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -107,7 +107,6 @@ typedef struct MPVContext {
     int input_picture_number;  ///< used to set pic->display_picture_number, should not be used for/by anything else
     int coded_picture_number;  ///< used to set pic->coded_picture_number, should not be used for/by anything else
     int picture_number;       //FIXME remove, unclear definition
-    int picture_in_gop_number; ///< 0-> first pic in gop, ...
     int mb_width, mb_height;   ///< number of MBs horizontally & vertically
     int mb_stride;             ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11
     int b8_stride;             ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index fd3f458fb7..86f2b5fcb1 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -292,7 +292,7 @@ static void mpv_encode_defaults(MPVMainEncContext *m)
     s->fcode_tab     = default_fcode_tab;
 
     s->input_picture_number  = 0;
-    s->picture_in_gop_number = 0;
+    m->picture_in_gop_number = 0;
 }
 
 av_cold int ff_dct_encode_init(MPVEncContext *s)
@@ -1381,7 +1381,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 < m->gop_size &&
+            if (m->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
@@ -1465,10 +1465,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 >= m->gop_size) {
+            if (m->picture_in_gop_number + b_frames >= m->gop_size) {
                 if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) &&
-                    m->gop_size > s->picture_in_gop_number) {
-                    b_frames = m->gop_size - s->picture_in_gop_number - 1;
+                    m->gop_size > m->picture_in_gop_number) {
+                    b_frames = m->gop_size - m->picture_in_gop_number - 1;
                 } else {
                     if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)
                         b_frames = 0;
@@ -1689,7 +1689,7 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
 
     s->vbv_ignore_qmax = 0;
 
-    s->picture_in_gop_number++;
+    m->picture_in_gop_number++;
 
     if (load_input_picture(m, pic_arg) < 0)
         return -1;
@@ -3719,7 +3719,7 @@ static int encode_picture(MPVMainEncContext *m, int picture_number)
     s->current_picture.f->pict_type = s->pict_type;
 
     if (s->current_picture.f->key_frame)
-        s->picture_in_gop_number=0;
+        m->picture_in_gop_number=0;
 
     s->mb_x = s->mb_y = 0;
     s->last_bits= put_bits_count(&s->pb);
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 09dabee223..a177b2d6c6 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -43,6 +43,7 @@ typedef struct MPVMainEncContext {
     int me_pre;                          ///< prepass for motion estimation
 
     int gop_size;
+    int picture_in_gop_number;     ///< 0-> first pic in gop, ...
 
     /* bit rate control */
     int64_t total_bits;
-- 
2.32.0



More information about the ffmpeg-devel mailing list