diff mbox

[FFmpeg-devel] lavc/vaapi_encode_h265: fix the hevc vaapi encoder output shaking issue.

Message ID ccc0367c-92d8-db0d-ac9d-6b953cf8fc49@gmail.com
State New
Headers show

Commit Message

Jun Zhao Nov. 11, 2016, 2:24 a.m. UTC
From 5db0b2cd0930ed88d853114f13b69a80a44d9c4c Mon Sep 17 00:00:00 2001
From: Jun Zhao <jun.zhao@intel.com>
Date: Fri, 11 Nov 2016 10:04:53 +0800
Subject: [PATCH] lavc/vaapi_encode_h265: fix the hevc vaapi encoder output
 shaking issue.

the max_num_reorder_pics/max_dec_pic_buffering_minus in vps/sps are incorrect.

merge libav commit 314b421dd8910ebed7a8d419a0dbea239a00044e
        vaapi_encode: Decide on GOP setup before initialising sequence parameters

merge libav commit b8cac1e83066aa87e8402c146c81b77a11b5eec3
        vaapi_h265: Fix buffering parameters

Merged-by: Wang, Yi A <yi.a.wang@intel.com>
Merged-by: Jun Zhao <jun.zhao@intel.com>
---
 libavcodec/vaapi_encode.c      | 13 ++++++-------
 libavcodec/vaapi_encode_h265.c |  8 ++++----
 2 files changed, 10 insertions(+), 11 deletions(-)

Comments

Mark Thompson Nov. 12, 2016, 2 p.m. UTC | #1
On 11/11/16 02:24, Jun Zhao wrote:
> From 5db0b2cd0930ed88d853114f13b69a80a44d9c4c Mon Sep 17 00:00:00 2001
> From: Jun Zhao <jun.zhao@intel.com>
> Date: Fri, 11 Nov 2016 10:04:53 +0800
> Subject: [PATCH] lavc/vaapi_encode_h265: fix the hevc vaapi encoder output
>  shaking issue.
>
> the max_num_reorder_pics/max_dec_pic_buffering_minus in vps/sps are incorrect.
>
> merge libav commit 314b421dd8910ebed7a8d419a0dbea239a00044e
>         vaapi_encode: Decide on GOP setup before initialising sequence parameters
>
> merge libav commit b8cac1e83066aa87e8402c146c81b77a11b5eec3
>         vaapi_h265: Fix buffering parameters
>
> Merged-by: Wang, Yi A <yi.a.wang@intel.com>
> Merged-by: Jun Zhao <jun.zhao@intel.com>
> ---
>  libavcodec/vaapi_encode.c      | 13 ++++++-------
>  libavcodec/vaapi_encode_h265.c |  8 ++++----
>  2 files changed, 10 insertions(+), 11 deletions(-)

As with the other patch, this is already in the merge queue and I would prefer to use it from there.

Thanks,

- Mark
Jun Zhao Nov. 14, 2016, 12:19 a.m. UTC | #2
On 2016/11/12 22:00, Mark Thompson wrote:
> On 11/11/16 02:24, Jun Zhao wrote:
>> From 5db0b2cd0930ed88d853114f13b69a80a44d9c4c Mon Sep 17 00:00:00 2001
>> From: Jun Zhao <jun.zhao@intel.com>
>> Date: Fri, 11 Nov 2016 10:04:53 +0800
>> Subject: [PATCH] lavc/vaapi_encode_h265: fix the hevc vaapi encoder output
>>  shaking issue.
>>
>> the max_num_reorder_pics/max_dec_pic_buffering_minus in vps/sps are incorrect.
>>
>> merge libav commit 314b421dd8910ebed7a8d419a0dbea239a00044e
>>         vaapi_encode: Decide on GOP setup before initialising sequence parameters
>>
>> merge libav commit b8cac1e83066aa87e8402c146c81b77a11b5eec3
>>         vaapi_h265: Fix buffering parameters
>>
>> Merged-by: Wang, Yi A <yi.a.wang@intel.com>
>> Merged-by: Jun Zhao <jun.zhao@intel.com>
>> ---
>>  libavcodec/vaapi_encode.c      | 13 ++++++-------
>>  libavcodec/vaapi_encode_h265.c |  8 ++++----
>>  2 files changed, 10 insertions(+), 11 deletions(-)
> 
> As with the other patch, this is already in the merge queue and I would prefer to use it from there.
> 
> Thanks,
> 
> - Mark
> 

Please go on the merge :). Hope we can get the mergee patch as quick, maybe I can try the early dorp if you like :)

