Skip to content

Put constant-frame-rate video on an exact frame grid when the source time base is coarse (Matroska's 1 ms), for an even 3:2 cadence at 60 Hz #886

Closed

Description

@akhanwav

What should the engine do?

When a constant-frame-rate video stream arrives on a coarse time base (Matroska's 1/1000 s), remux its timestamps onto the exact frame grid (n x 1001/24000 s for 23.976) in a fine timescale, instead of passing the millisecond-rounded values to AVPlayer.

Motivating media or use case

With Match Content off, so the panel stays at its 59.94 Hz home mode, 24p MKVs play with uneven motion through the native path. A player that presents frames itself (Infuse) plays the same files smoothly at the same output.

What we measured on the native path, from setNativeVideoFrameTimeObserver (item-axis times, sorted, 1,200 frames per window):

Source Spacing handed to AVPlayer Exact spacing
4K HEVC DV P7 MKV, 23.976 fps 41 ms x350, 42 ms x848 (one 84 ms gap) 41.708 ms
1080p H.264 MKV, 24.000 fps 41 ms x400, 42 ms x799 41.667 ms

The muxer keeps the source time base (MP4SegmentMuxer.swift:587, videoStream.pointee.time_base = video.timeBase, from HLSVideoEngine.swift:1443), so the fMP4 carries timescale 16000 with millisecond-quantized values. Each frame is up to 0.5 ms off its true time. The panel measured 59.944 Hz over 600 vsyncs.

Why that matters at 59.94 Hz: a 23.976 frame lasts exactly 2.5 refreshes, so every second frame's true time sits on a refresh boundary, the worst case for a 3:2 cadence. Rounding of up to 0.5 ms is enough to move those frames to the neighbouring refresh, which would turn the steady 3, 2, 3, 2 into bursts of 3, 2, 2, 3. With exact timestamps the cadence stays regular, and slips once where the content and panel rates differ.

What we have not shown: we did not capture the on-screen cadence with a high-speed camera, so the jitter is measured but its effect on screen is inferred. The timestamps were measured on 7.32.3; the muxer lines above are unchanged in 7.47.0. With Match Frame Rate on (one refresh per frame), no difference was seen and AVPlayer reported 0 dropped frames over 6 minutes.

Implementation thought: rounding each PTS and DTS to the nearest grid slot (round(t x fps)) keeps reorder order and moves video at most half a millisecond against audio. It could be limited to streams whose observed deltas all fall within one tick of the detected rate, so VFR and edited sources keep their own timestamps.

Area

Performance

Host app / integration context

Rivulet (tvOS), native loopback path, Apple TV 4K (3rd generation), tvOS 26.6

Would you be willing to open a PR?

No

Activity

  1. superuser404notfound commented on Oct 27, 2026

    @superuser404notfound
    Owner

    Thanks for the measurement and the pointer to the muxer line, that made this straightforward to reproduce.

    Reproduced on main with a 23.976 fps H.264 MKV served through aetherctl serve: the fMP4 carried timescale 16000 and the video samples alternated 656 and 672 ticks (41 / 42 ms), matching your table.

    Merged in bb1e24e2, not released yet. What it does:

    • A VOD video track whose source tick is 0.1 ms or coarser, and whose rate probes as exactly a standard rate the tick cannot hold (23.976, 24, 29.97, 30, 47.952, 48, 59.94, 60), is now muxed on a timescale with one frame in whole ticks: 1/24000 with 1001 ticks a frame for 23.976, 1000 for 24.000, 1/30000 for 29.97. 25 and 50 fps already fit 1 ms and are unchanged.
    • Each PTS within one source tick of a grid slot is placed on that slot, the grid anchored at the stream's start time. The DTS takes its own slot and never passes the PTS. Timestamps farther off keep their own time, so VFR or edited stretches pass through untouched.
    • The grid is derived from stream fields only (time base, rate, start time), not from observed packets, so every producer of a session writes the same init timescale and a restarted segment matches its continuous twin.

    Verified with aetherctl: 23.976 now reads 1001 ticks on every sample, 24p 1000, a 1.4 s start offset stays uniform, segments are contiguous, and a throttled seektest with two real producer restarts kept every packet on the grid. Video moves at most about half a millisecond against audio.

    Like you, I have not filmed the on-screen cadence, so the effect at 59.94 Hz is still inferred from the timestamps. A check against your DV P7 file once this is in a release would be very welcome.

  2. superuser404notfound commented on Oct 27, 2026

    @superuser404notfound
    Owner

    Released in 7.49.0: 24p Matroska video goes out on its exact frame grid. Together with #883 in the same release it also builds on Xcode 26.3 again, so the 3:2 cadence check at 60 Hz can run against 7.49.0.

  3. akhanwav commented on Oct 28, 2026

    @akhanwav
    Author

    Thanks, this is fixed in 7.49.0. Tested on an Apple TV 4K (3rd gen, tvOS 26.6) with Match Content off (panel at 59.944 Hz), using setNativeVideoFrameTimeObserver item times:

    Source 7.42.0 7.49.0
    4K HEVC DV P7 MKV, 23.976 41 / 42 ms, timescale 16000 every frame 1001/24000 s, timescale 24000
    1080p H.264 MKV, 24.000 41 / 42 ms every frame 1000/24000 s

    Every frame is on the exact grid, with no missing frames across 2,600 to 3,900 frames per run, and AVPlayer reported zero dropped frames. Sampling the item timebase at every vsync showed a perfect 3:2 cadence at 59.94 Hz (alternating 3 and 2, no repeats in 10-second windows) on the DV title, both as 8.1 and as the HDR10 base layer. The occasional 2 to 3 frame gap I saw earlier was an artifact of my own measurement windows cutting frames in decode order, not a missing frame. Thanks again!

  4. superuser404notfound commented on Oct 29, 2026

    @superuser404notfound
    Owner

    Thanks for the thorough retest, and for measuring it at vsync level. Good to have the 3:2 cadence at 59.94 Hz confirmed on the DV P7 title in both 8.1 and the HDR10 base layer, plus the 24.000 case. Closing as fixed in 7.49.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions