Skip to content

Instantly share code, notes, and snippets.

@Vonr
Last active October 28, 2021 03:13
Show Gist options
  • Select an option

  • Save Vonr/519ff7c70a5a379b4c51be9146f9c801 to your computer and use it in GitHub Desktop.

Select an option

Save Vonr/519ff7c70a5a379b4c51be9146f9c801 to your computer and use it in GitHub Desktop.
8mb video compressor
#!/bin/sh
stripped=$(echo $1 | sed 's/ //g')
rmdir /tmp/8mb
mkdir -p /tmp/8mb/
cp "$1" /tmp/8mb/
mv "/tmp/8mb/$1" /tmp/8mb/$stripped
vbr=$(echo "8*8192/$(ffprobe -i /tmp/8mb/$stripped -v quiet -show_entries format=duration -hide_banner -of default=noprint_wrappers=1:nokey=1)-128-2" | bc -l)
ffmpeg -y -i /tmp/8mb/$stripped -c:v libx264 -b:v ${vbr}k -pass 1 -an -f null /dev/null
ffmpeg -y -i /tmp/8mb/$stripped -c:v libx264 -b:v ${vbr}k -pass 2 -c:a aac -b:a 128k /tmp/8mb/out.mp4
mv /tmp/8mb/out.mp4 "$(echo "${1%.*}-8mb.mp4")"
echo "Output: ${1%.*}-8mb.mp4"
echo "Cleaning up..."
rm -f ffmpeg2pass-0.log
rm -f ffmpeg2pass-0.log.mbtree
rm -f /tmp/8mb/*
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment