Skip to content

Instantly share code, notes, and snippets.

@PatrickKalkman
Created May 26, 2025 14:22
Show Gist options
  • Save PatrickKalkman/19092f60d3487224b7aed65a793054f0 to your computer and use it in GitHub Desktop.
Save PatrickKalkman/19092f60d3487224b7aed65a793054f0 to your computer and use it in GitHub Desktop.
def encode_intro_segment_core(
video_file_path: str,
duration: float = 300.0, # 5 minutes
video_height: int = 120, # Low resolution
video_crf: int = 28, # Quality setting
video_fps: int = 5, # Reduced frame rate
) -> Optional[str]:
"""Extract and encode the first 5 minutes of the video."""
# Build optimized ffmpeg command
cmd = [
"ffmpeg", "-y", "-i", str(input_path),
"-t", str(duration),
"-vf", f"scale=trunc(oh*a/2)*2:{video_height},format=gray",
"-c:v", "libx264", "-crf", str(video_crf),
"-preset", "fast", "-r", str(video_fps),
"-an", # Remove audio entirely
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment