[FFmpeg-devel,2/2] lavc/qsvenc: enable hevc gpb option

Submitted by Zhong Li on April 2, 2019, 8 a.m.

Details

Message ID 20190402080012.17786-2-zhong.li@intel.com
State New
Headers show

Commit Message

Zhong Li April 2, 2019, 8 a.m.
GPB is the default type, just contains forward references but the
slice_type is B slice with higher encoding efficiency than regular P
slice, but lower performance.

Add an option to allow user to set regular P slice.

Fix ticket#6870

Test data on Intel Kabylake (i7-7567U CPU @ 3.50GHz):
1. ffmpeg -hwaccel qsv -c:v h264_qsv -i bbb_sunflower_1080p_30fps_normal.mp4 -vsync passthrough
-vframes 1000  -c:v hevc_qsv -gpb 0 -bf 0 -q 25 test_gpb_off_bf0_kbl.mp4

transcoding fps: 85
encoded file size of test_gpb_off_bf0_kbl.mp4: 21960100 (bytes)

2. ffmpeg -hwaccel qsv -c:v h264_qsv -i bbb_sunflower_1080p_30fps_normal.mp4 -vsync passthrough
-vframes 1000  -c:v hevc_qsv -gpb 1 -bf 0 -q 25 test_gpb_on_bf0_kbl.mp4

transcoding fps: 79
encoded file size oftest_gpb_on_bf0_kbl.mp4:  21211449 (bytes)

In this case, enable gpb can bring about 7% performance drop but 3.4% encoding efficiency improvment.

Signed-off-by: Zhong Li <zhong.li@intel.com>
---
 libavcodec/qsvenc.c      | 9 +++++++++
 libavcodec/qsvenc.h      | 3 +++
 libavcodec/qsvenc_hevc.c | 2 ++
 3 files changed, 14 insertions(+)

Comments

Carl Eugen Hoyos April 2, 2019, 9:52 p.m.
2019-04-02 10:00 GMT+02:00, Zhong Li <zhong.li@intel.com>:
> GPB is the default type, just contains forward references but the
> slice_type is B slice with higher encoding efficiency than regular P
> slice, but lower performance.
>
> Add an option to allow user to set regular P slice.

Ok.

> +    { "gpb", "GPB (generalized P/B frame) or regular P frame",
> OFFSET(qsv.gpb), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},

Before reading above, I was 100% sure that "true" ("1") would
set GPB frames but that the wording should change.

Use "P frames" instead of the default "P frames".
(But I am not a native speaker)

Carl Eugen
Zhong Li April 3, 2019, 1:24 a.m.
> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf

> Of Carl Eugen Hoyos

> Sent: Wednesday, April 3, 2019 5:52 AM

> To: FFmpeg development discussions and patches

> <ffmpeg-devel@ffmpeg.org>

> Subject: Re: [FFmpeg-devel] [PATCH 2/2] lavc/qsvenc: enable hevc gpb

> option

> 

> 2019-04-02 10:00 GMT+02:00, Zhong Li <zhong.li@intel.com>:

> > GPB is the default type, just contains forward references but the

> > slice_type is B slice with higher encoding efficiency than regular P

> > slice, but lower performance.

> >

> > Add an option to allow user to set regular P slice.

> 

> Ok.

> 

> > +    { "gpb", "GPB (generalized P/B frame) or regular P frame",

> > OFFSET(qsv.gpb), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},

> 

> Before reading above, I was 100% sure that "true" ("1") would set GPB

> frames but that the wording should change.


Now I would like to change my mind, take the "true" as default value, thus means GPB to be default frame type.

> Use "P frames" instead of the default "P frames".

> (But I am not a native speaker)


Sorry, I can't get your point, could you please give a completed sentence should be changed to?
(I am not a native speaker too)

Patch hide | download patch | download mbox

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 55f1223f02..e59fd96870 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -267,6 +267,11 @@  static void dump_video_param(AVCodecContext *avctx, QSVEncContext *q,
 #endif
 #endif
 
+#if QSV_HAVE_GPB
+    if (avctx->codec_id == AV_CODEC_ID_HEVC)
+        av_log(avctx, AV_LOG_VERBOSE,"GPB: %s\n", print_threestate(co3->GPB));
+#endif
+
     if (avctx->codec_id == AV_CODEC_ID_H264) {
         av_log(avctx, AV_LOG_VERBOSE, "Entropy coding: %s; MaxDecFrameBuffering: %"PRIu16"\n",
                co->CAVLC == MFX_CODINGOPTION_ON ? "CAVLC" : "CABAC", co->MaxDecFrameBuffering);
@@ -748,6 +753,10 @@  FF_ENABLE_DEPRECATION_WARNINGS
 #if QSV_HAVE_CO3
         q->extco3.Header.BufferId      = MFX_EXTBUFF_CODING_OPTION3;
         q->extco3.Header.BufferSz      = sizeof(q->extco3);
+#if QSV_HAVE_GPB
+        if (avctx->codec_id == AV_CODEC_ID_HEVC)
+            q->extco3.GPB              = q->gpb ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
+#endif       
         q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extco3;
 #endif
     }
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index f6d53d44cd..f2f4d38503 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -47,6 +47,8 @@ 
 #define QSV_HAVE_LA_HRD QSV_VERSION_ATLEAST(1, 11)
 #define QSV_HAVE_VDENC  QSV_VERSION_ATLEAST(1, 15)
 
+#define QSV_HAVE_GPB    QSV_VERSION_ATLEAST(1, 18)
+
 #if defined(_WIN32) || defined(__CYGWIN__)
 #define QSV_HAVE_AVBR   QSV_VERSION_ATLEAST(1, 3)
 #define QSV_HAVE_ICQ    QSV_VERSION_ATLEAST(1, 8)
@@ -173,6 +175,7 @@  typedef struct QSVEncContext {
 
     int repeat_pps;
     int low_power;
+    int gpb;
 
     int a53_cc;
 
diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index 4c2592355e..f323caf778 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -241,6 +241,8 @@  static const AVOption options[] = {
     { "main10",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_HEVC_MAIN10  }, INT_MIN, INT_MAX,     VE, "profile" },
     { "mainsp",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_HEVC_MAINSP  }, INT_MIN, INT_MAX,     VE, "profile" },
 
+    { "gpb", "GPB (generalized P/B frame) or regular P frame", OFFSET(qsv.gpb), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},
+
     { NULL },
 };