Skip to content

Extract codec extradata in add_mux_stream for Matroska#2305

Merged
WyattBlue merged 2 commits into
mainfrom
patch
Jun 14, 2026
Merged

Extract codec extradata in add_mux_stream for Matroska#2305
WyattBlue merged 2 commits into
mainfrom
patch

Conversation

@WyattBlue

Copy link
Copy Markdown
Member

Muxing pre-encoded H.264 packets into Matroska failed in avformat_write_header because the muxer needs CodecPrivate (the codec extradata) before the first packet, but add_mux_stream never set it.

For codec-less mux streams whose format embeds a global header, buffer packets and run the extract_extradata bitstream filter to recover the parameter sets from the bitstream, then set them on codecpar before the header is written. Streams give up after their first packet, so already length-prefixed packets fall back to the muxer's default behavior with no regression. The extraction uses direct libav calls (av_bsf_*, av_packet_get_side_data, memcpy) to avoid per-byte copies and wrapper allocations.

closes #2198

@WyattBlue WyattBlue force-pushed the patch branch 5 times, most recently from 7248205 to 682cc41 Compare June 14, 2026 02:47
Muxing packets into Matroska failed in avformat_write_header because
the muxer needs CodecPrivate (the codec extradata) before the first
packet.

For codec-less mux streams whose format embeds a global header, buffer
packets and run the extract_extradata bitstream filter to recover the
parameter sets from the bitstream, then set them on codecpar before the
header is written. Streams give up after their first packet, so already
length-prefixed packets fall back to the muxer's default behavior with no
regression.

closes #2198
actions/setup-python provides the python.org universal2 CPython, so
setuptools compiled the extensions for arm64 and x86_64. Also stop
installing libvorbis.
@WyattBlue WyattBlue merged commit 5b48f2d into main Jun 14, 2026
13 of 14 checks passed
@WyattBlue WyattBlue deleted the patch branch June 14, 2026 03:23
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.

add_mux_stream does not work properly with matroska.

1 participant