From d0b698984967190eb02f92ea476c55171d945704 Mon Sep 17 00:00:00 2001 From: Anton Sidorov aka anticodeguy Date: Thu, 30 Apr 2026 13:35:11 +0700 Subject: [PATCH] fix(render): preserve vertical aspect when source is portrait The scale filter in extract_segment hardcoded scale=1920:-2 (or scale=1280:-2 in draft mode), which assumes a landscape source. Given a portrait source like 1080x1920 from a phone, this upscaled width to 1920 and pushed height to 3414, producing an off-spec 1920x3414 output instead of the expected 1080x1920. Probe the source with ffprobe and pick the scale axis from orientation: - portrait (h > w): scale=-2:1920 / scale=-2:1280 - landscape: scale=1920:-2 / scale=1280:-2 This keeps native portrait sources at 1080x1920 in final/preview and 720x1280 in draft, matching the documented vertical social target in SKILL.md. --- helpers/render.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/helpers/render.py b/helpers/render.py index e1260aa..e9b9a0e 100644 --- a/helpers/render.py +++ b/helpers/render.py @@ -154,10 +154,21 @@ def extract_segment( """ out_path.parent.mkdir(parents=True, exist_ok=True) + probe = subprocess.run( + ["ffprobe", "-v", "error", "-select_streams", "v:0", + "-show_entries", "stream=width,height", + "-of", "csv=p=0:s=x", str(source)], + capture_output=True, text=True, + ) + try: + sw, sh = (int(x) for x in probe.stdout.strip().split("x")[:2]) + is_vertical = sh > sw + except Exception: + is_vertical = False if draft: - scale = "scale=1280:-2" + scale = "scale=-2:1280" if is_vertical else "scale=1280:-2" else: - scale = "scale=1920:-2" + scale = "scale=-2:1920" if is_vertical else "scale=1920:-2" vf_parts: list[str] = [] if is_hdr_source(source):