Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions helpers/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,33 @@ def is_hdr_source(video: Path) -> bool:


def is_portrait_source(video: Path) -> bool:
"""Return True if the video's height > width (portrait / vertical)."""
"""Return True if the video displays taller than wide (portrait / vertical).

Phone cameras store vertical footage as a landscape stream plus a rotation
entry. ffmpeg auto-rotates on decode, so the displayed dimensions -- not the
stored ones -- decide which axis to scale by.
"""
try:
out = subprocess.run(
["ffprobe", "-v", "error", "-select_streams", "v:0",
"-show_entries", "stream=width,height",
"-of", "csv=p=0", str(video)],
"-show_entries", "stream=width,height:stream_side_data=rotation:stream_tags=rotate",
"-of", "json", str(video)],
capture_output=True, text=True, check=True,
)
w, h = map(int, out.stdout.strip().split(","))
stream = json.loads(out.stdout)["streams"][0]
w, h = int(stream["width"]), int(stream["height"])

rotation = 0
for side_data in stream.get("side_data_list", []):
if "rotation" in side_data:
rotation = int(side_data["rotation"])
break
else:
# ffmpeg < 5 exposes the display matrix as a stream tag instead.
rotation = int(stream.get("tags", {}).get("rotate", 0))

if rotation % 180 != 0:

@cubic-dev-ai cubic-dev-ai Bot Jul 16, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Non-right-angle rotation metadata is classified as portrait, so slightly rotated landscape sources can take the portrait scaling path. Limit the swap to 90°/270° rotations, which are the only cases that exchange axes.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At helpers/render.py, line 160:

<comment>Non-right-angle rotation metadata is classified as portrait, so slightly rotated landscape sources can take the portrait scaling path. Limit the swap to 90°/270° rotations, which are the only cases that exchange axes.</comment>

<file context>
@@ -132,15 +132,33 @@ def is_hdr_source(video: Path) -> bool:
+            # ffmpeg < 5 exposes the display matrix as a stream tag instead.
+            rotation = int(stream.get("tags", {}).get("rotate", 0))
+
+        if rotation % 180 != 0:
+            w, h = h, w
         return h > w
</file context>
Suggested change
if rotation % 180 != 0:
if rotation % 180 == 90:
Fix with cubic

w, h = h, w
return h > w
except Exception:
return False
Expand Down