Skip to content

Instantly share code, notes, and snippets.

@jaredkc
Created November 21, 2025 16:19
Show Gist options
  • Select an option

  • Save jaredkc/d4b8510ae4154a70a405c3191a370682 to your computer and use it in GitHub Desktop.

Select an option

Save jaredkc/d4b8510ae4154a70a405c3191a370682 to your computer and use it in GitHub Desktop.
Video Optimization for Web

Video Optimization for Web

Quick Command

Convert a single video to web-optimized MP4:

ffmpeg -i input.mov -vf "scale=-2:1080:flags=lanczos" -c:v libx264 -crf 23 -preset slow -c:a aac -b:a 128k -movflags +faststart output_web.mp4

Batch Conversion

Convert all .mov files in current directory:

for file in *.mov; do
  ffmpeg -i "$file" -vf "scale=-2:1080:flags=lanczos" -c:v libx264 -crf 23 -preset slow -c:a aac -b:a 128k -movflags +faststart "${file%.mov}_web.mp4"
done

Parameter Breakdown

Parameter Purpose
-i input.mov Input file
-vf "scale=-2:1080:flags=lanczos" Scale to 1080p height, maintain aspect ratio, use high-quality Lanczos scaling
-c:v libx264 Use H.264 video codec (universally supported)
-crf 23 Quality level (18-28 range; 23 is good balance, lower = better quality/larger size)
-preset slow Encoding speed (slower = better compression; options: ultrafast, fast, medium, slow, veryslow)
-c:a aac Use AAC audio codec
-b:a 128k Audio bitrate 128kbps
-movflags +faststart Optimize for web streaming (moves metadata to beginning of file)

Adjusting Quality

  • Better quality, larger files: Use -crf 18 to -crf 21
  • Smaller files, lower quality: Use -crf 25 to -crf 28
  • Faster encoding: Change -preset slow to -preset medium or -preset fast

Different Resolutions

  • 720p: Change scale=-2:1080 to scale=-2:720
  • 1440p: Change scale=-2:1080 to scale=-2:1440
  • Keep original size: Remove the -vf "scale=-2:1080:flags=lanczos" parameter entirely

Requirements

  • ffmpeg must be installed
  • Install on macOS: brew install ffmpeg

Results from 2025-11-20

Converted 5 ProRes .mov files (1000M total) to web-optimized MP4s (14.1M total) - 98.6% reduction with excellent quality maintained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment