Fix is_portrait_source: account for display-matrix rotation#67
Open
VitorMRodovalho wants to merge 1 commit into
Open
Fix is_portrait_source: account for display-matrix rotation#67VitorMRodovalho wants to merge 1 commit into
VitorMRodovalho wants to merge 1 commit into
Conversation
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>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Renders of vertical phone footage come out with broken geometry because
is_portrait_sourceignores rotation metadata.Repro
A clip shot on a phone is often stored landscape (e.g.
848x480) with arotation=-90display matrix, and displays vertically (480x848). ffmpeg auto-applies the display matrix on decode.is_portrait_sourceonly compares rawwidth/height, so it classifies the clip as landscape andextract_segmentpicksscale=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.Fix
Add
_probe_rotation()(readsstream_side_data=rotation/stream_tags=rotate) and haveis_portrait_sourceswap orientation on a quarter-turn (±90/±270; 180 keeps orientation). The scale branch then matches the displayed frame.Verification
Same real
848x480,rotation=-90clip after the patch: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.
_probe_rotation()to readstream_side_data=rotationandstream_tags=rotateviaffprobe.is_portrait_sourceto swap width/height on ±90/±270; 0/180 unchanged.Written for commit e71134a. Summary will update on new commits.