Skip to content

fix(export): preserve cropped native aspect ratio#747

Merged
meiiie merged 4 commits into
mainfrom
fix/746-remove-background-export-parity
Jul 11, 2026
Merged

fix(export): preserve cropped native aspect ratio#747
meiiie merged 4 commits into
mainfrom
fix/746-remove-background-export-parity

Conversation

@meiiie

@meiiie meiiie commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Problem

With Remove background enabled, a cropped recording could still export with the selected
wallpaper visible above and below the content. This made MP4 output disagree with the editor
preview.

Root cause and fix

The preview derives Native aspect ratio from the cropped source bounds, while MP4 sizing used the
uncropped source dimensions. It could also memoize the 1920x1080 fallback before video metadata
became ready.

This change makes Native MP4 sizing crop-aware and recalculates it when the preview reports usable
video metadata. Fixed aspect-ratio exports keep their existing behavior. Both modern and legacy
MP4 pipelines consume the corrected shared dimensions.

Verification

  • Added a regression test that failed before the fix (320x180 instead of 320x144) and now
    passes; focused suite: 7/7.
  • Full Vitest suite passes.
  • Production Vite build and Electron main CJS smoke pass.
  • Windows runtime A/B with Chromium GPU acceleration disabled:
    • before: 1440x810, visible marker wallpaper above/below the cropped recording;
    • after, modern: 240x108, 60 frames / 2 seconds, no marker wallpaper;
    • after, legacy: 240x108, 60 frames / 2 seconds.
  • Targeted Biome and relaxed-unused TypeScript checks pass. Strict TypeScript and whole-repo Biome
    remain blocked by pre-existing baseline diagnostics outside this diff.

Risk

The change is limited to Native MP4 output dimensions. Windows was exercised directly; macOS is
reasoned from shared TypeScript paths but was not run locally. GIF uses a separate sizing model and
is intentionally outside this focused fix.

Related: #746, #692

Summary by CodeRabbit

  • Bug Fixes
    • Improved MP4 export source-dimension calculations for Native aspect ratio when crop is applied, preserving the selected crop more accurately.
    • MP4 export dimensions now derive from preview readiness to prevent incorrect sizing during initial load.
    • Reduced unnecessary MP4 support re-probing during export setting changes by debouncing probe updates and restoring expected dimensions on probe failure.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Native MP4 dimension calculation now accounts for crop bounds. The video editor waits for preview readiness, passes crop state into the calculation, and debounces native crop-driven support probes with stale-request protection. Tests cover cropped dimensions and probe debounce decisions.

Changes

MP4 export dimensions

Layer / File(s) Summary
Crop-aware dimension calculation
src/components/video-editor/exportDimensions.ts, src/components/video-editor/exportDimensions.test.ts
Native exports scale source dimensions using optional crop-region bounds, and probe debounce behavior is defined and tested.
Editor preview and probe wiring
src/components/video-editor/VideoEditor.tsx, src/components/video-editor/exportDimensions.ts
The editor uses ready preview dimensions, passes crop state into sizing, tracks probe snapshots, debounces native crop-driven probes, and ignores stale probe results.

Sequence Diagram(s)

sequenceDiagram
  participant PreviewVideo
  participant VideoEditor
  participant ExportDimensions
  participant MP4SupportProbe
  PreviewVideo->>VideoEditor: Preview readiness and video dimensions
  VideoEditor->>ExportDimensions: Source dimensions, aspect ratio, and crop region
  ExportDimensions-->>VideoEditor: Desired MP4 source dimensions
  VideoEditor->>ExportDimensions: Previous and current probe snapshots
  ExportDimensions-->>VideoEditor: Debounce decision
  VideoEditor->>MP4SupportProbe: Delayed native crop probe
  MP4SupportProbe-->>VideoEditor: Supported source dimensions
Loading

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately reflects the main fix: preserving cropped native aspect ratio for exports.
Description check ✅ Passed The description includes the problem, root cause, fix, verification, risk, and related issues, though it skips some template sections.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/746-remove-background-export-parity

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.

@meiiie meiiie marked this pull request as ready for review July 11, 2026 05:05

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/components/video-editor/VideoEditor.tsx (1)

1488-1496: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Debounce crop-driven MP4 support probing

When the crop editor is in native aspect ratio, each drag update can change desiredMp4SourceDimensions and re-run probeSupportedMp4Dimensions. The cache only helps on exact repeats; unique intermediate sizes still hit the encoder support check. Debounce the crop updates or probe only on commit/close.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/video-editor/VideoEditor.tsx` around lines 1488 - 1496,
Debounce crop-driven MP4 support probing to avoid checking every unique
intermediate dimension during dragging. Update the logic around
desiredMp4SourceDimensions and probeSupportedMp4Dimensions to defer probing
until crop changes settle, or trigger it only when the crop is committed/closed,
while preserving immediate handling of non-crop dependency changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/components/video-editor/VideoEditor.tsx`:
- Around line 1488-1496: Debounce crop-driven MP4 support probing to avoid
checking every unique intermediate dimension during dragging. Update the logic
around desiredMp4SourceDimensions and probeSupportedMp4Dimensions to defer
probing until crop changes settle, or trigger it only when the crop is
committed/closed, while preserving immediate handling of non-crop dependency
changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b43a363b-9b0e-48a0-8e8a-d9b1307441f8

📥 Commits

Reviewing files that changed from the base of the PR and between 8ac06cf and 0d7596f.

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

@meiiie

meiiie commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@meiiie

meiiie commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@meiiie

meiiie commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/components/video-editor/exportDimensions.test.ts (1)

28-47: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a regression test for crop ignored on fixed-aspect exports.

The PR explicitly states fixed-aspect-ratio exports keep their prior (non-cropped) behavior, but no test passes a cropRegion together with a non-"native" aspect ratio to confirm it's ignored. Worth locking this in given it's the exact boundary this PR carves out.

♻️ Suggested additional test
 	it("uses the rotated source bounds for 9:16 original exports", () => {
 		expect(calculateMp4SourceDimensions(1920, 1080, "9:16")).toEqual({
 			width: 1080,
 			height: 1920,
 		});
 	});
+
+	it("ignores cropRegion for non-native aspect ratios", () => {
+		expect(
+			calculateMp4SourceDimensions(1920, 1080, "9:16", { width: 0.5, height: 0.5 }),
+		).toEqual({
+			width: 1080,
+			height: 1920,
+		});
+	});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/video-editor/exportDimensions.test.ts` around lines 28 - 47,
Add a regression test alongside the existing calculateMp4SourceDimensions tests
that passes a cropRegion with a fixed non-"native" aspect ratio and asserts the
result matches the uncropped dimensions. Use calculateMp4SourceDimensions and a
representative ratio such as "4:3", confirming cropRegion is ignored for
fixed-aspect exports.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/components/video-editor/exportDimensions.test.ts`:
- Around line 28-47: Add a regression test alongside the existing
calculateMp4SourceDimensions tests that passes a cropRegion with a fixed
non-"native" aspect ratio and asserts the result matches the uncropped
dimensions. Use calculateMp4SourceDimensions and a representative ratio such as
"4:3", confirming cropRegion is ignored for fixed-aspect exports.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7c257064-3972-4729-b12e-9562845f5c15

📥 Commits

Reviewing files that changed from the base of the PR and between 0d7596f and 855998e.

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

@meiiie

meiiie commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@meiiie meiiie merged commit 770536f into main Jul 11, 2026
4 checks passed
@meiiie meiiie deleted the fix/746-remove-background-export-parity branch July 11, 2026 05:27
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.

1 participant