[FFmpeg-devel] [PATCH 3/3] libavcodec/qsvenc: Add pic_timing_sei reset support to qsv

Wenbin Chen wenbin.chen at intel.com
Fri Sep 23 05:44:12 EEST 2022


Signed-off-by: Wenbin Chen <wenbin.chen at intel.com>
---
 doc/encoders.texi   |  4 ++++
 libavcodec/qsvenc.c | 21 +++++++++++++++++++++
 libavcodec/qsvenc.h |  2 ++
 3 files changed, 27 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 2b6412dbec..741d545ea1 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3369,6 +3369,10 @@ Change this value to reset qsv codec's framerate configuration.
 @item @var{rc_initial_buffer_occupancy}
 @item @var{rc_max_rate}
 Change these value to reset qsv codec's bitrate control configuration.
+
+ at item @var{pic_timing_sei}
+Supported in h264_qsv and hevc_qsv.
+Change this value to reset qsv codec's pic_timing_sei configuration.
 @end table
 
 @subsection H264 options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 3371711872..c1a601f0b3 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -784,6 +784,7 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
 
         q->extco.PicTimingSEI         = q->pic_timing_sei ?
                                         MFX_CODINGOPTION_ON : MFX_CODINGOPTION_UNKNOWN;
+        q->old_pic_timing_sei = q->pic_timing_sei;
 
         if (q->rdo >= 0)
             q->extco.RateDistortionOpt = q->rdo > 0 ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
@@ -1900,6 +1901,25 @@ static int update_bitrate(AVCodecContext *avctx, QSVEncContext *q)
     return updated;
 }
 
+static int update_pic_timing_sei(AVCodecContext *avctx, QSVEncContext *q)
+{
+    int updated = 0;
+
+    if (avctx->codec_id != AV_CODEC_ID_H264 && avctx->codec_id != AV_CODEC_ID_HEVC)
+        return 0;
+
+    UPDATE_PARAM(q->old_pic_timing_sei, q->pic_timing_sei);
+    if (!updated)
+        return 0;
+
+    q->extco.PicTimingSEI = q->pic_timing_sei ?
+                            MFX_CODINGOPTION_ON : MFX_CODINGOPTION_UNKNOWN;
+    av_log(avctx, AV_LOG_DEBUG, "Reset PicTimingSEI: %s\n",
+           print_threestate(q->extco.PicTimingSEI));
+
+    return updated;
+}
+
 static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
                              const AVFrame *frame)
 {
@@ -1915,6 +1935,7 @@ static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
     needReset |= update_low_delay_brc(avctx, q);
     needReset |= update_frame_rate(avctx, q);
     needReset |= update_bitrate(avctx, q);
+    needReset |= update_pic_timing_sei(avctx, q);
     ret = update_min_max_qp(avctx, q);
     if (ret < 0)
         return ret;
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 6e1132d2e3..486c996fc6 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -278,6 +278,8 @@ typedef struct QSVEncContext {
     int old_rc_buffer_size;
     int old_rc_initial_buffer_occupancy;
     int old_rc_max_rate;
+    // This is used for SEI Timing reset
+    int old_pic_timing_sei;
 } QSVEncContext;
 
 int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q);
-- 
2.32.0



More information about the ffmpeg-devel mailing list