Skip to content

Instantly share code, notes, and snippets.

Last active July 26, 2021 20:21
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Compress MP4 for online content.
ffmpeg -i input.mp4 -codec:v libx264 -preset slow -b:v 1000k -maxrate 1500k -bufsize 1500k -vf scale=1080:-1 -threads 0 -codec:a libfdk_aac -b:a 128k output.mp4
Copy link

karltaylor commented Feb 14, 2017

To compress all in directory without resizing.

for file in *.mp4; do ffmpeg -i "$file" -vcodec libx264 -crf 22 "${file%.mp4}"-compressed.mp4; done

For the single file version.

ffmpeg -i input.mp4 -vcodec libx264 -crf 22 output-compressed.mp4

Flags and Options

  • -b:v 1000k sets target bitrate
  • -maxrate 1500k sets max bitrate (requires -b:v to be set.)
  • -bufsize 1500k tells the encoder how often to calculate the average bit rate and check to see if it conforms to the average bit rate specified on the command line (-b:v 1000k). More info here.

Copy link

Still works 💪

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