From 367568860a66affc8813c6d79e26429ff94ab1c6 Mon Sep 17 00:00:00 2001 From: Guillem Hernandez Sola Date: Tue, 19 May 2026 15:59:43 +0200 Subject: [PATCH] compress --- tiktok2bsky.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tiktok2bsky.py b/tiktok2bsky.py index a1de196..44fc7e6 100644 --- a/tiktok2bsky.py +++ b/tiktok2bsky.py @@ -538,14 +538,12 @@ def get_video_duration(path: str) -> float: logging.warning(f"⚠️ ffprobe failed: {e}") return 0.0 - def compress_video(input_path: str, output_path: str, max_duration: int = VIDEO_MAX_DURATION_S, max_size_bytes: int = VIDEO_MAX_SIZE_BYTES) -> bool: try: duration = get_video_duration(input_path) - # Guard: ffprobe returned 0 = file is not a valid video if duration <= 0: logging.error( f"❌ compress_video: ffprobe returned duration={duration} " @@ -569,7 +567,11 @@ def compress_video(input_path: str, output_path: str, "ffmpeg", "-y", "-i", input_path, "-t", str(trim_to), - "-vf", "scale='min(1280,iw)':'min(720,ih)':force_original_aspect_ratio=decrease", + # Scale to fit within 1280×720, then pad to even dimensions + # The pad filter is required because libx264 needs width/height + # divisible by 2. Portrait TikTok videos (9:16) would otherwise + # produce odd widths like 405px and crash the encoder. + "-vf", "scale='min(1280,iw)':'min(720,ih)':force_original_aspect_ratio=decrease,pad=ceil(iw/2)*2:ceil(ih/2)*2", "-c:v", "libx264", "-b:v", f"{video_kbps}k", "-maxrate", f"{video_kbps * 2}k", @@ -596,6 +598,7 @@ def compress_video(input_path: str, output_path: str, logging.error(f"❌ compress_video error: {e}") return False + def download_video(url: str, output_path: str, cookies: list = None) -> bool: """