Repository navigation
feat: record the screen to an MP4 file with iph record - #11
Conversation
3229f72 to
054b758
Compare
|
Thanks for another super thorough PR — the real-device measurements, failure-mode handling, and unit tests are great as always.
Before diving into a line-by-line review, I'd love to align on a few higher-level questions:
|
054b758 to
c75d985
Compare
iph record
|
Thanks for the careful read, and for asking before going line by line.
|
|
Thanks for trimming Yes, switching to Two small things to fold in while you're in there:
Once that's in and re-tested on a device, I'll do a full pass! |
`iph record start|stop|status` writes the phone's screen to an MP4 while other commands keep running, so an E2E run can keep video evidence of what happened. Taps, swipes and reads work during a recording. The recorder opens a screen-sharing session of its own with the phone, the video of one display, next to the input session's audio. The device library stops streams only with `stopAll`, which would let every input retry, idle close or sweep of an abandoned session end the recording. The phone also takes a list of streams to stop, each named by the `RemoteSSRC` of its stream configuration (sent as XPC uint64; it refuses int64 and strings), so `device::media::MediaControl` speaks the display service's requests itself and each session stops only its own streams. Seen on an iPhone Duo (iOS 27.2.1): stopping a recording's video by its SSRC left the input's audio running and taps working, and an input session dropped and swept mid-recording left the video running. A phone that refuses the list, or still lists the stream afterwards, is told to stop all streams instead. A recording ends with a reason in `ended_reason`, and the file is completed with what came, when the connection to the phone is closed, or reset after a connection error, an accessibility service that would not open, or a command that ran out of time (not when only the accessibility connection or the input session is made again), when the phone stops sending the video (none for 2.5 s and the phone no longer lists the stream: a still screen can be silent that long), when the phone changes the video's VPS, SPS or PPS (the file has one hvcC), or after `record_max_secs` (default 1800 s: at the phone's cap of 6 Mbit/s, 30 minutes is up to 1.4 GB, and a recording nobody stopped ends within the daemon's own idle time). Its report waits for `stop`, or the next `start` returns it under `previous`; the daemon does not exit while it records, nor for its idle time after a recording ended with nobody told. A recording a script started and did not stop ends with the script, also on a throw, and the script's result has its report under `recording`. The phone sends HEVC over RTP (payload type 100) with a 24 kHz clock and the parameter sets in band. It sends one keyframe per stream, so `start` waits for it, and a packet lost later damages the picture until the end while players still open the file. Losses before that keyframe damage nothing and are not counted. `stop` and `status` report `lost_packets`, and after a loss `first_loss_s` (where the damage starts in the file) and a `packets_lost` warning; the result stays `ok`. Frames go to `<file>.part` as they come and only the sample table stays in memory; `stop` appends the index and renames the file, and a start given up on the way leaves no file. On a still screen the phone may send few frames, so the last frame lasts until `stop`. A frame with no picture (its slices lost, or only parameter sets or SEI) is not written, and the frame before it lasts in its place. The MP4 boxes and the hvcC come from `shiguredo_mp4` (no dependencies, sans I/O): `stop` hands it the sample table and writes the index it returns at the end of the file. Without `--display`, displays 1, 0 and 2 are tried and the first whose video has the shape of the screen being read is kept. The new geometry check requires the horizontal and vertical pixels-per-point ratios to agree within 1%, else `display_mismatch`. On a folded iPhone Duo, displays 0 and 1 both show the cover screen and display 2 sends nothing. A killed daemon leaves its streams running on the phone for their RTCP timeout, an hour; minutes after a `kill -9` the media server still listed them. The input session and the recorder write their client session id to `<udid>.media` in the state directory, removed once its streams are stopped. The daemon's housekeeping stops one left id at a time, skipping the ids still in use, for at most 3 s with the session held and then 30 s apart after a failure, never on a request's way or inside an open; the daemon's exit tries once more, for up to 20 s. It stops only the streams the media server lists under such an id, so a stream another client started (Xcode's screen view, another Mac) is never stopped. The same command is the MCP tool `iph_record` (one tool with an action, as `iph_dnd`) and the script function `record()`, which is not an input and cannot choose the file. Batch is left out: a recording spans requests, and a failing batch would leave it running. Measured on an iPhone Duo (iOS 27.2.1, folded, USB): 1408x2048 at 50 to 52 fps while the screen moves, about 0.5 Mbit/s, no lost packets. On an iPhone 16 Pro over Wi-Fi, 2 of 9 short recordings lost packets (9 and 51). After the switch to `shiguredo_mp4`, 3 recordings of 15 to 19 s on the iPhone 16 Pro (iOS 27.2.1) over Wi-Fi lost no packet, their frame counts matched `ffprobe -count_frames`, and ffmpeg and AVFoundation decoded every frame. Co-Authored-By: Claude Opus 5.5 <[email protected]>
README.md and README.ko.md get a section on recordings: that a recording has its own screen-sharing session next to the input's, why to record over USB (one keyframe per stream), what a still screen does to the frame count, how the display is chosen, when a recording ends on its own (`record_max_secs`, a lost connection or video) and where its report goes, what a script's end does to a recording it started, and what is left when the resident process stops or is killed. The command table, the config example, the MCP tool list, batch (no recording step) and the known limits follow: over Wi-Fi 2 of 9 short recordings lost packets in testing, and a loss damages the rest of the file, reported as `first_loss_s` and a `packets_lost` warning. skills/iph/SKILL.md tells agents when to keep this evidence, to record over USB and stop every recording, and that a script's leftover recording ends with the script. Co-Authored-By: Claude Opus 5.5 <[email protected]>
c75d985 to
0acbfb5
Compare
|
Thanks! All three are in, and the PR is mergeable again.
A review pass over the new writer found three small things, also fixed. The crate's default Re-tested on a device: an iPhone 16 Pro (iOS 27.2.1) over Wi-Fi, 4 recordings of 15 to 19 s with swipes during the recording. No packets were lost. |
HyunSeob
left a comment
There was a problem hiding this comment.
Looks great — switching to shiguredo_mp4 cleaned up the MP4/HEVC layer nicely, and the rebase and has_picture() guard all look solid. Thanks for the thorough work on this, merging now!
Why
E2E evidence on a real phone needs more than a plain screenshot: a video of the flow. It comes from the phone without extra tools. The screen-sharing call iph already opens for input can also carry the screen as HEVC over RTP.
What changed
iph record start|stop|status [-o file.mp4] [--display N], also as MCPiph_recordand scriptrecord(). The recorder opens its own video-only display session, so input sessions keep working and are opened and closed as before. The HEVC stream is written to an MP4 withshiguredo_mp4(zero dependencies, sans I/O), with no ffmpeg or other runtime dependency. Frames go to<file>.partas they come;stophands the sample table to the muxer and writes the index it returns at the end of the file. A frame with no picture (its slices lost, or only parameter sets or SEI) is not written.RemoteSSRCinidentifiers.stopAllis a fallback used only when nothing but that session's streams runs. Session ids are kept in<udid>.media, and housekeeping stops streams a killed iph left behind.stopreturns{path, duration_s, frames, keyframes, lost_packets, bytes, width, height}. The phone sends one keyframe per stream, so a lost packet damages the rest of the file:stopthen addsfirst_loss_sand apackets_lostwarning. A recording ends on its own when the video stops, the connection resets, the script that started it ends, or afterrecord_max_secs(1800 s by default).display_mismatchwhen its video and the accessibility screen do not have the same shape, so a phone with two displays does not record the other one.Scope
iph screenshot --annotate, left in from testing, was removed during review.Tradeoffs
Verification
cargo test --lockedpasses, including the RTP and 24 kHz timing, the MP4 read back withshiguredo_mp4's demuxer, frames without a picture, loss accounting before and after the first keyframe, the stop decisions (including a status without the session list), and the geometry guard. Clippy: no new warning.shiguredo_mp4, on an iPhone17,1 (iOS 27.2.1) over Wi-Fi: 4 recordings of 15 to 19 s with swipes during the recording lost no packet;stopframes equalledffprobe -count_frames(1044, 946, 815, 453), ffmpeg decoded without errors, AVFoundation decoded every frame, andcreation_timewas the recording time.stopframes always equalffprobe -count_frames, ffmpeg decodes without errors, and AVFoundation plays them.input_idle_secs = 0(input opens and closes on every command) the recording kept going, and the phone stopped only each input's audio.kill -9, the next command worked and the leftover streams were stopped.record_max_secs = 8ended a recording at 8.8 s.first_loss_sthat matched where ffmpeg starts failing to decode.🤖 Generated with Claude Code