intel / media-driver

Intel Graphics Media Driver to support hardware decode, encode and video processing.
https://github.com/intel/media-driver/wiki
Other
972 stars 345 forks source link

ffmpeg qsv decode/encode broken since 3e60104d3 #173

Closed uartie closed 6 years ago

uartie commented 6 years ago

All ffmpeg qsv decode/encode operations fails since:

commit 3e60104d37b3cc58a399c90b5e8a20689af87659
Author: XinfengZhang <carl.zhang@intel.com>
Date:   Thu Apr 19 01:43:11 2018 +0800

    add check for vaCreateConfig parameters

    Signed-off-by: XinfengZhang <carl.zhang@intel.com>

Reproduce Step:

$ LIBVA_DRIVER_NAME=iHD ffmpeg -hwaccel qsv -hwaccel_device /dev/dri/renderD128 \
  -v verbose -c:v h264_qsv -i test.h264 -vf 'hwdownload,format=nv12' -pix_fmt yuv420p \
  -f rawvideo -vsync passthrough -vframes 5 -y ./dump.yuv

ffmpeg version 3.4.git Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (GCC)
  configuration: --prefix=/home/uaeoff/Work/workspace/media/install --disable-static --enable-shared --enable-libdrm --enable-vaapi --enable-libmfx --disable-amf --disable-audiotoolbox --disable-cuda --disable-cuda-sdk --disable-cuvid --disable-d3d11va --disable-dxva2 --disable-libnpp --disable-mmal --disable-nvdec --disable-nvenc --disable-omx --disable-omx-rpi --disable-rkmpp --disable-v4l2-m2m --disable-vdpau --disable-videotoolbox --enable-nonfree --enable-gpl
  libavutil      56. 18.102 / 56. 18.102
  libavcodec     58. 19.104 / 58. 19.104
  libavformat    58. 17.100 / 58. 17.100
  libavdevice    58.  4.100 / 58.  4.100
  libavfilter     7. 24.100 /  7. 24.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
[h264 @ 0x8db200] Reinit context to 1920x1088, pix_fmt: yuv420p
[h264 @ 0x8db200] Increasing reorder buffer to 1
[h264 @ 0x8d94c0] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, h264, from 'test.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (Main), 1 reference frame, yuv420p(top first, left), 1920x1080 (1920x1088), 25 fps, 25 tbr, 1200k tbn, 50 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (h264_qsv) -> rawvideo (native))
Press [q] to stop, [?] for help
[AVBSFContext @ 0x8de800] The input looks like it is Annex B already
[AVHWDeviceContext @ 0x8dd000] Opened VA display via X11 display :0.
[AVHWDeviceContext @ 0x8dd000] libva: VA-API version 1.1.0
[AVHWDeviceContext @ 0x8dd000] libva: va_getDriverName() returns 0
[AVHWDeviceContext @ 0x8dd000] libva: User requested driver 'iHD'
[AVHWDeviceContext @ 0x8dd000] libva: Trying to open /home/uaeoff/Work/workspace/media/install/lib/dri/iHD_drv_video.so
[AVHWDeviceContext @ 0x8dd000] libva: Found init function __vaDriverInit_1_1
[AVHWDeviceContext @ 0x8dd000] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x8dd000] Initialised VAAPI connection: version 1.1
[AVHWDeviceContext @ 0x8dd000] Unknown driver "Intel iHD driver - 2.0.0", assuming standard behaviour.
[AVHWDeviceContext @ 0x8dee80] Initialize MFX session: API version is 1.26, implementation version is 1.26
[AVHWDeviceContext @ 0x8dee80] MFX compile/runtime API: 1.26/1.26
[AVHWDeviceContext @ 0xa66a80] Unknown driver "Intel iHD driver - 2.0.0", assuming standard behaviour.
[AVHWFramesContext @ 0x8fdec0] Error opening the internal VPP session.Surface upload/download will not be possible
    Last message repeated 1 times
[graph 0 input from stream 0:0 @ 0x95ce40] w:1920 h:1080 pixfmt:qsv tb:1/1200000 fr:25/1 sar:0/1 sws_param:flags=2
[auto_scaler_0 @ 0xa4c140] w:iw h:ih flags:'bicubic' interl:0
[format @ 0xa05ac0] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_format_1' and the filter 'format'
[auto_scaler_0 @ 0xa4c140] w:1920 h:1080 fmt:nv12 sar:0/1 -> w:1920 h:1080 fmt:yuv420p sar:0/1 flags:0x4
[AVHWFramesContext @ 0x8fab80] Failed to sync surface 0x8fd1fc: 6 (invalid VASurfaceID).
[hwdownload @ 0x10d6480] Failed to download frame: -5.
Error while filtering: Input/output error
Failed to inject frame into filter network: Input/output error
Error while processing the decoded data for stream #0:0
Conversion failed!

Software Stack:

libva (master) heads/master-0-gb3be72a5a110  https://github.com/01org/libva
gmmlib (master) heads/master-0-g40b45bd6109a  https://github.com/intel/gmmlib
intel-media-driver (master) heads/master-0-g5ae54891f368  https://github.com/intel/media-driver
msdk (master) heads/master-0-g47d7bdc0b8f0  https://github.com/Intel-Media-SDK/MediaSDK
ffmpeg (master) heads/master-0-gbdf1bbdbb4eb  https://git.ffmpeg.org/ffmpeg

NOTE: all components compiled in release mode. It seems when msdk is compiled in debug mode, the issue disappears.

Pull-Request #172 does not fix this.

XinfengZhang commented 6 years ago

thanks for reporting, will fix or backout the commit ASAP.

dvrogozh commented 6 years ago

For the quick access, bad commit is 3e60104d3. And it is really strange. For example, it is missing the most basic check possible for the attributes: check for attrib.value == VA_ATTRIB_NOT_SUPPORTED.

uartie commented 6 years ago

Oddly, I tried this on both Fedora and Ubuntu and cannot reproduce on Ubuntu Xenial. But, on Fedora 26, Fedora 27 (driver doesn't compile on F28), Ubuntu Artful and Ubuntu Bionic all reproduce this. Xenial has GCC 5.4.0 whereas the others have GCC 7.x.

dvrogozh commented 6 years ago

I think I met the same issue on this command line:

ffmpeg \
  -y -hwaccel qsv -c:v h264_qsv -r 30 -i 1920x1080_file.264 -an -filter_complex \
    "split=3[s1][s2][s3]; [s1]scale_qsv=960:540[o1]; [s2]scale_qsv=480:360[o2]; [s3]scale_qsv=480:360[o3]" \
    -map [o1] -c:v h264_qsv -b:v 3200k -minrate 3200k -maxrate 3200k -f rawvideo /tmp/3200a.264 \
    -map [o2] -c:v h264_qsv -b:v 1750k -minrate 1750k -maxrate 1750k -f rawvideo /tmp/1750a.264 \
    -map [o3] -c:v h264_qsv -b:v 800k -minrate 800k -maxrate 800k -f rawvideo /tmp/800a.264

It errors out for me randomly as follows:

[Parsed_scale_qsv_1 @ 0x3346c00] Error opening the VPP for scaling
[Parsed_scale_qsv_1 @ 0x3346c00] Failed to configure output pad on Parsed_scale_qsv_1
Error reinitializing filters!
Failed to inject frame into filter network: Unknown error occurred
Error while processing the decoded data for stream #0:0
Conversion failed!

I have debugged the issue and it is due to the following code in mediasdk: https://github.com/Intel-Media-SDK/MediaSDK/blob/e01caa31f19bb9b3592b03bd5987c305cce98789/_studio/shared/src/mfx_vpp_vaapi.cpp#L260:

        // Configuration
        VAConfigAttrib va_attributes;
        vaSts = vaGetConfigAttributes(m_vaDisplay, VAProfileNone, VAEntrypointVideoProc, &va_attributes, 1);
        MFX_CHECK_WITH_ASSERT(VA_STATUS_SUCCESS == vaSts, MFX_ERR_DEVICE_FAILED);

        vaSts = vaCreateConfig( m_vaDisplay,
                                VAProfileNone,
                                VAEntrypointVideoProc,
                                &va_attributes,
                                1,
                                &m_vaConfig);
        MFX_CHECK_WITH_ASSERT(VA_STATUS_SUCCESS == vaSts, MFX_ERR_DEVICE_FAILED);

That's a misuse of vaGetConfigAttributes. Mediasdk don't initialize attributes at all and gets random results in return. When it pass attributes to vaCreateConfif everything depends which random case was hit. If we hit absolutely unknown attribute we will error out, if we hit known attribute we may work (don't ask me how:)).

The fix is eventually the following: https://github.com/Intel-Media-SDK/MediaSDK/pull/237

@uartie : can you, please, try the fix in a meanwhile?

uartie commented 6 years ago

@dvrogozh Intel-Media-SDK/MediaSDK#237 fixes this. Thanks!