Skip to content

Advertise packed sequence headers for encode - #7

Open
vitlav wants to merge 1 commit into
radxa-pkg:masterfrom
vitlav:packed-sequence-headers
Open

vitlav wants to merge 1 commit into
radxa-pkg:masterfrom
vitlav:packed-sequence-headers

Conversation

@vitlav

@vitlav vitlav commented Sep 23, 2026 •

Copy link
Copy Markdown

Summary

Fixes #6: muxing freshly encoded HEVC into Matroska fails because the backend reports VA_ENC_PACKED_HEADER_NONE, and FFmpeg then explicitly refuses to write a global header ("No global header will be written: … not muxable to some containers", vaapi_encode.c). Matroska requires hvcC extradata at write_header time, so hevc_vaapi → .mkv aborts. H.264 → MP4 only works by accident: the MP4 muxer extracts the in-band SPS/PPS from the first packet, which Matroska does not do for HEVC.

Changes

  • report VA_ENC_PACKED_HEADER_SEQUENCE for VAConfigAttribEncPackedHeaders, so clients generate their own sequence headers and build container extradata from them;
  • accept VAEncPackedHeaderParameterBufferType / VAEncPackedHeaderDataBufferType in buffer creation and encode rendering, discarding the payload — the stateful encoder already emits equivalent sequence headers in-band, and nothing can be spliced into its coded stream.

Note

The container extradata is client-generated (FFmpeg's own VPS/SPS/PPS), so it may not be byte-identical to the firmware's in-band headers; decoders pick up the in-band parameter sets.

Validation

Validated on Qualcomm SC7180 (TCL B220G, qcom-venus, together with #5): direct hevc_vaapi → Matroska muxing now succeeds without the extract_extradata remux workaround.

Clients such as FFmpeg only write container extradata (avcC/hvcC) when
the driver accepts VA_ENC_PACKED_HEADER_SEQUENCE; with
VA_ENC_PACKED_HEADER_NONE they refuse to produce a global header, so
muxing freshly encoded HEVC into Matroska fails at write_header.

Advertise the sequence bit and accept the packed header buffers without
splicing their payload into the coded stream: the stateful encoder
already emits equivalent sequence headers in-band.

Fixes radxa-pkg#6.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vitlav
vitlav marked this pull request as ready for review September 23, 2026 09:15
@nyanmisaka

nyanmisaka commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

so it may not be byte-identical to the firmware's in-band headers

This causes the latest version of FFmpeg, when using -tag:v hvc1 with the MP4 muxer, to produce videos that fail to play in Safari, Firefox, and MPC-BE. This will also break the ability to generate cross-platform compatible fMP4 segments from encoded video using hlsenc muxer.

The out-of-band PS written by FFmpeg is inconsistent with the actual in-band PS, and the in-band PS is removed when hvc1 is used.

See also https://gitlab.freedesktop.org/mesa/mesa/-/work_items/15529

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.

HEVC VAAPI encode does not provide container extradata on Venus

2 participants