Skip to content

Instantly share code, notes, and snippets.

@karltaylor
Last active July 26, 2021 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save karltaylor/f5e460123a661429148f44230bdf969f to your computer and use it in GitHub Desktop.
Save karltaylor/f5e460123a661429148f44230bdf969f to your computer and use it in GitHub Desktop.
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
@karltaylor
Copy link
Author

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.

@karltaylor
Copy link
Author

Still works 💪

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