Skip to content

Instantly share code, notes, and snippets.

@599316527
Last active July 17, 2019 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 599316527/425a6a8d8cdfde4e85aef1c577d89f19 to your computer and use it in GitHub Desktop.
Save 599316527/425a6a8d8cdfde4e85aef1c577d89f19 to your computer and use it in GitHub Desktop.
ffmpeg compress video to a specific filesize
#!/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