Skip to content

Instantly share code, notes, and snippets.

@ymollard
Created May 19, 2017 14:45
Show Gist options
  • Save ymollard/368657f74a716ce5db67af868e9b23e0 to your computer and use it in GitHub Desktop.
Save ymollard/368657f74a716ce5db67af868e9b23e0 to your computer and use it in GitHub Desktop.
Two pass FFMPEG

Your video is 10 minutes (600 seconds) long and an output of 200 MiB is desired. Since bitrate = file size / duration:

(200 MiB * 8192 [converts MiB to kBit]) / 600 seconds = ~2730 kBit/s total bitrate 2730 - 128 kBit/s (desired audio bitrate) = 2602 kBit/s video bitrate

ffmpeg -y -i input -c:v libx264 -preset medium -b:v 2600k -pass 1 -c:a aac -b:a 128k -f mp4 /dev/null
ffmpeg -i input -c:v libx264 -preset medium -b:v 2600k -pass 2 -c:a aac -b:a 128k output.mp4

From FFMPEG H264 documentation.

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