Skip to content

Instantly share code, notes, and snippets.

@hebrides
Last active December 11, 2022 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hebrides/8e88cd2b63ea1da54597cabbc3fdc8fe to your computer and use it in GitHub Desktop.
Save hebrides/8e88cd2b63ea1da54597cabbc3fdc8fe to your computer and use it in GitHub Desktop.
Video Compressor
# 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