diff options
author | gennyble <gen@nyble.dev> | 2023-12-09 14:08:24 -0600 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2023-12-09 14:08:24 -0600 |
commit | fcefead773591a5dee2f6571802d5d0985d481cf (patch) | |
tree | b82d56938e0e5b63f8b3345fcb0f204574c7a721 /discordify.sh | |
parent | c5111b3482bd867e13b1d835c9779765dff73d4f (diff) | |
download | 🌦-fcefead773591a5dee2f6571802d5d0985d481cf.tar.gz 🌦-fcefead773591a5dee2f6571802d5d0985d481cf.zip |
add discordify script
Diffstat (limited to 'discordify.sh')
-rwxr-xr-x | discordify.sh | 47 |
1 files changed, 47 insertions, 0 deletions
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 |