Repository navigation
fix(mac): 1080p30 GPU-direct streams ran video at twice real time (release blocker) - #1265
Merged
Merged
Conversation
… destination fps macOS 1080p30 GPU-direct RTMP/SRT/HLS (the shipping default) stamped pictures as frameNumber / 30 while frameNumber counted 60 Hz Program frames: video ran at twice real time (A/V drift about 1 s per second), and VideoToolbox, which budgets bits by PTS, spent about twice the target bitrate. - ProgramFrame::programTick (Metal: the render slot, so skipped slots stay timestamp holes) and GpuVideoEncoder::programTickRate (VideoToolbox: 60). - The sender converts the shared-AAC clock with that rate, and a slower destination picks pictures from the tick grid (every even tick for 30) instead of the wall-clock pacer, which picked frames 1,3,1,3 apart. - The shared encoder pool takes one picture per destination period. - Windows behaviour is unchanged (tick = frame number, rate = destination fps); the Media Foundation encoder has the same defect at 30 fps and is not fixed. - The streaming gate runs 30 and 60 on the 60 Hz canvas, gains an HLS sink, and fails on A/V timestamp drift, video cadence and any audio gap. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…udio PES at Stop Homebrew ffmpeg has no SRT, so the SRT leg could not listen on a Mac; it now falls back to the bundled build. An SRT capture of silent audio carries 17 AAC frames (363 ms) per PES and loses the unfinished one at Stop: 241 ms measured on a healthy run, with a constant video/audio mux position for the whole capture. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…er's wall-second output The raw fallback encodes B-frames, so packet order is decode order: monotonicity is checked on DTS and cadence on sorted PTS. The sender's mux-input Mbps per wall second now gates --check-bitrate: a capture cut at a media-time limit hid the doubled bitrate (6.0 per media second against 12 emitted). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
macOS 1080p30 GPU-direct streaming: video ran at twice real time
Release blocker from the macOS 1.0.0 qualification (installer 14). It hit the shipping default for RTMP, SRT and HLS.
Root cause
The render loop is a fixed 60 Hz, but the VideoToolbox encoder made PTS as
frameNumber / destinationFps(30).ProgramStreamClockanchored audio the same way.Fix
ProgramFrame::programTick: the render slot on Metal. 0 elsewhere, which means the frame number.GpuVideoEncoder::programTickRate: 60 for VideoToolbox. The default is the destination fps, so Windows is unchanged. The sender uses the same rate for audio PTS.ProgramCadenceDecimator: every even tick for 30). The shared encoder pool takes one picture per destination period.Windows (from code only; not run on Windows hardware)
Windows has the same bug at 30 fps on the GPU-direct path.
MediaFoundationGpuVideoEncoder::processInputstampsframeNumber / config.fps.convertToNv12replaces the frame number with the published one). So the sender's 30 fps pacer does not limit what gets encoded: about 60 pictures/s, each stamped 1/30 apart. That means 2x video time, with the rate controller andH264CbrFillerbudgeting 1/30 s per picture.This PR does not change Windows behaviour. The Media Foundation encoder is untouched and keeps the default tick rate. A fix there needs it to encode only the selected pictures and report 60.
The default gate now includes a 30 fps leg, so expect it to fail on Windows until that is fixed.
Gate (
scripts/validate-gpu-encode.mjs)--fpsit runs 30 and then 60 on the 60 Hz canvas, with sources pinned at 60.--sink-protocol hls(local PUT origin). The SRT receiver falls back to the bundled ffmpeg when the system ffmpeg has no libsrt.--check-bitrate).--slow-sinkruns that discard audio will now fail. They were not run here.origin/mainat 30, the gate fails: 66.6 ms cadence, 8.2 s drift (capture cut by-t), 15.0 fps.Real gate results (M3 Max, local sinks, one 1080p60 fake participant, 60 s unless noted)
This was not an idle machine. Parsec, ChatGPT and Chrome were running. Most runs started once the 1-minute load was below 2.45. Runs before about 01:05 were on battery and later runs on AC. This is not a performance qualification.
30 fps (the blocker): A/V clock, cadence and bitrate are correct on all three protocols
GPU_ENCODE=0)(1) These runs predate the
encoder outputline. (2) This is the unfinished MPEG-TS audio PES at Stop. In the first capture, the video-to-audio mux position stayed at 0.345 to 0.347 s from start to end.An earlier raw-fallback run failed only because of a judge bug with B-frame order, fixed in 2c1df92.
60 fps: timestamps and audio are correct, but frame delivery fails intermittently on both this branch and unfixed
origin/main. This is the separate frame-loss problem and was not investigated. Frames are already missing at the sender's mux input.origin/main40a00d6, fpsNo 60 fps run had zero missing pictures. Two early SRT/HLS 60 runs overlapped each other by mistake and are excluded.
An unverified lead from writing the tests: the unchanged 60-on-60 wall-clock pacer rejects a tick more than 1 ms early. A test fixture with +-1.5 ms of jitter lost 143 of 600 frames.
Every counted 60 fps run, on both builds, had A/V offsets within 250 ms and 0 audio gaps.
Tests
node --test scripts/qa/stream-timing-judge.test.mjs, 21/21.ProgramStreamClock(30 and 60, skips, audio phase); a destination-clock (Windows-like) encoder keeping its pacing and units; Metal ticks; the shared pool; the composite anchor.Not fixed, noted by review: on macOS the audio anchor pairs the frame's tick with the time the video-output tick picked it up, so a late pickup at stream start becomes a constant offset of that size. This predates the PR.
Not covered: Windows hardware, HEVC,
--slow-sink, multiple simultaneous destinations on hardware, audio content (the test audio is digital silence, so timestamps only), lip sync, RTMPS, and real platforms.🤖 Generated with Claude Code