Repository navigation
fix(recording): keep a Studio recording when a resumed segment captures no frames - #4297
richiemcilroy wants to merge 10 commits into
Conversation
|
Sandchest reviewed Sandchest reviews every change for vulnerabilities an attacker could use · 3 credits · Review details |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
hey @greptileai, please re-review the PR |
| && packet.duration() <= 0 | ||
| && let Some(rate) = self.video_frame_rate[output_index] | ||
| { | ||
| packet.set_duration( |
There was a problem hiding this comment.
First-packet duration fallback may shift video timing on multi-frame tracks
Medium Severity · Investigate
The new branch in StreamRemuxer::write_packet runs for the first packet of every video stream whose packet duration is <= 0, not only for a stream that holds one frame. recovery.rs (lines 2586 and 2622) sends every fragmented Studio video track through concatenate_m4s_segments_with_init[_validated], and the code comment and the new test say these fragments carry no sample durations. So for a normal multi-frame display or camera track, packet 0 receives a duration of 1/avg_frame_rate, while the real gap from packet 0 to packet 1 is whatever the capture produced. Packets after the first still get their durations from dts deltas, so if the mov muxer honours an explicit first-packet duration (as the single-frame test's packets[0].duration assertion suggests), every later video sample is shifted earlier by (first_gap - 1 frame) relative to the audio tracks. Screen capture delivers frames on content change, so a static screen right after a resume can produce a first gap far larger than one frame. Fix: apply the fallback only when the stream has no later packet, or derive the first duration from the next packet's dts, which is what the muxer already does. Verification target: libavformat movenc.c duration handling for packets with a non-zero explicit duration, and a new test with a multi-frame durationless fixture whose first dts gap is not one frame, checking the output video sample durations against the input dts. The existing multi-frame tests compare the validated and legacy outputs, and both now take this branch, so they cannot detect the change. Not verified by running code.
# Conflicts: # crates/recording/src/studio_recording.rs

A user reported a Studio recording that hung on Pause and would not open afterwards. Their log shows
Failed to finish MP4 encoder: NotWritingright after pausing.Root cause
Two ways a short resumed segment loses the whole recording on main:
AVAssetWriternever started, soMP4Encoder::finish_startreturnedNotWriting.AVFoundationMp4Muxer::finishmade that a display media error,Actor::stop_pipelinemade it terminal, and Pause failed the recording.RecoveryManagerremux) fails the whole recording. macOS fragments carry no sample durations.StreamRemuxercopied the lone frame with duration 0, so the MP4 track had zero length and readers discarded its only sample:display video validation failed ... No decodable frames found after trying 1 packets.Only the first segment gets the start gate's held frame, so any resumed segment can hit this when Pause lands before ScreenCaptureKit delivers frames. On the Mac mini, pausing straight after Resume reproduces the second case on main with no fault injection.
Change
crates/enc-avfoundation/src/mp4.rs: a writer that never started reportsFinishError::NoFrames.NotWritingstays for a second finish.crates/recording/src/output_pipeline/macos.rs: the screen and camera muxers mapNoFramesto a typedNoVideoFramesCaptured(output_pipeline/core.rs). Every other finish error is unchanged.OutputPipeline::stop_with_outcomeis untouched, so the capture-exited rules stay as they are.crates/recording/src/studio_recording.rs:Pipeline::stopmarks the segmentscreen_emptywhen the screen reportedNoVideoFramesCaptured, or finished cleanly with zero frames (fragmented, Windows and Linux writers). That is not a media error. A camera with no frame is left out of that segment, like a segment recorded with the camera off.NoVideoFramesCapturedas a clean end only while Pause or Stop is stopping the pipeline. A track that ends on its own is still a failure.stop_pipelineleaves an empty segment out. It moves the segment folder tocontent/empty-segments/segment-N-Kand the next segment reuses index N, socontent/segmentsstays numbered like the saved segments, which recovery and finalize rely on. The segment's other files are kept.RecordingMarkers::segment_droppedmoves markers pressed in that segment to the end of the segment before.crates/enc-ffmpeg/src/remux.rs:StreamRemuxergives a video stream's first packet one frame's duration when it has none. The MP4 muxer takes every other sample's duration from the next sample, so only a single-frame output changes.Callers checked
MP4Encoder::finish/finish_nowait: Studio screen (non-fragmented), Studio camera, Instant camera-only (still an error, now typed),Drop.Pipeline::stop: Studio Pause, Stop, Cancel.stop_pipeline: Pause and Stop.StreamRemuxer:remux_file,concatenate_m4s_segments_with_init(_validated), the concat-demuxer paths. Audio streams are untouched.stop_recordingandSegmentStartTimesare untouched; an empty segment never reaches them.Tests
enc-avfoundation:finish_without_any_frame_reports_no_frames(fails on main withNotWriting),finish_after_a_single_frame_writes_a_playable_file.enc-ffmpeg:remux_of_a_single_durationless_frame_stays_playable(0 decodable frames on main).recording, macOS:finishing_without_a_frame_reports_no_video_framesfor the screen and camera muxers.recording, all platforms:stop_reports_a_screen_and_camera_that_captured_nothing_as_empty,a_dropped_segment_hands_its_markers_to_the_segment_before.recording, macOS and Windows:a_resumed_segment_without_screen_frames_is_left_outdrives the actor through Resume, Pause and Stop (and Stop while recording) for both writer behaviours, and checks the folder is moved aside.hardware_studio_empty_segment(real ScreenCaptureKit, debug build): 8 quick pauses after Resume, and a resumed segment withcap_failskipping every screen frame. Fragmented and not, each followed by the app's finalize step and a decode of every saved display.Measured on a Mac mini (M4, macOS 27), main vs this branch
Failedsegment-2/display.mp4not decodable14ca1258…14ca1258…Normal recordings (3 segments, system audio, 2 s each with 0.5 s pauses):
The mini was shared with other builds, so fragmented Pause times swing by seconds on both sides. One run on each side hit an unrelated
Output storage stalled while finishingon the build volume.Not proven on hardware: Windows and Linux capture. Their writers finish cleanly with zero frames, a case the cross-platform unit tests cover.


Confidence Score: 5/5
The PR appears safe to merge; no new actionable issue was found.Summary
Keeps Studio recordings when a resumed segment captures no screen frames, and gives a lone durationless video packet a usable duration during remux.
The three previous unnumbered findings are addressed: segment folders stay aligned with saved indexes, unexpected capture endings still reach the caller, and the redundant test comment was removed. No new actionable issue was found. Tests were inspected, not run.
Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile