From fcefead773591a5dee2f6571802d5d0985d481cf Mon Sep 17 00:00:00 2001 From: gennyble Date: Sat, 9 Dec 2023 14:08:24 -0600 Subject: add discordify script --- discordify.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 discordify.sh diff --git a/discordify.sh b/discordify.sh new file mode 100755 index 0000000..265e692 --- /dev/null +++ b/discordify.sh @@ -0,0 +1,47 @@ +#!/usr/local/bin/fish + +if test -z "$argv[1]" -o ! -e "$argv[1]" + echo "The input file '$argv[1]' is not present or does not exist" + exit +end + +if test -z "$argv[2]" + echo "Output file not specified!" + exit +end + +set ifile "$argv[1]" +set ofile "$argv[2]" + +# https://stackoverflow.com/q/30977472 +# File length (seconds) +set length (\ + ffprobe -i "$ifile" \ + -show_entries format=duration -v quiet -of csv="p=0"\ + ) + +# I think this is supposed to say KB? But the RHS of the division seems to +# be the filesize in kilobit. It's 7.6 and not 8 (for an 8MB file) because +# i was getting slightly over 8MB. I think because of file overhead? +# - 2023-12-09 genny +# v File Size in MB +set file_bitrate (math "floor((7.6 * 8000) / $length)") +set audio_bitrate 128 +set video_bitrate (math "$file_bitrate - $audio_bitrate") + +echo "Length of '$ifile' is $length and will get a bitrate of "$video_bitrate"kbps" +echo "Output file will be '$ofile'" + +#ffmpeg -i $ifile -vf scale=320:-1 -b:v $bitrate"k" $ofile + +# Two pass: http://trac.ffmpeg.org/wiki/Encode/H.264#twopass +ffmpeg -y -i $ifile \ + -vf scale=960:-1 \ + -c:v libx264 -b:v $video_bitrate"k" -pass 1 \ + -an \ + -f null /dev/null && \ +ffmpeg -i $ifile \ + -vf scale=960:-1 \ + -c:v libx264 -b:v $video_bitrate"k" -pass 2 \ + -c:a aac -b:a $audio_bitrate"k" \ + $ofile -- cgit 1.4.1-3-g733a5