Repository navigation
Conversation
get_video_capture_fps demuxed up to 20,000 video packets, so opening a constant-rate recording in the editor read the whole display track on every open. It now reads the timestamps from the container sample index, and falls back to the packet scan when the index does not cover the track (fragmented files), the stream reorders frames, or an entry is marked discard.
…d tracks Adds a variable-rate fixture that is healed to its capture rate and a constant-rate fixture whose stored fps differs from its track, plus a track-heal-benchmark example that reports the time and bytes read per heal check.
…osition offsets The sample index holds decode times while the packet scan used presentation times, so a track with varying composition offsets could measure a different capture rate. The index is now used only when track_has_no_composition_offsets holds; that check and its box helpers move unchanged from cap-video-decode to cap_enc_ffmpeg::mp4_boxes so both crates share them.
Contributor
|
@AatmanAJ is attempting to deploy a commit to the Cap Software Inc Team on Vercel. A member of the Team first needs to authorize it. |
Member
|
@greptileai review |
This branch has not been deployed
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.
Demo
Opening a long constant-rate recording in the editor no longer reads its whole display track. On a 10-minute 1080p30 recording the editor reads 8.8 MB instead of 1,191 MB while it opens, and with a cold disk cache the first frame shows 2.8x sooner. With a warm cache it's 1.5x sooner, and a 5-second recording opens in the same time as before.
Full film (24 s) · 8 s cut · Square cut
Why it was slow
Every editor open runs
editor_window::preflight, which runstrack_heal::heal_stretched_tracks. Its first step,heal_average_display_fps, checks whether a recording's stored display fps is the track's average rate (an older finalization bug). When it is, it callsget_video_capture_fps, which demuxed up to 20,000 video packets to measure the capture rate from their timestamps.A healthy constant-rate recording (video, games, steady scrolling) has a stored fps equal to its average and a capture rate equal to both. Nothing gets rewritten, so the check repeats on every open. At 1080p30 that means reading the first 11 minutes of the file; at 60 fps, the first 5.5 minutes.
What changed
get_video_capture_fpsreads the timestamps from the container's sample index (avformat_index_get_entry), which the MP4 demuxer builds from themoovbox without touching sample data. The timestamps, the 20,000-sample cap andcapture_fps_from_timestampsare unchanged, so the result is the same.video_delay > 0), or an entry is marked discard by an edit list.track_has_no_composition_offsetsfromcrates/video-decode/src/avassetreader.rs. It moves, with its box-parsing helpers and unchanged, tocap_enc_ffmpeg::mp4_boxesso both crates share one copy.avassetreader.rsis macOS-only and now imports it.crates/recording/examples/track-heal-benchmark.rstimesheal_stretched_trackson a project and reports bytes read from/proc/self/io.Results
Linux x86_64 VM, 4 vCPU, release builds, mean of 3 alternating runs. Cold runs drop the page cache first (
echo 3 > /proc/sys/vm/drop_caches). The 10-minute project is 1080p30 testsrc2 with libx264 (1.18 GB display track, 18,000 frames) plus an Opus mic track. The 5-second project is the same recipe.Editor open, measured in the GPUI app under Xvfb from the
editor window openedlog line, with whole-processrcharat first frame:The heal check alone (
track-heal-benchmark):Raw output:
Tests
Tested on macOS 27.0.1 (Apple M5 Max, rustc 1.88.0):
cargo check --all-targetsandcargo clippy --all-targets -- -D warningspass for cap-enc-ffmpeg and cap-video-decode, soavassetreader.rscompiles with the moved helpers.cargo testpasses for cap-enc-ffmpeg (268), cap-video-decode (24, including the avassetreader composition-offset and reordering tests), the cap-recording lib (852) andoop_muxer(13). With--all-targets, cap-recording's clippy hits 9 errors that are identical onmainand sit in files this PR doesn't touch (cursor.rs,recovery/needs_remux_tests.rs), and thehardware_*suites need Screen Recording permission, as they do onmain. cap-gpui builds in release. On a 10-minute 1080p30 project with a warm cache (mean of 5 alternating launches), the editor's first frame drops from 291 to 199 ms after the window opens, and project validation drops from 185 to 82 ms. The heal check alone drops from 94.5 to 7.1 ms. A 5-second project stays within run-to-run spread (206 vs 194 ms to first frame). Cold-cache runs and bytes read weren't measured on macOS, because there's no/procand no root to purge the cache.indexed_timestamps_match_a_full_packet_scan: on constant-rate, bursty variable-rate, jittered and paused tracks written by Cap's ownMP4File+H264Encoder, the index gives exactly the timestamps a full packet scan does.varying_composition_offsets_fall_back_to_reading_packets: on the repo'sh264-varying-composition-offset.mp4fixture the index is refused and the capture rate equals the one computed from a packet scan; theh264-no-reordering.mp4fixture still uses the index and matches the scan.a_fragmented_track_falls_back_to_reading_packets: an init segment plus fragments has no usable index; the scan still runs and returns 30 fps.a_jittered_variable_rate_display_at_its_average_is_healedanda_display_fps_that_differs_from_its_track_is_left_alonejoin the existing heal tests. All of them pass before and after, so heal decisions are unchanged.cargo test -p cap-enc-ffmpeg: 265 passed.cargo test -p cap-video-decode: 17 passed on Linux.cargo test -p cap-recording --lib --tests: 989 lib tests plus every integration suite pass (oop_muxerneedscargo build -p cap-muxerfirst).cargo clippy --all-targets -- -D warningsis clean forcap-enc-ffmpegandcap-video-decode.cargo clippy -p cap-recording --no-depsreports only errors that already exist on main on Linux, in files this PR doesn't touch (screen_capture/linux.rs,cursor.rs,recovery/needs_remux_tests.rs), plus two incap-utils.cargo fmt --allis clean.Risks and what wasn't tested
avassetreader.rsonly compiles on macOS and wasn't compiled here. Its change is one import replacing the moved functions, and its two existing tests fortrack_has_no_composition_offsetsstay with it.

Confidence Score: 5/5
The PR appears safe to merge; no blocking issues were found.Summary
This PR speeds up capture-rate checks by reading safe MP4 sample indexes instead of scanning video packets.
No actionable issues were found. Tests were not run during this review.
Reviews (2) · Last reviewed commit: "Merge branch 'main' into capy/editor-ope..." · Reviewed by Greptile