Skip to content

Fix is_portrait_source: account for display-matrix rotation#67

Open
VitorMRodovalho wants to merge 1 commit into
browser-use:mainfrom
VitorMRodovalho:fix/portrait-rotation-detection
Open

Fix is_portrait_source: account for display-matrix rotation#67
VitorMRodovalho wants to merge 1 commit into
browser-use:mainfrom
VitorMRodovalho:fix/portrait-rotation-detection

Conversation

@VitorMRodovalho

@VitorMRodovalho VitorMRodovalho commented Jun 15, 2026

Copy link
Copy Markdown

Renders of vertical phone footage come out with broken geometry because is_portrait_source ignores rotation metadata.

Repro

A clip shot on a phone is often stored landscape (e.g. 848x480) with a rotation=-90 display matrix, and displays vertically (480x848). ffmpeg auto-applies the display matrix on decode.

is_portrait_source only compares raw width/height, so it classifies the clip as landscape and extract_segment picks scale=1920:-2. After ffmpeg applies the rotation, scaling the (now portrait) frame by width to 1920 yields a stretched 1920x3392 instead of ~1080x1920 — wrong aspect, and roughly double the file size.

$ ffprobe -select_streams v:0 -show_entries stream_side_data=rotation in.mp4
rotation=-90
# before this patch:
$ ffprobe -select_streams v:0 -show_entries stream=width,height final.mp4
width=1920
height=3392

Fix

Add _probe_rotation() (reads stream_side_data=rotation / stream_tags=rotate) and have is_portrait_source swap orientation on a quarter-turn (±90/±270; 180 keeps orientation). The scale branch then matches the displayed frame.

Verification

Same real 848x480, rotation=-90 clip after the patch:

width=1086
height=1920

Correct 9:16, file size roughly halved. No change for non-rotated or genuinely-landscape sources (rotation 0/180 → no swap).


Assisted-By: Claude (Anthropic) — patch authored with Claude Code; human is sole author of record.


Summary by cubic

Fixes portrait detection to respect display-matrix rotation so vertical phone footage scales correctly. Prevents stretched outputs (e.g., 1920x3392) and lowers file size.

  • Bug Fixes
    • Added _probe_rotation() to read stream_side_data=rotation and stream_tags=rotate via ffprobe.
    • Updated is_portrait_source to swap width/height on ±90/±270; 0/180 unchanged.
    • Scaling now matches displayed orientation; a rotated 848x480 clip renders ~1080x1920 instead of 1920x3392.
    • No change for non-rotated or 180° sources.

Written for commit e71134a. Summary will update on new commits.

Review in cubic

Phone footage is commonly stored landscape (e.g. 848x480) with a
rotation=±90 display matrix and actually displays vertically. The old
is_portrait_source only compared raw width/height, so these rotated
sources were classified as landscape. ffmpeg auto-applies the display
matrix on decode, so scale=1920:-2 then stretched the rotated picture to
a broken geometry (1920x3392 instead of ~1080x1920), doubling file size.

Probe the rotation side_data / rotate tag and swap orientation on a
quarter-turn (±90/±270; 180 keeps orientation), so the scale branch
matches the displayed frame. Verified on a real 848x480 rotation=-90
clip: output now renders 1086x1920.

Assisted-By: Claude (Anthropic) <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

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