Video Engine
Status: the writer is tested on the Mac with all three codecs; the full recording flow is tested in the Simulator; recording from a real camera and microphone has not been tested.
Path of a frame
sequenceDiagram
participant C as Camera (data output)
participant P as FramePipeline
participant R as VideoRecorder
participant W as AVAssetWriter
C->>P: BGRA frame + timestamp
P->>P: keep as latest (monitor)
P->>R: appendVideo (every frame, or one per interval)
R->>W: adaptor.append (if ready, else count a drop)
Note over C,P: audio buffers follow the same route
P-->>R: stop
R->>W: endSession + finishWriting
R-->>P: result (duration, frames, dropped, size)
VideoRecorder
Packages/ORIXCameraKit/Sources/ORIXImaging/Capture/VideoRecorder.swift
| Aspect | Implementation |
|---|---|
| Container | QuickTime .mov, movie fragments every 5 s |
| Video | H.264, HEVC or ProRes 422 from BGRA buffers through a pixel-buffer adaptor |
| Bit rate | H.264 and HEVC: width × height × fps × 0.25 or × 0.13 as average bit rate, key frame every second. ProRes: not rate-controlled (2.4 bits/pixel is used only to estimate storage) |
| Audio | AAC, 96 kbit/s mono (160 kbit/s if stereo), real-time input |
| Orientation | frames stored as delivered; the track transform carries the rotation |
| Timeline | the session starts at the first video frame; audio before it is ignored |
| Drops | a frame is dropped and counted when the encoder is not ready, the append fails, or its timestamp does not advance |
| Retiming | with timeLapsePlaybackRate, frame i gets the timestamp i / rate and audio is discarded |
| Finish | one nominal frame duration is added after the last timestamp; a recording with no frame throws and leaves no file |
Encoder availability is asked of VideoToolbox (VTCopyVideoEncoderList), not assumed from the device model.
Why not AVCaptureMovieFileOutput
AVCaptureMovieFileOutput is the simplest way to record on iOS. ORIX Camera uses a video data output and AVAssetWriter instead.
| Reason | Detail |
|---|---|
| One stream for everything | The same BGRA frames feed the monitor (with peaking and zebras drawn on the exact pixels), the histogram and focus analysis, the recorder, and the multi-frame modes. There is one code path to reason about. |
| Retiming | Time-lapse and slow motion are the same recorder with rewritten timestamps. |
| Testability | The writer runs on macOS. Tests record real movies with each codec, decode a frame back, check duration, frame count, audio presence and drop accounting. |
| Crash safety | Movie fragments keep an interrupted recording playable up to the last fragment; the next launch adopts such files into the library. |
| Explicit accounting | Dropped frames are counted by the recorder and reported to the user. |
Costs accepted:
- 8-bit SDR only. The pipeline carries 32BGRA. Recording 10-bit HLG or Apple Log needs bi-planar 10-bit buffers through the monitor shader and the writer. Not done in 1.0; the app detects and reports when the camera offers them.
- More code than a movie file output, and more responsibility: timestamps, session start, finishing.
- BGRA conversion by the capture pipeline has a cost at 4K60 that has not been measured on a device.
- ProRes from 8-bit BGRA is valid ProRes 422, but it does not carry more than 8 bits of source precision.
Recording flow in the app
CameraModel.startRecording:
- refuse if free space cannot hold ten seconds at the target rate plus the 200 MB reserve;
- create the recorder in
Incoming/with the stream's real dimensions, the chosen codec, the measured frame rate and the capture rotation; - sound is on only with microphone permission and outside time-lapse and slow motion;
- hand the recorder to the pipeline; keep the screen awake.
stopRecording detaches the recorder, finishes it, moves the file into Media/, makes a thumbnail, indexes it with its duration and summary, and reports dropped frames or the interruption reason.
| Kind | Trigger | Retiming |
|---|---|---|
video |
Pro Video | none |
slowMotion |
Pro Video above 60 fps with "Play back in slow motion" | every frame, 30 fps |
timeLapse |
Creative → Time-lapse | one frame per interval, 30 fps |
Interruptions
| Event | Behaviour |
|---|---|
| Session interrupted (call, other app, multitasking, thermal shutdown) | recording stopped and saved, with the reason in the message; a card explains the pause |
| App goes to the background | suspend() stops and saves the recording before stopping the session |
| App killed while recording | the fragmented file stays in Incoming/; recoverInterruptedRecordings adopts it at the next launch if it has a duration |
| System pressure serious or critical | heat badge; a warning at critical; the monitor refreshes at 30 Hz |
| Audio route change | handled by the capture session; no specific code. Untested |
Storage estimate
ExposureMath.bytesPerSecond = video bit rate / 8 + 12 000 bytes/s when sound is on. remainingRecordingTime divides the free space, minus a 500 MB reserve, by that rate. The format sheet shows megabytes per minute for each codec at the selected format.