Last active
July 17, 2019 13:16
-
-
Save 599316527/425a6a8d8cdfde4e85aef1c577d89f19 to your computer and use it in GitHub Desktop.
ffmpeg compress video to a specific filesize
This file contains 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
#!/bin/zsh | |
ffmpegParam="-hide_banner -y"; | |
videoEncodeParam="-c:v libx264 -crf 23 -profile:v main -level 3.1 -pix_fmt yuv420p -movflags +faststart -s 1024x768"; | |
audioEncodeParam="-an"; | |
fileSizeParam="-b:v 1.6M -maxrate 1.6M -bufsize 2m"; | |
echo "Convert: $1 -> $2"; | |
# Use two-pass to reduce size https://trac.ffmpeg.org/wiki/Encode/H.264 | |
/usr/local/bin/ffmpeg $ffmpegParam -i $1 $videoEncodeParam $audioEncodeParam $fileSizeParam -pass 1 -f mp4 /dev/null && \ | |
/usr/local/bin/ffmpeg $ffmpegParam -i $1 $videoEncodeParam $audioEncodeParam $fileSizeParam -pass 2 -f mp4 $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment