Repository navigation
feat(rendering): add opt-in macOS software codec mode - #2948
AasishDairelSahayaGrinspan wants to merge 3 commits into
Conversation
VideoToolbox can schedule H.264 decode and encode on the integrated GPU even when the renderer is on the discrete GPU. Add CAP_MACOS_SOFTWARE_CODECS=1 to force FFmpeg software decode and libx264 export so the integrated GPU stays idle. The default codec behavior is unchanged; this only changes codec choice when the variable is set.
|
@AasishDairelSahayaGrinspan is attempting to deploy a commit to the Cap Software Inc Team on Vercel. A member of the Team first needs to authorize it. |
| let software_codecs = crate::software_video_codecs_requested(); | ||
| if force_ffmpeg || path.is_dir() || software_codecs { |
There was a problem hiding this comment.
Preview ignores software codecs
Setting CAP_MACOS_SOFTWARE_CODECS=1 does not force software decoding in the preparing editor preview. This check only covers spawn_decoder, while that preview uses spawn_managed_decoder. The desktop enables hardware decoding on macOS, and the managed decoder forwards that choice unchanged, so FFmpeg still selects VideoToolbox. Users can therefore still get the integrated-GPU activity this option is meant to avoid. Apply the software-codec setting to the managed decoder path too.
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/rendering/src/decoder/mod.rs
Line: 1476-1477
Comment:
**Preview ignores software codecs**
Setting `CAP_MACOS_SOFTWARE_CODECS=1` does not force software decoding in the preparing editor preview. This check only covers `spawn_decoder`, while that preview uses `spawn_managed_decoder`. The desktop enables hardware decoding on macOS, and the managed decoder forwards that choice unchanged, so FFmpeg still selects VideoToolbox. Users can therefore still get the integrated-GPU activity this option is meant to avoid. Apply the software-codec setting to the managed decoder path too.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Fixed in 0550695. spawn_managed_decoder now applies CAP_MACOS_SOFTWARE_CODECS before constructing the FFmpeg decoder, so the preparing preview and camera managed decoders use software decoding too.
The preparing editor preview uses spawn_managed_decoder, so CAP_MACOS_SOFTWARE_CODECS only affected spawn_decoder. Apply the same override to the managed decoder path so preview and camera decoders also avoid VideoToolbox on the integrated GPU.
|
@greptileai review |
|
Thanks @AasishDairelSahayaGrinspan for splitting this out and for the clear measurements on the 2019 MBP! The decode and export changes look right: |
CAP_MACOS_SOFTWARE_CODECS was forcing libx264 for live Studio recording encoding as well as export. Live macOS recording builds its encoder through H264EncoderBuilder, so setting the variable could drop frames at high resolutions. Gate the new env var on is_export and keep CAP_EXPORT_FORCE_SOFTWARE_ENCODER unchanged.
|
Fixed in
The decode and export changes are unchanged from the reviewed revision. |
|
@greptileai review |
Summary
On dual-GPU Macs, VideoToolbox can keep using the integrated GPU for H.264 decode and encode even when the renderer is on the discrete GPU. There is no public API to pin VideoToolbox to a specific Metal device, so this adds an opt-in software codec mode:
CAP_MACOS_SOFTWARE_CODECS=1forces FFmpeg software decode in the editor and export paths.libx264and disables zero-copy VideoToolbox input.CAP_EXPORT_FORCE_SOFTWARE_ENCODERremains the existing escape hatch.This only changes codec choice; it does not change GPU selection. Split out of #2776 at the maintainer's request.
Setting the variable
Apps launched from Finder or the Dock do not inherit shell environment variables. Set it for GUI apps and relaunch Cap:
launchctl setenv CAP_MACOS_SOFTWARE_CODECS 1 # relaunch Cap launchctl unsetenv CAP_MACOS_SOFTWARE_CODECSVerification
2019 MacBook Pro, AMD Radeon Pro 5300M + Intel UHD 630, 3072x1920 studio recording:
CAP_MACOS_SOFTWARE_CODECS=1playbackCAP_MACOS_SOFTWARE_CODECS=1exportlibx264, no zero-copyThe software export path is about 2.8x slower than hardware, which is why this is opt-in rather than the default. Live recording encoding is intentionally left on the hardware path.
Local checks:
cargo fmt --all --check,cargo check -p cap-rendering -p cap-enc-ffmpeg -p cap-export, andcargo test -p cap-enc-ffmpeg software_codec_env_only_forces_export_encoder_priority.

Confidence Score: 5/5
The PR appears safe to merge; the preview fix remains in place, and export-only encoder selection matches the intended behavior.Summary
Adds opt-in software codecs on macOS without changing renderer GPU selection.
Reviews (3) · Last reviewed commit: "fix(enc-ffmpeg): limit software codec en..." · Reviewed by Greptile