avformat/mpegtsenc: write the Dolby Vision descriptors #26097
No reviewers
Labels
No labels
avcodec
avdevice
avfilter
avformat
avutil
backport/release/4.3
backport/release/4.4
backport/release/5.0
backport/release/5.1
backport/release/6.0
backport/release/6.1
backport/release/7.0
backport/release/7.1
backport/release/8.0
backport/release/8.1
backport/release/9.0
backport/release/9.1
CLI
doc
Forgejo Fairy
swresample
swscale
vulkan
API
API major
bug
enhancement
fix/bug
fix/regression
GSoC
GSoC-Qualification
help wanted
important
LGTM
meta
needs backport
needs docs
needs fate test
needs info
needs sample
needs testing
new
question
regression
repro
flaky
repro
no
repro
no(env)
repro
yes
resolution
duplicate
resolution
external
resolution
fixed
resolution
invalid
resolution
wontfix
security
small
No milestone
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
FFmpeg/FFmpeg!26097
Loading…
Reference in a new issue
No description provided.
Delete branch "superuser404/FFmpeg:mpegts-dovi-descriptor"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The mpegts demuxer reads the DOVI video stream descriptor (0xb0) into
AV_PKT_DATA_DOVI_CONF, but the muxer never writes it. A Dolby Vision stream copied into MPEG-TS keeps every RPU and loses its configuration record:A player that routes Dolby Vision from the record then plays a Profile 8.1 copy as HDR10, Profile 8.4 as HLG, and Profile 5 as HDR10 with IPT-PQ-c2 decoded as YCbCr. We hit this with live TV recordings, which are a stream copy from a broadcast TS into a TS file.
Three commits:
avformat/mpegtsenc: check that a whole video entry fits the PMT. The PMT writer only kept a fixed 32-byte margin per entry, which does not bound the LCEVC linkage descriptor. A video entry is now sized before it is written and takes the existing truncation path when it would not fit the 1012 bytes a section can carry.avformat/mpegtsenc: write the Dolby Vision descriptors(Zbigniew Szepczyński, with my changes listed in the message). For an H.264 or HEVC stream whose record carries both the base layer and the RPU, write the 0xb0 descriptor from "Dolby Vision Streams Within the MPEG-2 Transport Stream Format" v1.2, and for compatibility ID 0 (Profile 5) also theDOVIregistration, ahead of the codec registration socodec_tagstaysHEVC.fate/mpegts: test Dolby Vision signalling on stream copy.Two deliberate departures from v1.2, both explained in the commit message:
dv_md_compressionin bits 3-2, where the demuxer reads it sincece8166a19c, instead of four reserved bits.Not covered: a dual-PID enhancement layer (needs the base layer's PID and stream_type 0x06, could come from the Dolby Vision stream group the demuxer now builds), and the HEVC video descriptor (0x38), which this muxer does not write for any HEVC stream.
Tests:
fate-mpegts-dovi-write-p5,-p81and-p7-blcopymov/dovi-p5.mp4,mov/dovi-p81.mp4andmov/dovi-p7-hvce.mp4(the last throughdovi_split=mode=bl) into MPEG-TS and probe codec, codec tag and record back. The first two fail on master, all three fail on the first version of this PR. Full FATE on macOS arm64 ran 6188 tests; the only 16 failures are tests whose samples my local copy of the suite lacks (sacd, g723_1, cavs-avsplus and a few more), none of them in mpegts.The muxer change comes from a patch Zbigniew wrote for FFmpegBuild, https://github.com/superuser404notfound/FFmpegBuild/pull/11, where it was also checked end to end on Profile 8.1, 8.4 and 5 recordings.
LLM
Findings
Major — The added descriptors can overrun the PMT buffer or suppress the entire PMT (
309cd6afc2, libavformat/mpegtsenc.c:879).The guard at line 611 reserves 32 bytes. An HEVC entry now uses 24 bytes before the variable-length LCEVC linkage descriptor, which needs another
4 + nb_stream_groups. The muxer checks that each LCEVC group has two members, but that does not bound how many groups reference this stream. The linkage write was already unbounded; the extra 13 bytes make previously fitting entries unsafe. There is also a smaller on-wire limit:mpegts_write_section1()accepts only 1,012 payload bytes after accounting for the header and CRC. GPT-6.2-SOL observed a program for which the parent wrote a PMT and the patch wrote only the PAT, with muxing still reporting success. Please check the complete video entry before writing its first byte, against the remaining section payload, and take the existing logged truncation path if it will not fit. Increasing the fixed allowance alone does not bound the linkage. — GPT-6.2-SOL, GROK-4.7Major — The imported muxer implementation needs its original Git author (
309cd6afc2, libavformat/mpegtsenc.c:369).All 38 added muxer lines match Zbigniew Szepczyński’s patch in FFmpegBuild #11, aee6ff889860. The commit message credits him, but the Git author is Vincent.
doc/developer.texiasks that the commit author be set correctly. I pushed fairy/pr26097-attribution-and-fate as a starting point: c37e24c83023 preserves Zbigniew’s authorship of the muxer change, and 6b8315ba83b9 keeps Vincent’s authorship of the FATE tests and fixes their dependencies. The branch deliberately leaves the muxer behavior unchanged; it is not a merge-ready replacement. (github.com) — GPT-6.2-SOL, GPT-6-SOLModerate — The new registration changes a working HEVC-to-AVI stream copy into an unidentified video stream (
309cd6afc2, libavformat/mpegtsenc.c:879).libavformat/mpegts.c:2315assignscodec_tagfrom each registration descriptor. WithDOVIlast, the Profile 5 TS still probes ashevc/DOVI, but copying it to AVI givesunknown/DOVI; the same operation on the parent giveshevc/HEVC. I also reproduced this for Profile 8.1. With the current pair of registrations, movingput_dovi_descriptor(&q, st->codecpar);before the codec-registration block preserves both the Dolby record and a recognizable AVI FourCC. That addresses the ordering regression, not the Profile 5 mapping below. Please includecodec_tag_stringin the probe check. (github.com) — GROK-4.7Moderate — The Profile 5 test passes with the wrong PMT stream type for the cited specification (
309cd6afc2, libavformat/mpegtsenc.c:418).Both test files use
0x24. In Dolby Vision Streams Within the MPEG-2 Transport Stream Format v1.2, §§7.1.1–7.1.2, that is correct for Profile 8.1, but the Profile 5 sample’s compatibility ID of zero calls for0x06andDOVIregistration. Both cases also require a codec video descriptor; theHEVCregistration (0x05) is not the HEVC video descriptor (0x38). Profile 8.1 does not require the extraDOVIregistration. (professional.dolby.com)Changing just the type in an already-written Profile 5 PMT does let FFmpeg read HEVC when the
HEVCregistration remains, as GPT-6-SOL reported. Changing the muxer’s type selection alone is different: line 873 would then omit that registration. Without it, my reduced build read the0x06stream asbin_datadespite finding the Dolby record. Please test both the emitted PMT type and codec identification. If0x24is intentional for the broadcast receivers you target, could you identify the convention or specification revision and document why it is needed? (github.com) — GPT-6.2-SOL, GPT-6-SOL, GROK-4.7Moderate — A base layer without Dolby metadata gets advertised as Dolby Vision (
309cd6afc2, libavformat/mpegtsenc.c:380).With
mov/dovi-p7-hvce.mp4and-c copy -bsf:v dovi_split=mode=bl, the output PMT advertises Profile 7 even though the filter removed both the RPU and enhancement layer. For this single-PID path, useif (!dovi->bl_present_flag || !dovi->rpu_present_flag) return;. Also restrict this AVC/HEVC signaling path to those codecs: AV1 Profile 10 can supply the same side-data type, but this muxer carries AV1 as private data. Leaving dual-PID enhancement-layer support for a follow-up is reasonable; that descriptor needs a base-layer PID not present in the record. (professional.dolby.com) — GPT-6.2-SOLModerate — Both FATE targets select configurations that cannot produce their references (
309cd6afc2, tests/fate/mpegts.mak:86 and :90).Disabling only
EXTRACT_EXTRADATA_BSFremoves the#extradataline; disabling onlyHEVC_PARSERremoves the ten packet rows. The Dolby record still reads back in both cases. For the currenttranscodetests,$(call REMUX, MPEGTS, MOV_DEMUXER HEVC_DECODER HEVC_PARSER EXTRACT_EXTRADATA_BSF)fixes selection. I verified that the published branch selects and passes both tests with those components enabled, and omits them when either is disabled. A remux-and-probe test focused on PMT signaling would also avoid depending on unrelated packet output. — GPT-6.2-SOLConditional issues
Moderate if v1.2 is the target — The final descriptor nibble has two interpretations (
309cd6afc2, libavformat/mpegtsenc.c:394).Table 3-2 reserves all four bits; the patch writes
dv_md_compressioninto two of them, matching FFmpeg’s reader. The existingmpegts/dovi-p7.tsillustrates why changing the writer alone is not a fix: its last byte is0x6f, which FFmpeg reads as extended compression. I could not verify a later TS specification assigning those bits. Could you cite the intended TS revision, or document that this is compatibility with an existing reader convention? (professional.dolby.com) — GPT-6.2-SOL, GPT-6-SOL, GROK-4.7Minor, unverified — Is the same signaling intended in M2TS mode (
309cd6afc2, libavformat/mpegtsenc.c:879)?The Profile 5
.m2tsoutput contains both the program-levelHDMVregistration and the new elementary-stream descriptors. The Blu-ray exception described atlibavformat/mpegts.c:2658concerns a dual-PID enhancement layer, so it does not establish that this single-PID output is invalid. tsMuxer omits the descriptors in Blu-ray mode, but no player failure was verified here. (github.com) — GROK-4.7Verification
The intended configuration round trip works on the supplied samples (
309cd6afc2).Both new FATE tests passed on Linux arm64 for GPT-6.2-SOL, GPT-6-SOL and me with the parser and filter enabled. GROK-4.7 matched the reference file sizes and checksums. I confirmed the Profile 5, 8.1 and single-PID 7 descriptor payloads directly. NUT, MP4 and MOV retained HEVC identification in the remux check; the demonstrated FourCC regression is specific to AVI among those outputs. I did not run full FATE.
Classification
Major issues — Please revise before merging.
Preserving the record fixes the reported playback path, and the two reference cases demonstrate that benefit. But writing beyond a fixed array and losing the PMT for a previously writable program meet the major-issue criteria independently of the specification questions. The imported implementation also falls under the project’s Git-authorship rule. Those are the reasons to hold the PR, not the deferred dual-PID feature or the unverified Blu-ray concern. (ffmpeg.org)
309cd6afc2d0bd044011Thanks for the review. I force-pushed a reworked branch, now three commits, and updated the description.
1. PMT size. Reproduced with one LCEVC group on a Dolby Vision base after 88 audio entries. master writes the PMT (section_length 1013), the previous head wrote none. The new first commit sizes a video entry's descriptors (codec registration, Dolby Vision, LCEVC linkage) before writing it and checks the entry against the 1012 bytes
mpegts_write_section1()accepts, falling back to the existing logged truncation. Same setup now: Profile 8.1 fits (section_length 1020), Profile 5 logs "cannot fit stream 89" and writes the other 89 entries.2. Authorship. The muxer commit is authored by Zbigniew now, with my changes listed at the end of the message. The tests are a separate commit under my name. I made the split myself instead of taking your branch, because the muxer code changed for points 3 to 5.
3. Codec tag. The Dolby Vision descriptors now go before the codec registration, so the last registration the demuxer reads is
HEVCagain. The tests printcodec_tag_string, and copying the Profile 5 TS to AVI giveshevc/HEVC.4. Stream type. Checked against v1.2, you are right on both counts. 7.1.1 (compatibility ID non-zero) asks for 0x24 and no
DOVIregistration, 7.1.2 (compatibility ID 0) asks for 0x06 with the registration. The registration is now written only for compatibility ID 0, so Profile 8.x gets just the 0xb0 descriptor, which the demuxer reads without the registration.Profile 5 keeps 0x24 on purpose. With 0x06 this demuxer reads it as data, and so does any player that does not know Dolby Vision. tsMuxer made exactly this change in January 2023 and reverted it two weeks later because VLC could no longer play the files, while a 0x24 Profile 5 TS played on an LG C1 (https://github.com/justdan96/tsMuxer/issues/662). The commit message and a comment at the write say so. The HEVC video descriptor (0x38) is missing for every HEVC stream this muxer writes, Dolby Vision or not, so I left it for a separate change.
5. Base layer without RPU. The record now needs both
bl_present_flagandrpu_present_flag, and the codec has to be H.264 or HEVC.dovi_split=mode=blclearsrpu_present_flagin its output record, so the stripped Profile 7 base layer gets nothing;fate-mpegts-dovi-write-p7-blcovers that. Dual-PID enhancement layers stay a follow-up.6. FATE. The tests are remux and probe now (
ffmpeg -c copy -f mpegts - | ffprobe -show_entries stream=codec_name,codec_tag_string:stream_side_data_list pipe:), with no packet output. Dependencies areMOV_DEMUXER MPEGTS_MUXER MPEGTS_DEMUXER FILE_PROTOCOL PIPE_PROTOCOL, plusDOVI_SPLIT_BSFfor the third test; configure already selectshevc_mp4toannexbfor the mpegts muxer. I checked this with two--disable-everythingbuilds. Withoutdovi_splitthe first two run and pass and the third is not selected, and withouthevc_mp4toannexbenabled by hand all three still run and pass.Last nibble. I can't cite a later TS revision. It follows the demuxer, which reads
dv_md_compressionfrom bits 3-2 sincece8166a19c, the same place as in dvcC. Writing the v1.2 reserved bits as 1111 would come back from our own demuxer as compression 3 (extended), which is whatmpegts/dovi-p7.tsshows today. Documented in the commit message and in a comment.M2TS. I kept the descriptors in m2ts mode.
m2ts_modecovers any BDAV file, not only disc authoring. tsMuxer leaves them out only in its Blu-ray mode and writes them for plain .m2ts output, and a Blu-ray disc carries Dolby Vision as dual-PID Profile 7, which this patch does not touch. If you'd rather leave m2ts unchanged, it is one condition.Full FATE on macOS arm64 ran 6188 tests; the only 16 failures are tests whose samples my local suite lacks (sacd, g723_1, cavs-avsplus and a few more), none in mpegts. The first commit alone builds without warnings, and on it all existing mpegts tests pass.
LLM
Replies
Reply — The documented compatibility choices address the earlier questions; superuser404’s update.
Retaining Profile 5 stream type
0x24is an interoperability workaround, not strict conformance to Dolby Vision Streams Within the MPEG-2 Transport Stream Format v1.2. The reported VLC failure, LG C1 playback result and decision to revert in tsMuxer #662 support its benefit. Likewise, the compression bits preserve the existing FFmpeg reader convention; v1.2, Table 3-2 still reserves that nibble. Both departures are now explicit. Keeping the generally missing HEVC video descriptor and dual-PID support as follow-ups is reasonable. The previous M2TS concern remains unverified and does not justify requesting a mode restriction. — GPT-6.1-SOL (code/design), GROK-4.7Findings
Minor — The test commit describes the wrong baseline;
d0bd044011, commit-message paragraph beginning “On the parent commit all three fail”.Its parent,
5b4dee1cb5, already contains the descriptor writer and RPU guard;d0bd044011changes only tests. The stripped Profile 7 output also matches the negative reference with the muxer fromd686652a8a, before descriptor writing was added. Please replace that paragraph with:This wording distinguishes the existing failures from the new negative test. — GPT-6.1-SOL (code/design)
Resolved issues
Resolved Major — Complete video entries are checked before writing;
d0bd044011, libavformat/mpegtsenc.c:674.The sizing helper agrees with the video descriptor writes and includes the variable-length LCEVC linkage. The limit is the section writer’s 1,012-byte payload capacity. The normal Profile 5 and 8.1 entries are respectively 24 and 18 bytes, confirmed against emitted PMTs. This addresses the earlier video-entry overflow and PMT-loss finding. — GPT-6.1-SOL (code/design), GROK-4.7
Resolved Major — Original authorship is preserved;
5b4dee1cb5, commit metadata.Zbigniew Szepczyński is now the muxer commit’s Git author, Vincent’s modifications are identified, and the tests retain Vincent’s authorship separately. — GROK-4.7
Resolved Moderate — Codec registration and stripped-base-layer signaling are corrected;
5b4dee1cb5, libavformat/mpegtsenc.c:370 and :932.Dolby descriptors precede the codec registration, and eligibility requires H.264/HEVC with both BL and RPU present. The tests confirm
hevc/HEVC, retained Profile 5/8.1 records, and no record after the Profile 7 base-layer split. GROK-4.7 also reports successful Profile 5/8.1 copies to AVI. — GPT-6.1-SOL (code/design), GROK-4.7Resolved Moderate — The revised FATE tests work without the previously missing dependencies;
d0bd044011, tests/fate/mpegts.mak:86.All three passed in my reduced build with the HEVC parser, decoder and
extract_extradatadisabled. Configure selectshevc_mp4toannexbthrough the MPEG-TS muxer, and the third test explicitly requiresdovi_split. — GPT-6.1-SOL (code/design)Verification
Independent checks passed at
d0bd044011.The exact-head reduced build and three new FATE tests passed. Emitted Profile 5/8.1 PMTs matched GROK-4.7’s reported bytes and section lengths. Unstripped single-PID Profile 7 retained its configuration record, including the EL flag. The baseline check confirmed the commit-message correction.
git diff --checkpassed.The drafts report additional coverage, with stated limits.
Both GPT-6.1-SOL reviews report passing tests in two reduced arm64 configurations and successful PMT boundary checks; the code review also reports an independent first-commit build. GROK-4.7 reports AVI round trips and preservation of the single-PID Profile 7 enhancement-layer payload. The design review’s four interleaved runs per revision yielded medians of 3.30 versus 3.31 seconds under high host load; these do not establish a meaningful performance difference. None of the drafts claims full FATE or hardware playback validation.
Classification
Minor issues, approve — The remaining correction is confined to the test commit’s explanation.
This meets the supplied rule classifying minor inconsistencies between commit messages and implementation as minor, and the
minor_issues_approvedefinition permits merging with such non-blocking corrections. The earlier substantive findings are addressed, the focused tests pass, and the compatibility departures have a documented rationale. This also follows the development policy’s requirements for informative commit messages and adequate, proportionate testing in doc/developer.texi.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.