Skip to content

fix(build): the mpegts muxer writes the Dolby Vision descriptors - #11

Merged
superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
MistyKuu:fix/mpegts-dovi-descriptor
Nov 16, 2026
Merged

superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
MistyKuu:fix/mpegts-dovi-descriptor

Conversation

@MistyKuu

Copy link
Copy Markdown
Contributor

Summary

A Dolby Vision live channel recorded with AetherEngine's startRecording(to:) plays back without Dolby Vision. Checked on AetherEngine main (95ee3ce, after 7.68.0) and on 7.53.1: Profile 8.1 plays back as HDR10, Profile 8.4 as HLG, Profile 5 as HDR10 with the wrong colours.

Cause: the recording is a stream copy into MPEG-TS, and FFmpeg's mpegts muxer never writes the Dolby Vision descriptors. The demuxer reads the DOVI video stream descriptor (0xb0) into AV_PKT_DATA_DOVI_CONF, and avcodec_parameters_copy carries that record to the output stream, but mpegtsenc.c has no code for it (n8.1.3, n9.0.2 and master alike). The file keeps every RPU and loses the record, and the engine routes Dolby Vision from that record.

What changed

  • patches/mpegts-dovi-descriptor.patch, applied by patch_ffmpeg_mpegts_dovi_descriptor: for a video stream whose record declares a base layer, the PMT gets the DOVI registration descriptor and the 0xb0 descriptor built from the record (version, profile, level, the present flags, base-layer compatibility id, metadata compression; the two reserved bits set). This is the layout the demuxer already parses.
  • A stream without a base layer (a Profile 7 enhancement-layer PID) is left as it was: its descriptor also needs the base layer's PID, which the record does not carry. A stream without a record gets nothing new.
  • New MPEGTSDolbyVisionDescriptorTests: muxes HEVC with a record through the shipped mpegts muxer and opens the file the way a player does. Records 8.1, 8.4, 8.2, 5, single-PID 7 and one with metadata compression come back unchanged, with the DOVI registration in the PMT. No record, and an enhancement layer without its base layer, get no descriptor.
  • README: the patch in the list (and the count, which said twelve for thirteen).

This PR carries only the source changes; the xcframeworks need a rebuild on your side. Not proposed to FFmpeg upstream yet.

Test plan

  • Mac17,4 (M5), macOS 27.2, Xcode 27.2. Not run on an Apple TV.
  • Build: ./build.sh reduced to the macos-arm64 slice (my Xcode 27 has no Metal toolchain, so that local build had --disable-metal and no yadif_videotoolbox). Only the rebuilt AetherLibavformat was put in place of the 3.15.0 one, so before and after differ in libavformat alone.
  • swift test on 3.15.0: the new suite fails (no record read back, no DOVI registration). With the patched libavformat: all 50 tests in 17 suites pass.
  • AetherEngine main pointed at this build, end to end on real HEVC: x265 4.3 and dovi_tool 2.3.4 encode 45 s of 3840x2160 10-bit as Profile 8.1, 8.4 and 5, muxed to TS with the descriptors (the source shape a broadcast DV channel has). A local HTTP origin serves each as a live channel, the engine plays it, records 20 s with startRecording(to:), then plays the file:
Source Recording on 3.15.0 Recording with this patch
DV 8.1 no record, plays as hdr10, served hvc1 8.1 record, plays as dolbyVision, served hvc1 + dvh1.08.06/db1p
DV 8.4 no record, plays as hlg, served hvc1 8.4 record, plays as dolbyVision, served hvc1 + dvh1.08.06/db4h
DV 5 no record, plays as hdr10 (IPT read as YCbCr), served hvc1 5 record, plays as dolbyVision, served dvh1.05.06
HDR10 unchanged unchanged
HLG unchanged unchanged

In every case the recording now takes the same route as the live channel. Every access unit of every recording carries its RPU, before and after.

  • AetherEngine side, on a branch of my fork (fix/recording-keeps-dolby-vision): a LiveRecordingWriterTests case that records Profile 8.1, 8.4 and 5 and reads the record back through AetherEngine.dvConfig(stream:). It fails on 3.15.0 and passes with this build. I can open it together with the pin bump once a release carries this, or you can take it with the bump.

Checklist

  • The fix lives in FFmpeg's muxer, not in a host-side workaround
  • Patch documented in place in build.sh and in the README list
  • Test that fails before and passes after
  • Commit message follows Conventional Commits

FFmpeg reads the DOVI video stream descriptor (0xb0) of a transport
stream into AV_PKT_DATA_DOVI_CONF, but its mpegts muxer never writes
it. A Dolby Vision stream copied into MPEG-TS, which is what
AetherEngine live recordings are, kept every RPU and lost its record,
and played back as HDR10 (Profile 8.1), HLG (8.4) or HDR10 with the
wrong colours (5).

patch_ffmpeg_mpegts_dovi_descriptor applies
patches/mpegts-dovi-descriptor.patch: a video stream whose record
declares a base layer gets the DOVI registration descriptor and the
0xb0 descriptor built from the record. MPEGTSDolbyVisionDescriptorTests
round-trips records through the muxer and the demuxer.
@superuser404notfound
superuser404notfound merged commit 297b19f into superuser404notfound:main Nov 16, 2026
@superuser404notfound

Copy link
Copy Markdown
Owner

Thanks a lot, this is a really clean one. I checked the descriptor against what mpegts.c parses and the PMT space check, everything lines up, so I merged it as is.

On top I rebuilt every slice with the patch (8912e78). All 50 tests pass, the new suite included.

I also took it upstream as https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26097, with you credited in the commit message and the PR text. Master's muxer has moved a bit since n8.1.3, so the patch is rebased there and comes with two FATE tests on the existing mov/dovi-p5.mp4 and mov/dovi-p81.mp4 samples. I left the dual-PID Profile 7 case out there too, but noted that master's demuxer now builds Dolby Vision stream groups, so the base layer's PID could come from there in a follow-up.

The next FFmpegBuild release will carry this. Once it's out, feel free to open your LiveRecordingWriterTests case together with the engine bump.

@superuser404notfound

Copy link
Copy Markdown
Owner

Released in 3.16.0 (7de456f), and AetherEngine main pins it since 572a8f7a. So your LiveRecordingWriterTests case from fix/recording-keeps-dolby-vision can go in as a PR against AetherEngine now, if you still want to send it.

superuser404notfound pushed a commit to superuser404notfound/AetherEngine that referenced this pull request Nov 19, 2026
superuser404notfound pushed a commit to superuser404notfound/AetherEngine that referenced this pull request Nov 19, 2026
…ix the NAL comment

Follow-up to PR #1096 from Quint's review: the record attach no longer
drops its result (a failure would have leaked the record and failed later
on a nil profile), the codecpar goes through avcodec_parameters_free so
its side data is released, and the NAL header comment describes the one
byte annexBPayload writes.

Refs superuser404notfound/FFmpegBuild#11

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SeT6NgMt1vv32kPBhUmsUz
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.

2 participants