Thanks
Mark Thompson Nov. 21, 2016, 10:20 p.m. UTC | #3
On 14/11/16 00:19, Jun Zhao wrote:
> 
> 
> On 2016/11/12 22:00, Mark Thompson wrote:
>> On 11/11/16 02:24, Jun Zhao wrote:
>>> From 5db0b2cd0930ed88d853114f13b69a80a44d9c4c Mon Sep 17 00:00:00 2001
>>> From: Jun Zhao <jun.zhao@intel.com>
>>> Date: Fri, 11 Nov 2016 10:04:53 +0800
>>> Subject: [PATCH] lavc/vaapi_encode_h265: fix the hevc vaapi encoder output
>>>  shaking issue.
>>>
>>> the max_num_reorder_pics/max_dec_pic_buffering_minus in vps/sps are incorrect.
>>>
>>> merge libav commit 314b421dd8910ebed7a8d419a0dbea239a00044e
>>>         vaapi_encode: Decide on GOP setup before initialising sequence parameters
>>>
>>> merge libav commit b8cac1e83066aa87e8402c146c81b77a11b5eec3
>>>         vaapi_h265: Fix buffering parameters
>>>
>>> Merged-by: Wang, Yi A <yi.a.wang@intel.com>
>>> Merged-by: Jun Zhao <jun.zhao@intel.com>
>>> ---
>>>  libavcodec/vaapi_encode.c      | 13 ++++++-------
>>>  libavcodec/vaapi_encode_h265.c |  8 ++++----
>>>  2 files changed, 10 insertions(+), 11 deletions(-)
>>
>> As with the other patch, this is already in the merge queue and I would prefer to use it from there.
>>
>> Thanks,
>>
>> - Mark
>>
> 
> Please go on the merge :). Hope we can get the mergee patch as quick, maybe I can try the early dorp if you like :)
> 
> Thanks
> 

Hi,

Apologies for the delay in coming back to this.  I have now cherry-picked the following commits:

3a9662af6c741f8354b1ca97642f78f5c02e2e8f vaapi_h264: Fix HRD bit_rate/cpb_size scaling
80a5d05108cb218e8cd2e25c6621a3bfef0a832e vaapi_encode: Refactor initialisation
892bbbcdc171ff0d08d69636a240ffb95f54243c vaapi_encode: Check packed header capabilities
086e4b58b59ea3993107aa24d92bb962ec69667c vaapi_encode: Sync to input surface rather than output
956a54129db522998a5abae869568dae2c9774cb vaapi_h264: Set max_num_ref_frames to 1 when not using B frames
314b421dd8910ebed7a8d419a0dbea239a00044e vaapi_encode: Decide on GOP setup before initialising sequence parameters
17a0f9481cf07af0feb3838ca315b970117e8000 vaapi_h264: Fix CFR mode with frame_rate set in AVCodecContext
ec17ab381ede4f31c4bdd2767d8f62d24aaf430a vaapi_h264: Write bitstream restriction fields
fc30a90898e419cee7c7cb496976da6337d0bf3e vaapi_h265: Fix slice header writing
b8cac1e83066aa87e8402c146c81b77a11b5eec3 vaapi_h265: Fix buffering parameters

This should fix the issues you highlighted above while staying in sync with libav.

Thanks,

- Mark
diff mbox

Patch

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 21a8656..233f749 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1181,6 +1181,12 @@  av_cold int ff_vaapi_encode_init(AVCodecContext *avctx,
     ctx->decode_delay = 1;
     ctx->output_order = - ctx->output_delay - 1;
 
+    // Currently we never generate I frames, only IDR.
+    ctx->i_per_idr = 0;
+    ctx->p_per_i = ((avctx->gop_size + avctx->max_b_frames) /
+                    (avctx->max_b_frames + 1));
+    ctx->b_per_p = avctx->max_b_frames;
+
     if (ctx->codec->sequence_params_size > 0) {
         ctx->codec_sequence_params =
             av_mallocz(ctx->codec->sequence_params_size);
@@ -1206,13 +1212,6 @@  av_cold int ff_vaapi_encode_init(AVCodecContext *avctx,
             goto fail;
         }
     }
-
-    // All I are IDR for now.
-    ctx->i_per_idr = 0;
-    ctx->p_per_i = ((avctx->gop_size + avctx->max_b_frames) /
-                    (avctx->max_b_frames + 1));
-    ctx->b_per_p = avctx->max_b_frames;
-
     // This should be configurable somehow.  (Needs testing on a machine
     // where it actually overlaps properly, though.)
     ctx->issue_mode = ISSUE_MODE_MAXIMISE_THROUGHPUT;
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 45f6f6d..33de041 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -897,12 +897,12 @@  static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
 
         mseq->log2_max_pic_order_cnt_lsb_minus4 = 8;
         mseq->vps_sub_layer_ordering_info_present_flag = 0;
-        mseq->vps_max_dec_pic_buffering_minus1[0] = 1;
-        mseq->vps_max_num_reorder_pics[0]         = ctx->b_per_p;
+        mseq->vps_max_dec_pic_buffering_minus1[0] = (avctx->max_b_frames > 0) + 1;
+        mseq->vps_max_num_reorder_pics[0]         = (avctx->max_b_frames > 0);
         mseq->vps_max_latency_increase_plus1[0]   = 0;
         mseq->sps_sub_layer_ordering_info_present_flag = 0;
-        mseq->sps_max_dec_pic_buffering_minus1[0] = 1;
-        mseq->sps_max_num_reorder_pics[0]         = ctx->b_per_p;
+        mseq->sps_max_dec_pic_buffering_minus1[0] = (avctx->max_b_frames > 0) + 1;
+        mseq->sps_max_num_reorder_pics[0]         = (avctx->max_b_frames > 0);
         mseq->sps_max_latency_increase_plus1[0]   = 0;
 
         mseq->vps_timing_info_present_flag = 1;