[FFmpeg-devel] [PATCH v2 35/69] avcodec/mpegvideo: Move pts and dts fields to MPVMainEncContext

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


user_specified_pts, dts_delta and reordered_pts are only used
by the main thread.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/mpegvideo.h     | 10 ----------
 libavcodec/mpegvideo_enc.c | 22 +++++++++++-----------
 libavcodec/mpegvideoenc.h  | 11 +++++++++++
 3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 08c795ba17..3dd04d6e82 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -118,16 +118,6 @@ typedef struct MPVContext {
     Picture **input_picture;   ///< next pictures on display order for encoding
     Picture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding
 
-    int64_t user_specified_pts; ///< last non-zero pts from AVFrame which was passed into avcodec_send_frame()
-    /**
-     * pts difference between the first and second input frame, used for
-     * calculating dts of the first frame when there's a delay */
-    int64_t dts_delta;
-    /**
-     * reordered pts to be used as dts for the next output frame when there's
-     * a delay */
-    int64_t reordered_pts;
-
     /** bit output */
     PutBitContext pb;
 
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 86f2b5fcb1..4f64fd28a7 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -391,7 +391,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_ERROR, "intra dc precision too large\n");
         return AVERROR(EINVAL);
     }
-    s->user_specified_pts = AV_NOPTS_VALUE;
+    m->user_specified_pts = AV_NOPTS_VALUE;
 
     if (m->gop_size <= 1) {
         s->intra_only = 1;
@@ -1023,8 +1023,8 @@ static int load_input_picture(MPVMainEncContext *m, const AVFrame *pic_arg)
         display_picture_number = s->input_picture_number++;
 
         if (pts != AV_NOPTS_VALUE) {
-            if (s->user_specified_pts != AV_NOPTS_VALUE) {
-                int64_t last = s->user_specified_pts;
+            if (m->user_specified_pts != AV_NOPTS_VALUE) {
+                int64_t last = m->user_specified_pts;
 
                 if (pts <= last) {
                     av_log(s->avctx, AV_LOG_ERROR,
@@ -1034,13 +1034,13 @@ static int load_input_picture(MPVMainEncContext *m, const AVFrame *pic_arg)
                 }
 
                 if (!s->low_delay && display_picture_number == 1)
-                    s->dts_delta = pts - last;
+                    m->dts_delta = pts - last;
             }
-            s->user_specified_pts = pts;
+            m->user_specified_pts = pts;
         } else {
-            if (s->user_specified_pts != AV_NOPTS_VALUE) {
-                s->user_specified_pts =
-                pts = s->user_specified_pts + 1;
+            if (m->user_specified_pts != AV_NOPTS_VALUE) {
+                m->user_specified_pts =
+                pts = m->user_specified_pts + 1;
                 av_log(s->avctx, AV_LOG_INFO,
                        "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n",
                        pts);
@@ -1889,10 +1889,10 @@ vbv_retry:
         pkt->pts = s->current_picture.f->pts;
         if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B) {
             if (!s->current_picture.f->coded_picture_number)
-                pkt->dts = pkt->pts - s->dts_delta;
+                pkt->dts = pkt->pts - m->dts_delta;
             else
-                pkt->dts = s->reordered_pts;
-            s->reordered_pts = pkt->pts;
+                pkt->dts = m->reordered_pts;
+            m->reordered_pts = pkt->pts;
         } else
             pkt->dts = pkt->pts;
         if (s->current_picture.f->key_frame)
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index a177b2d6c6..836fa2eaa3 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -45,6 +45,17 @@ typedef struct MPVMainEncContext {
     int gop_size;
     int picture_in_gop_number;     ///< 0-> first pic in gop, ...
 
+    /** last non-zero pts from AVFrame which was passed into avcodec_send_frame() */
+    int64_t user_specified_pts;
+    /**
+     * pts difference between the first and second input frame, used for
+     * calculating dts of the first frame when there's a delay */
+    int64_t dts_delta;
+    /**
+     * reordered pts to be used as dts for the next output frame when there's
+     * a delay */
+    int64_t reordered_pts;
+
     /* bit rate control */
     int64_t total_bits;
     int frame_bits;                ///< bits used for the current frame
-- 
2.32.0



More information about the ffmpeg-devel mailing list