Created
August 20, 2025 19:37
-
-
Save dhcgn/79f02039ba78843e1af9cf56529e6967 to your computer and use it in GitHub Desktop.
Optimize a video file for web with ffmpeg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# params | |
VF="scale='min(1280,iw)':'min(720,ih)':force_original_aspect_ratio=decrease" | |
# Pass 1 | |
ffmpeg -y -i main.mp4 -map 0:v:0 -an \ | |
-c:v libx264 -pix_fmt yuv420p -profile:v high -level 4.1 -preset slow \ | |
-vf "$VF" -g 60 -keyint_min 60 -sc_threshold 0 \ | |
-b:v 1150k -maxrate 1500k -bufsize 3000k \ | |
-movflags +faststart -pass 1 -f mp4 /dev/null | |
# Pass 2 | |
ffmpeg -i main.mp4 -map 0:v:0 -map 0:a:0? \ | |
-c:v libx264 -pix_fmt yuv420p -profile:v high -level 4.1 -preset slow \ | |
-vf "$VF" -g 60 -keyint_min 60 -sc_threshold 0 \ | |
-b:v 1150k -maxrate 1500k -bufsize 3000k \ | |
-c:a aac -ac 2 -b:a 96k \ | |
-movflags +faststart -pass 2 output.mp4 | |
ls -lh output.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment