Skip to content

Cap the export canvas at the pixel area of 4K UHD so 5K captures can export - #978

Open
Sdergham wants to merge 2 commits into
webadderallorg:mainfrom
Makerecur:fix/export-canvas-pixel-budget
Open

Sdergham wants to merge 2 commits into
webadderallorg:mainfrom
Makerecur:fix/export-canvas-pixel-budget

Conversation

@Sdergham

@Sdergham Sdergham commented Sep 16, 2026

Copy link
Copy Markdown

Description

Caps the export canvas that the MP4 quality tiers scale from at the pixel area of 4K UHD (3840 x 2160). A canvas over that area is scaled down by the square root of the ratio, keeping its shape; anything at or under it keeps its size. The cap applies to native and fixed-aspect exports alike, before the quality tier scale.

Two files change: src/components/video-editor/exportDimensions.ts (a MAX_EXPORT_CANVAS_PIXELS constant and a capExportCanvasDimensions helper, applied inside calculateMp4SourceDimensions) and its test file.

Motivation

A full-screen capture of a 5K display (5120 x 2880) exported at 9:16 produces a 2880 x 5120 canvas: 14.7 megapixels read back per frame and taller than H.264 hardware encoders accept. The export never completes and nothing is logged. The encoder support probe does not catch it. See the linked issue for the full reproduction.

With the cap, the same project's tiers become 1296 x 2304, 1620 x 2880, 1944 x 3456 and 2160 x 3840, and the Medium export completes on the original 5K source with no proxy.

Sources at or below 4K UHD are unchanged. This includes 4K displays at any ratio and a 5120 x 1440 ultrawide, which is under the area and keeps its size.

The trade-off, stated plainly: on displays above 4K, "Original" is no longer the source size, and every tier scales from the capped canvas. Medium on a 5K 16:9 screen drops from 3840 x 2160 to 2880 x 1620. If you would rather expose the ceiling as a setting or use a different budget, the constant is the only thing to change.

Type of Change

  • Bug Fix

Related Issue(s)

Fixes #977. Related: #653 (the Level 6.0 decoder deadlock on 5K and 6K sources reported against 1.3.4-beta.1; the same Level 6.0 source decoded on current main in my testing, so this PR addresses the canvas size, not the decoder, and does not add the watchdog suggested there) and #639 (Original on a 4K source exporting below 4K; sources at or below 4K UHD are untouched by this change).

Screenshots / Video

Export settings menu on the 5K source, 9:16, before and after:

Tier Before After
Low 1728 x 3072 1296 x 2304
Medium 2160 x 3840 1620 x 2880
High 2592 x 4608 1944 x 3456
Original 2880 x 5120 2160 x 3840

A screenshot of the menu after the change can be attached here.

Testing Guide

Unit tests:

npx vitest --run src/components/video-editor/exportDimensions.test.ts

Twelve new cases cover the 5K native and 9:16 paths, native crops above and below the budget, an ultrawide inside the budget, an ultrawide above it, a sweep of six oversize screens checking the result never exceeds the budget after rounding to even dimensions, and the resulting quality tiers. The full suite passes (1,195 tests), as do tsc and biome check.

Manual check on a display larger than 4K UHD:

  1. Record the full screen and open the recording in the editor.
  2. Open the export settings. The Original tier should show at most 8.3 megapixels (3840 x 2160 for 16:9, 2160 x 3840 for 9:16), with the lower tiers scaled from it.
  3. Export MP4 at Medium. It should complete.

On a 1080p, 1440p or 4K display, the tier sizes are unchanged from main.

Verified on macOS 26, M4 Max, Dell U4320Q at 5120 x 2880: a 179 s 9:16 export at Medium completed at 1620 x 2880, 4,307 frames at 24 fps.

Checklist

  • I have performed a self-review of my code.
  • I have added any necessary screenshots or videos.
  • I have linked related issue(s) and updated the changelog if applicable.

Summary by CodeRabbit

  • Bug Fixes
    • Export canvases larger than 4K UHD are now automatically scaled down to fit within the supported pixel budget.
    • Video exports preserve the original aspect ratio and use even-numbered dimensions for improved compatibility.
    • Native, portrait, ultrawide, and cropped exports now consistently apply the canvas size limit while leaving supported 4K dimensions unchanged.

Sdergham and others added 2 commits September 16, 2026 11:53
The export canvas follows the source with no ceiling, so a full-screen
capture of a 5K panel at backing scale 2 (5120 x 2880) produced a
2880 x 5120 canvas for 9:16 exports: 14.7 megapixels read back per frame
and taller than H.264 hardware encoders accept. Exports stalled or failed
at every tier.

calculateMp4SourceDimensions now caps the derived canvas at 3840 on the
long side and 2160 on the short side, for native and fixed-aspect
exports alike, and every quality tier scales from the capped canvas.
Sources at or below 4K are unchanged. Verified on a 179 s 5K capture:
Medium at 9:16 exported 1620 x 2880, 4307 frames at 24 fps.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A per-side ceiling (3840 long, 2160 short) also shrank wide or tall
sources that were already inside the area of 4K UHD, such as a
5120 x 1440 ultrawide, whose Original export was fine. The cap is now a
pixel budget equal to 4K UHD's area: a canvas over the budget scales by
the square root of the ratio, keeping its shape, and anything under it
keeps its size. The 5K-to-9:16 case lands on the same 2160 x 3840 canvas
as before.

The previous commit's claim that exports failed at every tier was not
verified; only Original was observed failing before the proxy route.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: c7dfa6fd-a4a3-49fb-b0bf-21f8ff84938b

📥 Commits

Reviewing files that changed from the base of the PR and between b3ea775 and 30c1340.

📒 Files selected for processing (2)
  • src/components/video-editor/exportDimensions.test.ts
  • src/components/video-editor/exportDimensions.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Changes

The MP4 export dimension logic adds a 4K UHD pixel ceiling. Oversized canvases scale down proportionally and normalize to even dimensions. Native and fitted source dimensions now use the ceiling. Tests cover 5K, 4K, portrait, crop, ultrawide, and custom-budget cases.

Export canvas cap

Layer / File(s) Summary
Canvas cap helper and coverage
src/components/video-editor/exportDimensions.ts, src/components/video-editor/exportDimensions.test.ts
Adds the 4K UHD pixel budget and capExportCanvasDimensions. Tests verify proportional scaling, even dimensions, unchanged in-budget dimensions, and custom budgets.
Source dimension integration
src/components/video-editor/exportDimensions.ts, src/components/video-editor/exportDimensions.test.ts
Applies the cap to native and fitted MP4 source dimensions. Tests verify 5K portrait and landscape results, crop handling, 4K pass-through, and export-tier scaling.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: meiiie

Merge Risk: ⚪ Minimal · up to 30c13

The canvas cap and export-tier paths are covered without an identified current-head issue, so the change is ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: capping the export canvas at the 4K UHD pixel area to support 5K captures.
Description check ✅ Passed The description covers the purpose, motivation, change type, related issues, testing steps, validation results, and checklist. The screenshot or video is not attached, and the changelog item remains u…
Linked Issues check ✅ Passed Issue #977 requires an export-canvas ceiling that preserves aspect ratio and leaves sources within the 4K UHD pixel area unchanged. MAX_EXPORT_CANVAS_PIXELS sets the 3840 × 2160 area. `capExportCanv…
Out of Scope Changes check ✅ Passed The changes are limited to MP4 export dimension calculation and its automated tests. The implementation directly supports issue #977. No unrelated product behavior or unrelated files are changed.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

MP4 export cannot complete from a full-screen capture of a 5K display (export canvas has no ceiling)

1 participant