Opened 2 years ago

Closed 20 months ago

Last modified 14 months ago

#7330 closed defect (invalid)

ffmpeg 4.0 fails to transcoding one 4k clip

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


Summary of the bug:
How to reproduce:

% ffmpeg -nostdin -y -hwaccel qsv -c:v h264_qsv -i src_AVC_4K.mp4 -b:a 80000 -ar 44100 -c:v h264_qsv -g 300 -profile:v high -preset veryfast -c:a libfdk_aac -max_muxing_queue_size 4000 -b:v 17418000 -movflags +faststart -strict -3 -vsync passthrough -f mp4 dst_AVC_4K.mp4
ffmpeg 4.0.2 + 4.0

ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-16)
  configuration: --enable-version3 --enable-asm --enable-x86asm --enable-avfilter --disable-static --enable-shared --enable-gpl --enable-nonfree --prefix=/usr/local/ --enable-libvidstab --enable-libass --enable-libfreetype --extra-libs=-lfreetype --enable-libtesseract --enable-libfdk_aac --enable-libmp3lame --enable-libx264 --enable-libopenjpeg --enable-libwebp --enable-libx265 --enable-libvorbis --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --enable-stripping --enable-libmfx
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'src_AVC_4K.mp4':
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.12.100
  Duration: 00:00:03.05, start: 0.000000, bitrate: 42590 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 3840x2160 [SAR 1:1 DAR 16:9], 43119 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 82 kb/s (default)
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (h264_qsv) -> h264 (h264_qsv))
  Stream #0:1 -> #0:1 (aac (native) -> aac (libfdk_aac))
[h264_qsv @ 0x22b8480] Encoder will work with partial HW accelerationte=  -0.0kbits/s speed=N/A    
[h264_qsv @ 0x22b8480] Error initializing the encoder: invalid video parameters (-15)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
[libfdk_aac @ 0x23b12c0] 2 frames left in the queue on closing
Conversion failed!

src_AVC_4K.mp4 can be downloaded via the link url:

Is it a ffmpeg bug?

Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.

Change History (10)

comment:1 Changed 2 years ago by cehoyos

  • Keywords Intel removed

Please test current FFmpeg git head to make this a valid ticket and please post gpu and driver information.

comment:2 Changed 23 months ago by fulinjie

Reproduced on the latest ffmpeg master version.

ffmpeg -nostdin -y -hwaccel qsv -c:v h264_qsv -i src_AVC_4K.mp4 -b:a 80000 -ar 44100 -c:v h264_qsv -g 300 -profile:v high -preset veryfast -c:a libfdk_aac -max_muxing_queue_size 4000 -b:v 17418000 -movflags +faststart -strict -3 -vsync passthrough -f mp4 dst_AVC_4K.mp4

Failed with:

[h264_qsv @ 0x55997bc94d80] Current profile is unsupported
[h264_qsv @ 0x55997bc94d80] Selected ratecontrol mode is unsupported
[h264_qsv @ 0x55997bc94d80] Current frame rate is unsupported
[h264_qsv @ 0x55997bc94d80] Current picture structure is unsupported
[h264_qsv @ 0x55997bc94d80] Current resolution is unsupported
[h264_qsv @ 0x55997bc94d80] Current pixel format is unsupported
[h264_qsv @ 0x55997bc94d80] some encoding parameters are not supported by the QSV runtime. Please double check the input parameters.
[h264_qsv @ 0x55997bc94d80] encoded 0 frames, avarge qp is -nan
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Encoder initializing failed.
Frame can not be decoded but no errors reported.

Tracing this issue:

  1. src_AVC_4K.mp4 has some errors: Value of slice::pic_parameter_set_id is out of range.
  2. it can be decoded successfully in soft ways but fails in h264_qsv.
  3. in the function of decode_simple_receive_frame():
    while (!frame->buf[0]) {
            ret = decode_simple_internal(avctx, frame);
            if (ret < 0)
                return ret;

When decode_simple_internal returns a normal value (ret = 0), the value of frame->buf[0] still equals to 0x00 which is incorrect. So it can not jump out of the loop until decode_simple_internal returns -11 (wait for data to be processed).

It's the reason why frames can't be decoded but report no errors.

  1. The function qsv_decode() in qsvdec.c calls :
 ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? &bs : NULL,
                                              insurf, &outsurf, sync);

returns: ret = -10, whcih means MFX_ERR_MORE_DATA (/* expect more data at input */ according to the mfxdefs.h)
This lead to the error condition in 4.

  1. Varify this issue through MSDK sample_decode:
./sample_decode h264 -i src_AVC_4K.mp4 -o sample_out.mp4

[ERROR], sts=MFX_ERR_MORE_DATA(-10), InitMfxParams, m_FileReader->ReadNextFrame failed at /home/linjiefu/Documents/git/msdk/samples/sample_decode/src/pipeline_decode.cpp:653

[ERROR], sts=MFX_ERR_MORE_DATA(-10), Init, InitMfxParams failed at /home/linjiefu/Documents/git/msdk/samples/sample_decode/src/pipeline_decode.cpp:395

[ERROR], sts=MFX_ERR_MORE_DATA(-10), main, Pipeline.Init failed at /home/linjiefu/Documents/git/msdk/samples/sample_decode/src/sample_decode.cpp:666

sample_decode can't decode src_AVC_4K.mp4 successfully.

comment:3 Changed 23 months ago by lizhong1008

Though the error message remind some thing wrong in qsv encoder, actually it is an decoding issue: can't get the decoded frame successfully and then avctx->hw_frames_ctx is NULL in qsvenc_init_session, thus cause encoder device hasn't been initialized successfully.

comment:4 Changed 23 months ago by lizhong1008

As an option, can use vaapi decoder + qsv encoder: ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i src_AVC_4K.mp4.mp4 -vf 'hwmap=derive_device=qsv,format=qsv' -c:v h264_qsv -b:v 5M output.mp4

Last edited 23 months ago by lizhong1008 (previous) (diff)

comment:5 follow-up: Changed 22 months ago by cehoyos

Where can the sample be found?

comment:6 in reply to: ↑ 5 Changed 21 months ago by lizhong1008

Replying to cehoyos:

Where can the sample be found?

It was put on google doc as the bug description:

comment:7 Changed 21 months ago by lizhong1008

This clip is H264 6.0 level. However, The maximum level supported by MSDK is 5.2.
There are some limitation on Intel HW platform (e.g: Skylake) to support level 6.0+: Resolution larger than 4K is not supported, and there are some other limitation such MV range(such is MB level limitation which is are hard to check in MSDK and vaapi driver).
I wonder to know the possibility to exposing level 6.0+ in MSDK (at least in API level, just like VAAPI is doing. Relative discussion: But anyway, I believe this is not a ffmpeg issue and should be closed here.

comment:8 Changed 20 months ago by lizhong1008

  • Resolution set to wontfix
  • Status changed from new to closed

comment:9 Changed 20 months ago by cehoyos

  • Resolution changed from wontfix to invalid

comment:10 Changed 14 months ago by lizhong1008

commit_id 48627aaf646270a8c98337ee208574543e499bfd is helpful to detect HW limitation and give an warning message.

Note: See TracTickets for help on using tickets.