Repository navigation
Speed up desktop exports with VideoToolbox and a 1080p default - #109
Merged
Merged
Conversation
Benchmarked on an M1 Pro with iPhone-style 4K HEVC 10-bit footage, the native export was barely realtime: software HEVC decoding alone took 19 s per 30 s of 4K. Three changes: - Hardware decode (macOS) for HEVC, ProRes and AV1 sources: 4K HEVC decodes 6x faster on VideoToolbox. H.264 stays in software, which measured faster at every size (4K: 3.9 s vs 7.0 s hardware). - Hardware H.264 encode (macOS) for MP4 at -q:v 65, which matched libx264 -crf 22 on size and SSIM (31 vs 32 MB, 0.9818 vs 0.9823). Even with libx264 on an 8-core M1 Pro; 1.5-2.2x faster when the encoder has 4 cores. Probed once per session (Intel Macs lack constant-quality VideoToolbox and keep libx264). A failed hardware attempt re-runs the same job in software and is reported as native-hw-fallback. RESCRIPT_MEDIA_HW=0 turns it off. - Export defaults to 1080p when the source is larger, the source size otherwise. Resolutions now cap the frame's short side, so 1080p of a vertical 2160x3840 video is 1080x1920 rather than 608x1080; the new scale expression is plain arithmetic and checked on ffmpeg 5.1 (wasm), 6.0 and 6.1. In the app, a 30 s 4K HEVC clip with cuts: 1080p 21.0 s -> 6.2 s, original 4K 40.2 s -> 15.5 s; the old default (original, software) to the new one (1080p, hardware) is 40.2 s -> 6.2 s. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Exports still felt much slower than CapCut. I benchmarked the bundled ffmpeg on an M1 Pro to find where the time goes.
What
Hardware decode on macOS for HEVC, ProRes and AV1 sources (
-hwaccel videotoolbox). This is decided by codec, from measurements:H.264 therefore stays in software. Decoded frames come back to system memory, so the CPU filtergraph is unchanged. VideoToolbox quietly falls back to software for codecs it can't decode (verified with VP9).
Hardware H.264 encode on macOS for MP4 (
h264_videotoolbox -q:v 65).-q:v 65matched x264-crf 22on a 30 s 1080p sample: 31 MB vs 32 MB, SSIM 0.9818 vs 0.9823.runAttempts).stage=native-hw-fallback, with the stderr tail.RESCRIPT_MEDIA_HW=0turns hardware off. Windows and Linux stay on software until hardware encoding is checked on real GPUs.Default export resolution is 1080p when the source is larger, and the source size otherwise. A user's explicit pick still sticks.
Results (in the app, 30 s 4K HEVC 10-bit clip with cuts, M1 Pro)
The 1080p H.264 source → MP4 job uses hardware encode only, because software decode is faster there.
Testing
tsc(web + electron),eslint,next build,build:electron,test:i18n,test:timelineandtest:ffmpegall pass.export-args-test:defaultExportResolutioncases: landscape, portrait, 1440p, 1080p, 720p, unknown.native-ffmpeg-test:parseVideoStreamon real input-dump lines: iPhone HDR colour info with commas, ProRes, VP9, cover art skipped, audio-only.runAttempts: a broken first attempt falls back and the output is the full edit; a cancelled run isn't retried.electron:devwith a throwaway--user-data-dir), driven over CDP:RESCRIPT_MEDIA_HW=0gave the numbers above.Not verified
runAttemptstests, but I couldn't make VideoToolbox fail on demand.Follow-ups
🤖 Generated with Claude Code