Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#5821 closed defect (fixed)

jerky result when using hevc_vaapi encoding on Skylake cpu

Reported by: trivita Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: vaapi
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
How to reproduce:

ffmpeg -vaapi_device /dev/dri/renderD128 -i x264-8bit-560K.mp4 -vf 'format=nv12,hwupload' -c:v hevc_vaapi o.mp4

ffmpeg built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.2) 20160609

uname -a

Linux trivita-ThinkPad-T460 4.8.0-040800rc3-generic #201608212032 SMP Mon Aug 22 00:34:39 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

vainfo

libva info: VA-API version 0.39.2
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.39 (libva 1.7.1)
vainfo: Driver version: Intel i965 driver for Intel(R) Skylake - 1.7.1
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Simple            :	VAEntrypointEncSlice
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSliceLP
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointEncSliceLP
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointEncSliceLP
      VAProfileH264MultiviewHigh      :	VAEntrypointVLD
      VAProfileH264MultiviewHigh      :	VAEntrypointEncSlice
      VAProfileH264StereoHigh         :	VAEntrypointVLD
      VAProfileH264StereoHigh         :	VAEntrypointEncSlice
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileNone                   :	VAEntrypointVideoProc
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointEncPicture
      VAProfileVP8Version0_3          :	VAEntrypointVLD
      VAProfileVP8Version0_3          :	VAEntrypointEncSlice
      VAProfileHEVCMain               :	VAEntrypointVLD
      VAProfileHEVCMain               :	VAEntrypointEncSlice

no problem using h264_vaapi
no problem hardware decoding hevc
no problem using software encoding libx265

the whole encoding process runs perfectly smooth, no warnings or errors. but the resulting video has problem. like frames go back and forth from time to time. i call it 'jerky'.

Change History (10)

comment:1 Changed 2 years ago by trivita

ffmpeg -version

ffmpeg version N-81512-g499e8b0 Copyright (c) 2000-2016 the FFmpeg developers

comment:2 Changed 2 years ago by mani

Hi

Did you resolve this, i am struggling with the same problem and am attaching the mediainfo of the input and the jerky output got through hevc_vaapi. If this is not yet resolved can anybody please have a look into this and see if more experienced people can find the issue.

the input file from mediainfo

mediainfo input.mp4
General
Complete name                            : input.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 11.2 GiB
Duration                                 : 3h 8mn
Overall bit rate mode                    : Variable
Overall bit rate                         : 8 496 Kbps
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
Writing application                      : Lavf56.40.101

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4.1
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 3h 8mn
Bit rate mode                            : Variable
Bit rate                                 : 8 361 Kbps
Maximum bit rate                         : 35.0 Mbps
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 24.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.168
Stream size                              : 11.0 GiB (98%)
Writing library                          : x264 core
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709

Audio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 3h 8mn
Duration_LastFrame                       : -11ms
Bit rate mode                            : Constant
Bit rate                                 : 128 Kbps
Channel(s)                               : 2 channels
Channel(s)_Original                      : 6 channels
Channel positions                        : Front: L C R, Side: L R, LFE
Sampling rate                            : 48.0 KHz
Frame rate                               : 46.875 fps (1024 spf)
Compression mode                         : Lossy
Stream size                              : 173 MiB (2%)
Default                                  : Yes
Alternate group                          : 1
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00


Encoded file using hevc_vaapi from mediainfo

$ mediainfo output.mp4
General
Complete name                            : output.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/mp41)
File size                                : 5.51 MiB
Duration                                 : 25s 259ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 1 830 Kbps
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
Writing application                      : Lavf57.48.102

Video
ID                                       : 1
Format                                   : HEVC
Format/Info                              : High Efficiency Video Coding
Codec ID                                 : hev1
Codec ID/Info                            : High Efficiency Video Coding
Duration                                 : 25s 42ms
Bit rate                                 : 1 659 Kbps
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 24.000 fps
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.033
Stream size                              : 4.95 MiB (90%)
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

Audio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 25s 259ms
Bit rate mode                            : Variable
Bit rate                                 : 180 Kbps
Maximum bit rate                         : 341 Kbps
Channel(s)                               : 2 channels
Channel(s)_Original                      : 6 channels
Channel positions                        : Front: L C R, Side: L R, LFE
Sampling rate                            : 48.0 KHz
Frame rate                               : 46.875 fps (1024 spf)
Compression mode                         : Lossy
Stream size                              : 554 KiB (10%)
Default                                  : Yes
Alternate group                          : 1
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

Thanks
Mani

comment:3 Changed 2 years ago by jkqxz

Sounds like <https://git.libav.org/?p=libav.git;a=commit;h=b8cac1e83066aa87e8402c146c81b77a11b5eec3>.

Does it happen:
(a) If you encode with no B-frames (add "-bf 0" to the encode options).
or
(b) If you apply this patch:

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index db339aa..006cc2a 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;

comment:4 Changed 2 years ago by mani

Hi jkqxz

Yes, it solves the problems. I tried with no b-frames and it eliminates my problem, so now i am going to apply this patch.

I owe you a lot :-), thanks for the same.

Best Regards
Mani

comment:5 Changed 2 years ago by cehoyos

  • Keywords h265 hevc removed
  • Status changed from new to open

comment:6 Changed 2 years ago by mani

Hi

After looking around multiple videos, this does reduce the problem, but does have jerky artifacts -though it now seems localized to portions of the screen and not in all conditions as well, and is not yet clean video. Need to do some further digging.

Best Regards
Mani

comment:7 Changed 2 years ago by mani

Update:

I did put in the patch into the latest libavcodec -as per the diff, the jerky artifacts dont exist for most of the video, but they do exist in portions and during scene changeovers. Like a tearaway and it catches up to the video and settles down.

So i guess, this patch has given some pointers, but doesnt go all the way to solve the problems.

Best Regards
Mani

comment:8 Changed 2 years ago by jkqxz

The patch above is merged as 30ebabca7c3a2cea1cb871563f6097f3619c8be9, which I believe fixes the main issue here. Can you retest with current git and report back on any further problems which might still be present for you? (Or close this ticket if none.)

comment:9 follow-up: Changed 2 years ago by mani

  • Resolution set to fixed
  • Status changed from open to closed

This patch solves the problem, thanks for pointing it out. I am marking this as closed.

comment:10 in reply to: ↑ 9 Changed 2 years ago by trivita

Replying to mani:

This patch solves the problem, thanks for pointing it out. I am marking this as closed.

confirmed. problem solved. thank you.

Note: See TracTickets for help on using tickets.