Last active
December 11, 2022 03:00
-
-
Save hebrides/8e88cd2b63ea1da54597cabbc3fdc8fe to your computer and use it in GitHub Desktop.
Video Compressor
This file contains 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
# From: https://stackoverflow.com/questions/29082422/ffmpeg-video-compression-specific-file-size | |
# Here's a way to do it automatically with a bash script | |
# Just call like ./script.sh file.mp4 15 for 15mB | |
# Audio Bitrate is 64k | |
# TODO: Write a simple wrapper, make audio variable / add controls | |
bitrate="$(awk "BEGIN {print int($2 * 1024 * 1024 * 8 / $(ffprobe \ | |
-v error \ | |
-show_entries format=duration \ | |
-of default=noprint_wrappers=1:nokey=1 \ | |
"$1" \ | |
) / 1000)}")k" | |
ffmpeg \ | |
-y \ | |
-i "$1" \ | |
-c:v libx264 \ | |
-preset medium \ | |
-b:v $bitrate \ | |
-b:a 64k \ | |
-r 12 \ | |
-pass 1 \ | |
-f mp4 \ | |
/dev/null \ | |
&& \ | |
ffmpeg \ | |
-i "$1" \ | |
-c:v libx264 \ | |
-preset medium \ | |
-b:v $bitrate \ | |
-b:a 64k \ | |
-r 12 \ | |
-pass 2 \ | |
"${1%.*}-$2mB.mp4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment