Skip to content

fix(ios): drain an autorelease pool per frame in compressWithBitrate - #15

Merged
thangdevalone merged 1 commit into
thangdevalone:mainfrom
FrikkieSnyman:fix/ios-compress-autoreleasepool
Nov 19, 2026
Merged

thangdevalone merged 1 commit into
thangdevalone:mainfrom
FrikkieSnyman:fix/ios-compress-autoreleasepool

Conversation

@FrikkieSnyman

Copy link
Copy Markdown
Contributor

What

On iOS, compressWithBitrate's video loop now wraps each frame in autoreleasepool. The loop body is unchanged apart from return/continue becoming the closure's Bool result.

Why

requestMediaDataWhenReady can append hundreds of frames in a single callback when the encoder keeps up, for example a 4K 60 fps source scaled down to 720p. Without a per-frame pool, every decoded source frame (about 12 MB at 4K) stayed alive until the callback returned. On an iPhone 17 Pro Max, compressing a 10 s range of a 4K60 HDR clip pushed the app to 2.0–2.7 GB. iOS then either killed the app (out of memory) or failed the export with AVFoundationErrorDomain -11819 ("Cannot Complete Action", media services reset, underlying OSStatus -16155). 4K30 and 1080p clips stayed under the limit, which is why only high-frame-rate 4K sources showed it.

Testing

compressWithBitrate was copied unchanged into a macOS command-line harness and run on synthetic clips: bitrate 4.2 Mbps, maxWidth 1280, audio muted. On macOS the hardware decoder runs in VTDecoderXPCService, so the numbers below are that process's peak phys_footprint.

Source Before After
4K60 HEVC HDR, 10 s range 6,587 MB 392 MB
4K60 HEVC HDR, full 15 s 10,240 MB 382 MB
4K30 HEVC HDR, 10 s range 479 MB 376 MB
1080p60 HEVC HDR, 10 s range 140 MB 104 MB

Output sizes and encode times are unchanged; the path without resizing (maxWidth 0) also works. yarn typecheck passes and swiftc -parse is clean. This ships in Relive as a patch on 2.4.2.

🤖 Generated with Claude Code

The video loop in compressWithBitrate can append hundreds of frames in
one requestMediaDataWhenReady callback when the encoder keeps up (e.g.
4K60 scaled to 720p). Without a per-iteration pool every decoded source
frame stayed alive until the callback returned, so 4K60 sources grew to
several GB and iOS killed the app or reset media services
(AVFoundationErrorDomain -11819).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thangdevalone
thangdevalone merged commit 944fa9f into thangdevalone:main Nov 19, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants