Last active
February 24, 2018 20:08
-
-
Save alexzzhu/fa0fabb6762c96351863507c42de0547 to your computer and use it in GitHub Desktop.
Compresses a video using ffmpeg for conference submissions
This file contains hidden or 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
# First, resize the video to a reasonable size. Here only the width is specified, and the height is determined by the | |
# aspect ratio. | |
ffmpeg -i input.mp4 -vf scale=1024:-2 -an input_resized.mp4 | |
# Here a bitrate of 300k is used. To calculate the right bitrate, use the formula: | |
# bitrate = FILE_SIZE*8192*1000/LENGTH | |
# where FILE_SIZE is in MB and LENGTH is in seconds, and the output bitrate is in kilobits. | |
# e.g. for a 137s video and a desired file size of 5MB, the bitrate should be around 5*8192*1000/137 ~ 300k | |
ffmpeg -y -i input_resized.mp4 -c:v libx264 -preset medium -b:v 300k -pass 1 -an -f mp4 /dev/null | |
ffmpeg -i input_resized.mp4 -c:v libx264 -preset medium -b:v 300k -pass 2 -an input_compressed.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You might get better results using the -crf option, but this guarantees the output file size.