compress
This commit is contained in:
@@ -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:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user