Skip to content

FFmpeg decoders: failure of a decoder handled as an issue of the decoder, not of the file - #561

Merged
JeromeMartinez merged 2 commits into
MediaArea:mainfrom
JeromeMartinez:ffv1-decoder-failure-handling
Nov 27, 2026
Merged

JeromeMartinez merged 2 commits into
MediaArea:mainfrom
JeromeMartinez:ffv1-decoder-failure-handling

Conversation

@JeromeMartinez

Copy link
Copy Markdown
Member

A failure of an FFmpeg decoder (vulkan or ffmpeg) was reported as an issue of the file ("undecodable frame"), also when the decoder itself failed (e.g. GPU memory), and the decoder was used again for the next frames. With FFmpeg 9.0 (libavcodec 63.1) the Vulkan FFV1 decoder then segfaults: when the setup of the hardware decoding of a frame fails partway, the release of this frame dereferences a NULL feedback buffer (vk_ffv1_free_frame_priv), at the next frame or when the decoder is released. This is fixed in FFmpeg master by 898b8aa922 ("vulkan_ffv1: survive setup failures on preceding frames"), not in release/9.0.

FFmpeg decoders: failure of a decoder handled as an issue of the decoder, not of the file

  • Frame with invalid content (AVERROR_INVALIDDATA, which comes only from the parsing of the frame header and of the slice positions, or a slice with a wrong CRC as already checked by us): issue of the frame, reported, the decoder decodes the next frames. In a stream with frames which are not keyframes, the next frames which are not keyframes for this decoder depend on this frame and are reported without being decoded, until the next keyframe (also avoids another FFmpeg 9.0 crash with them).
  • Other failure with a keyframe: the frame is decoded again by the fallback decoder (our decoder, or the FFmpeg decoder on CPU for an FFmpeg decoder with Vulkan, e.g. ffmpeg+vulkan). If the fallback decoder decodes it, issue of the FFmpeg decoder: it is not used for the next frames and an info is shown at the end. Else issue of the frame: the frame is reported and the FFmpeg decoder is used again.
  • Other failure with a frame no other decoder can decode again (not a keyframe, or no fallback decoder): decoding is stopped with an error naming the decoder and suggesting fewer decoders (e.g. --decoder internal+vulkan if there were 2 vulkan decoders on the device). With the auto decoder, early in the file (first 1/256 of the file, or first 256 frames), the check is done again with 1 less FFmpeg decoder with Vulkan on this device (our decoder only after the last one), also for the next files.
  • Before libavcodec 63.8, an FFmpeg decoder with Vulkan which failed is not released (kept until the end of the program).
  • Same rules for the FFmpeg decoder on CPU.

FFV1: issue of a frame not reported for the next frames

Our decoder kept the first error of the stream: after a frame with an issue (e.g. a slice with a wrong CRC), each next frame decoded by our decoder was reported as undecodable, also frames without issue, and also with several decoders in parallel (auto) for the frames decoded by our decoder. The issue is now kept for each frame: reset by a keyframe, inherited by a frame which is not a keyframe.

With a corrupted frame (64 bytes overwritten in the middle of a frame), all decoder combinations (internal, auto, vulkan, ffmpeg, ffmpeg+vulkan, internal+ffmpeg) now report the same frames: only this frame in an intra stream, this frame and the next frames of its GOP in a stream with -g 10. Before, our decoder reported every next frame it decoded.

Failures of the decoders were tested with forced errors (not in this PR): keyframe decoded again by our decoder or by the FFmpeg decoder on CPU, decoder used again if the fallback decoder also fails, stop with vulkan+vulkan, check done again with 1 then 0 vulkan decoder in auto mode, invalid data in intra and non intra streams. No measurable speed change of the check.

Our decoder kept the first error of the stream: after a frame with an issue (e.g. a slice with a wrong CRC), each next frame decoded by our decoder was reported as undecodable, also frames without issue, and also with several decoders in parallel for the frames decoded by our decoder.
The issue is now kept for each frame: it is reset by a keyframe, and a frame which is not a keyframe has the issue of the previous frame (it uses its decoding states).
…der, not of the file

A frame an FFmpeg decoder (vulkan or ffmpeg) failed to decode was reported as an undecodable frame, also when the decoder failed (e.g. GPU memory), and the decoder was used again for the next frames (with FFmpeg 9.0, the Vulkan decoder then crashes).
Now:
- Frame with invalid content (invalid data from FFmpeg, or a slice with a wrong CRC): issue of the frame, reported, the decoder decodes the next frames. In a stream with frames which are not keyframes, the next frames which are not keyframes for this decoder depend on this frame and are reported without being decoded, until the next keyframe.
- Other failure with a keyframe: the frame is decoded again by the fallback decoder (our decoder, or the FFmpeg decoder on CPU for an FFmpeg decoder with Vulkan, e.g. ffmpeg+vulkan). If it decodes it, issue of the FFmpeg decoder: it is not used for the next frames and an info is shown at the end. Else issue of the frame: the frame is reported and the FFmpeg decoder is used again.
- Other failure with a frame no other decoder can decode again (not a keyframe, or no fallback decoder): decoding is stopped with an error naming the decoder, with a suggestion of fewer decoders. With the auto decoder, if it is early in the file (in its first 1/256, or in the first 256 frames), the check is done again with 1 less FFmpeg decoder with Vulkan on this device (our decoder only after the last one), also for the next files.
An FFmpeg decoder with Vulkan which failed is not released before libavcodec 63.8 (e.g. FFmpeg 9.0): FFmpeg crashes when it releases a frame whose hardware decoding setup failed partway, at the next frame or when the decoder is released.
@JeromeMartinez
JeromeMartinez merged commit 1f69dea into MediaArea:main Nov 27, 2026
32 checks passed
@JeromeMartinez
JeromeMartinez deleted the ffv1-decoder-failure-handling branch November 27, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant