Spaces:
Sleeping
Sleeping
import subprocess | |
from fastapi import HTTPException | |
def compress_video(input_path: str, output_path: str, resolution: str = "256x144"): | |
"""Compress video using FFmpeg for maximum reduction, with audio removed.""" | |
command = [ | |
"ffmpeg", | |
"-y", # Force overwrite without asking | |
"-i", input_path, | |
"-vf", f"scale={resolution}", | |
"-an", # Remove audio | |
"-c:v", "libx265", | |
"-preset", "medium", # Changed from veryslow for better speed/compression balance | |
"-crf", "32", | |
"-maxrate", "150k", | |
"-bufsize", "200k", | |
"-r", "10", | |
output_path | |
] | |
try: | |
subprocess.run(command, check=True, capture_output=True, text=True) | |
except subprocess.CalledProcessError as e: | |
print(f"Compression error: {e.stderr}") | |
raise HTTPException(status_code=500, detail="Video compression failed") |