#!/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