Skip to content

Instantly share code, notes, and snippets.

@seb26
Created May 26, 2025 08:19
Show Gist options
  • Save seb26/120248a315637f1768f2cae612cde6c9 to your computer and use it in GitHub Desktop.
Save seb26/120248a315637f1768f2cae612cde6c9 to your computer and use it in GitHub Desktop.
#!/bin/bash
input_file="$1"
basename=$(basename "$input_file" | sed 's/\.[^.]*$//') # remove extension
timestamp=$(date +%H%M%S)
output_file="${basename}_${timestamp}.mp4"
ffmpeg \
-i "$input_file" \
-c:v libx264 \ # best H.264 encoder
-b:v 2.8M \ # leave ~200k for audio inside 3M total
-maxrate 2.8M \ # cap peak video bitrate
-bufsize 5.6M \ # 2x buffer for stable rate control
-preset veryslow \ # best compression (if time allows)
-profile:v high \ # advanced compression tools
-level 4.1 \ # max device compatibility (up to 1080p60)
-crf 18 \ # visually lossless baseline, tightens quality
-pix_fmt yuv420p \ # 8-bit 4:2:0 → widest playback support
-c:a aac \ # AAC → best balance of quality + compatibility
-b:a 192k \ # cap audio at 192 kbps (best quality allowed)
-ac 2 \ # ensure stereo output (no extra channels)
"$output_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment