AMF
AMF copied to clipboard
[Bug]: DX11 or DXVA2 (copy-back) HW decoder fails and causes driver crash on encountering corrupted frame
Describe the bug When using hw decoder on some corrupted videos, both by watching and transcoding such files driver will crash with "Access Violation" error in player. At moment of encountering of the corrupted frame, playback will instantly stop. Then crash follows. Crash can be not absolutely immediate (depending on player/decoder), but will always happen very soon after passing corrupted frame (within 3 seconds).
To Reproduce
- Use MPC-HC for comfort (not neccessary, you can even use default Windows 11 player)
- Set up HW Decoder to use either D3D11 or DXVA2 (copy-back)
- Play one of these samples [i cropped them out of the original videos via ffmpeg]: [These are .mkv in disguise, because GitHub doesn't allow MKV to be uploaded for some reason. Still should be able to play them like normal.] https://github.com/GPUOpen-LibrariesAndSDKs/AMF/assets/9446187/5650b62c-e0ce-42f8-b15a-4eaf14d4fd68 https://github.com/GPUOpen-LibrariesAndSDKs/AMF/assets/9446187/7bc6d3f0-dade-4a80-9ad0-142c05af19f0
Same crashing problem will happen when you try to transcode such videos while using hw decoder. SW decoder will throw an error, but continue without crash.
Bugged behaviour: For D3D11 - on bugged frame image will freeze right at it or after, playback timeline will be stopped. Then driver crash follows For DXVA2 (copy-back) - on bugged frame image will still freeze, but playback timeline WON'T be stopped. Then driver crash follows DXVA2 (native), and CPU rendering will just show partial frame corruption.
Setup (please complete the following information):
- OS: Windows 11, 23H2, build 22631.3085
- Driver Version: 24.1.1
- GPU: RX 7800XT
- Which component has the issue: Decoder
Debug Log (please upload or paste): Full log - compressed as uncompressed takes 639MB of space [even compressed it takes more space than GitHub allows to upload]: https://drive.google.com/file/d/13SpDouZKz4ZbSUu7juwtFBCJEqzlaDuL/view?usp=sharing
Crash point in log from VCEEnc debug run.
[AMFVideoStreamParserImpl] 2024-02-13 02:33:41.178 4A04 [AMFVideoStreamParserImpl] Debug: AMFVideoStreamParserImpl::SubmitInput()
[matroska @ 0000028f5ac78ec0] Writing block of size 768 with pts 7261760, dts 7261760, duration 32 at relative offset 2823405 in cluster at offset 9753243328. TrackNumber 9, keyframe 1
[AMFEncoderCoreH264] 2024-02-13 02:33:41.180 3590 [AMFEncoderCoreH264] Debug: GetProperty(OutputMode), 0
[matroska @ 0000028f5ac78ec0] Writing block of size 1792 with pts 7261792, dts 7261792, duration 32 at relative offset 2824180 in cluster at offset 9753243328. TrackNumber 2, keyframe 1
[AMFVideoStreamParserImpl] 2024-02-13 02:33:41.180 4A04 [AMFVideoStreamParserImpl] Debug: AMFVideoStreamParserImpl::QueryOutput()
[matroska @ 0000028f5ac78ec0] Writing block of size 1536 with pts 7261792, dts 7261792, duration 32 at relative offset 2825979 in cluster at offset 9753243328. TrackNumber 3, keyframe 1
AMFENC: Fatal error when getting output bitstream from encoder.
[AMFDecodeEngineImplDX11] 2024-02-13 02:33:46.662 4A04 [AMFDecodeEngineImplDX11] Error: ..\..\..\..\..\runtime\src\components\DecoderUVD\DecodeEngines\DirectX\DirectX11\DecodeEngineDX11.cpp(1322):COM failed, HR = 80070057:InitDecoder() CreateVideoDecoderOutputView failed
Break in task AMFENC: device operation failure..
[AMFDecoderUVDImpl] 2024-02-13 02:33:46.663 4A04 [AMFDecoderUVDImpl] Error: ..\..\..\..\..\runtime\src\components\DecoderUVD\DecoderUVDImpl.cpp(1879):AMF_ERROR 1 : AMF_FAIL: DecodeFrame() - BeginDecodeFrame failed
Clear vpp filters...
Closing m_pmfxDEC/ENC/VPP...
Closing Encoder...
[AMFEncoderCoreH264] 2024-02-13 02:33:46.664 3590 [AMFEncoderCoreH264] Debug: AMFEncoderCoreH264Impl::Terminate()
[PrivateChannelDx11] 2024-02-13 02:33:46.665 3590 [PrivateChannelDx11] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(158):Assertion failed:D3D Device removed.
[PrivateChannelDx11] 2024-02-13 02:33:46.665 3590 [PrivateChannelDx11] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(191):AMF_ERROR 17 : AMF_NO_DEVICE: Failed in ValidateDevice.
[PrivateChannel] 2024-02-13 02:33:46.665 3590 [PrivateChannel] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannel.cpp(480):AMF_ERROR 17 : AMF_NO_DEVICE: SubmitSessionInfo() Failed to transport function package.
[PrivateChannelDx11] 2024-02-13 02:33:46.666 3590 [PrivateChannelDx11] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(158):Assertion failed:D3D Device removed.
[PrivateChannelDx11] 2024-02-13 02:33:46.666 3590 [PrivateChannelDx11] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(191):AMF_ERROR 17 : AMF_NO_DEVICE: Failed in ValidateDevice.
[PrivateChannel] 2024-02-13 02:33:46.666 3590 [PrivateChannel] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannel.cpp(251):AMF_ERROR 17 : AMF_NO_DEVICE: QueryProperties() Failed to transport function package.
[AMFEncoderCoreBaseImpl] 2024-02-13 02:33:46.666 3590 [AMFEncoderCoreBaseImpl] Warning: ReleaseThroughput() - Failed to release throughput.
[PrivateChannelDx11] 2024-02-13 02:33:46.666 3590 [PrivateChannelDx11] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(158):Assertion failed:D3D Device removed.
[PrivateChannelDx11] 2024-02-13 02:33:46.667 3590 [PrivateChannelDx11] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(191):AMF_ERROR 17 : AMF_NO_DEVICE: Failed in ValidateDevice.
[PrivateChannel] 2024-02-13 02:33:46.667 3590 [PrivateChannel] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannel.cpp(321):AMF_ERROR 17 : AMF_NO_DEVICE: DestroyQueue() Failed to transport function package.
[EncodeQueueWinImpl] 2024-02-13 02:33:46.667 3590 [EncodeQueueWinImpl] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\EncodeQueueWinImpl.cpp(45):AMF_ERROR 17 : AMF_NO_DEVICE: Failed to destroy encode queue.
[PrivateChannelDx11] 2024-02-13 02:33:46.667 3590 [PrivateChannelDx11] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(158):Assertion failed:D3D Device removed.
[PrivateChannelDx11] 2024-02-13 02:33:46.668 3590 [PrivateChannelDx11] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(191):AMF_ERROR 17 : AMF_NO_DEVICE: Failed in ValidateDevice.
[PrivateChannel] 2024-02-13 02:33:46.668 3590 [PrivateChannel] Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannel.cpp(54):AMF_ERROR 17 : AMF_NO_DEVICE: Failed to transport package for function. 7
Closed Encoder.
Closing Decoder...
[AMFDecoderUVDImpl] 2024-02-13 02:33:46.670 3590 [AMFDecoderUVDImpl] Debug: AMFDecoderUVDImpl::Terminate()
[AMFVideoStreamParserImpl] 2024-02-13 02:33:46.671 3590 [AMFVideoStreamParserImpl] Debug: AMFVideoStreamParserImpl::Terminate()
[AMFDecoderUVDImpl] 2024-02-13 02:33:46.672 3590 [AMFDecoderUVDImpl] Info: Submitted 174126, Queried 174117
Closed Decoder.
Clear pipeline tasks and allocated frames...
[AMFEncoderCoreH264] 2024-02-13 02:33:46.678 3590 [AMFEncoderCoreH264] Debug: AMFEncoderCoreH264Impl::Terminate()
Waiting for writer to finish...
avout: closed audio process thread default.
avout: closed audio process thread 7.0.
avout: closed audio process thread 1.0.
avout: closed audio process thread 2.0.
avout: closed audio process thread 3.0.
avout: closed audio process thread 4.0.
avout: closed audio process thread 5.0.
avout: closed audio process thread 6.0.
avout: closed audio process thread 8.0.
avout: closed audio encode thread default.
Short log (level info)
C:\Users\-----\Videos\Processing>C:\Users\DimkaTsv\Desktop\Utilites\VCE_Encoder\VCEEncC_x64\\VCEEncC64.exe -i C:\Users\-----\Videos\Processing\Star.Wars.Episode.IV.A.New.Hope.1977.HDTV.1080p.mkv -o "Star.Wars.Episode.IV.A.New.Hope.1977.HDTV.1080p_processed.mkv" --avsw --codec avc --profile main --level 5.1 --preset balanced --ref 4 --ltr 3 --vbr 7500 --max-bitrate 15000 --qp-max 36 --audio-copy --chapter-copy --log vceencc_log.txt --log-level info
--------------------------------------------------------------------------------
Star.Wars.Episode.V.The.Empire.Strikes.Back.1980.HDTV.1080p_processed.mkv
--------------------------------------------------------------------------------
Input #0, matroska,webm, from 'C:\Users\-----\Videos\Processing\Star.Wars.Episode.V.The.Empire.Strikes.Back.1980.HDTV.1080p.mkv':
Metadata:
encoder : libebml v0.8.0 + libmatroska v0.9.0
creation_time : 2010-06-02T13:34:44.000000Z
Duration: 02:07:26.91, start: 0.000000, bitrate: 20701 kb/s
Stream #0:0: Video: h264 (Main), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn
Stream #0:1(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s (default)
Metadata:
title : Dubbed
Stream #0:2(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
Metadata:
title : Kinomania
Stream #0:3(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
Metadata:
title : Tycoon
Stream #0:4(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
Metadata:
title : Glanz
Stream #0:5(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
Metadata:
title : Gavrilov
Stream #0:6(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
Metadata:
title : Zhivov
Stream #0:7(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
Metadata:
title : English
Stream #0:8: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
Metadata:
title : Comments
Stream #0:9(rus): Subtitle: subrip (default)
Metadata:
title : Forced
Stream #0:10(rus): Subtitle: subrip
Metadata:
title : Kinomania
Stream #0:11: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
VCEEnc (x64) 8.21 (r1577) by rigaya, Dec 10 2023 04:01:37 (VC 1937/Win)
OS: Windows 11 x64 (22631) [UTF-8]
CPU: AMD Ryzen 7 5800X3D 8-Core Processor [4.45GHz] (8C/16T)
GPU: AMD Radeon RX 7800 XT [31.0.24002.92]
AMF: Runtime 1.4.33 / SDK 1.4.30
Input Info: avvce: H.264/AVC, 1920x1080, 24000/1001 fps
Output: H.264/AVC Main @ Level 5.1
1920x1080p 1:1 23.976fps (24000/1001fps)
avwriter: h264, ac3, ac3, ac3, ac3, ac3, ac3, ac3, ac3, ac3
=> matroska
Quality: balanced
VBR: 7500 kbps
Max bitrate: 15000 kbps
QP: Min: 0:0, Max: 36:36
VBV Bufsize: 7500 kb
Bframes: 0 frames
Pre Analysis: off
Ref frames: 4 frames
LTR frames: 3 frames
Motion Est: Q-pel
Slices: 1
GOP Len: 240 frames
Others: skipframe:on deblock
Output #0, matroska, to 'Star.Wars.Episode.V.The.Empire.Strikes.Back.1980.HDTV.1080p_processed.mkv':
Metadata:
encoding_tool : VCEEnc (x64) 8.21
encoder : Lavf60.16.100
Stream #0:0: Video: h264 (Main) (H264 / 0x34363248), nv12(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 23.98 fps, 1k tbn
Stream #0:1(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s (default)
Metadata:
title : Dubbed
Stream #0:2(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 384 kb/s
Metadata:
title : Kinomania
Stream #0:3(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
Metadata:
title : Tycoon
Stream #0:4(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
Metadata:
title : Glanz
Stream #0:5(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
Metadata:
title : Gavrilov
Stream #0:6(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
Metadata:
title : Zhivov
Stream #0:7(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
Metadata:
title : English
Stream #0:8: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 192 kb/s
Metadata:
title : Comments
Stream #0:9: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
AMFENC: Fatal error when getting output bitstream from encoder.
Break in task AMFENC: device operation failure..
encoded 177166 frames, 383.24 fps, 7443.51 kbps, 6556.79 MB
encode time 0:07:42, CPU: 0.3%, GPU: 3.0%, VE: 100.0%
frame type IDR 739
frame type I 739, avgQP 19.43, total size 74.53 MB
frame type P 176427, avgQP 20.83, total size 6482.26 MB
Expected behavior Throwing an error, like CPU decoder on transcoding does is fine. But crashing decoder thread AND driver, is not. Expected behaviour would be to not attempt to "fix it" and ignore corruption.
For example, that's how CPU decoder throws an error:
--------------------------------------------------------------------------------
Star.Wars.Episode.IV.A.New.Hope.1977.HDTV.1080p_processed.mkv
--------------------------------------------------------------------------------
VCEEnc (x64) 8.21 (r1577) by rigaya, Dec 10 2023 04:01:37 (VC 1937/Win)
OS: Windows 11 x64 (22631) [UTF-8]
CPU: AMD Ryzen 7 5800X3D 8-Core Processor [4.48GHz] (8C/16T)
GPU: AMD Radeon RX 7800 XT [31.0.24002.92]
AMF: Runtime 1.4.33 / SDK 1.4.30
Input Info: avsw: h264(yv12)->nv12 [AVX2], 1920x1080, 24000/1001 fps
Output: H.264/AVC Main @ Level 5.1
1920x1080p 1:1 23.976fps (24000/1001fps)
avwriter: h264, ac3, ac3, ac3, ac3, ac3, ac3, ac3, ac3
=> matroska
Quality: balanced
VBR: 7500 kbps
Max bitrate: 15000 kbps
QP: Min: 0:0, Max: 36:36
VBV Bufsize: 7500 kb
Bframes: 0 frames
Pre Analysis: off
Ref frames: 4 frames
LTR frames: 3 frames
Motion Est: Q-pel
Slices: 1
GOP Len: 240 frames
Others: skipframe:on deblock
[h264 @ 000002cc4a27a300] top block unavailable for requested intra mode 78%, est out size 7099.7MB
[h264 @ 000002cc4a27a300] error while decoding MB 91 56, bytestream 18094
encoded 179207 frames, 518.85 fps, 7462.61 kbps, 6649.34 MB
encode time 0:05:45, CPU: 2.1%, GPU: 4.7%, VE: 75.1%
frame type IDR 747
frame type I 747, avgQP 19.63, total size 75.07 MB
frame type P 178460, avgQP 20.97, total size 6574.28 MB
Screenshots
These frames are causing a crash (screenshot from CPU decoded sample)
Additional context There were 6 videos from same source. (I think you might guess what 6 videos were about). 2 of them were corrupted so they got a crash. But 4 others were skipping fragments (sometimes even large parts, like 20 minutes long) on transcoding, if i used hw decoder. So all 6 were corrupted in some way. Nuance is... Doing hw decode (or even playing video with hw decode) was completely fine on these 4 videos though. Only on hw decode skipping was observed. And by skipping i meant actual skipping, like almost 50000 frames not being encoded, on same length of resulting video. With full source i am losing both video and sound for this fragment. But when i cropped affected part, only video is missing, so file contains 2 seconds of video and 23 minutes of audio.
Here is data on this particular bug or case, idk how to take on it. I kinda don't want to duplicate issue manually. https://github.com/rigaya/VCEEnc/issues/101