From 035b622feca94d9cea517509ba6bd168740a73bf Mon Sep 17 00:00:00 2001 From: Quad Date: Wed, 9 Oct 2019 20:31:38 +0200 Subject: [PATCH] Initial commit --- fedi-compress.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 fedi-compress.sh diff --git a/fedi-compress.sh b/fedi-compress.sh new file mode 100755 index 0000000..82d7414 --- /dev/null +++ b/fedi-compress.sh @@ -0,0 +1,32 @@ +#! /usr/bin/env bash +if [[ $# -ne 5 ]]; then + echo "It's script.sh [input] [output] [start] [length] [bitrate] you idiot" + echo "Converts weebshit to small files for the fediverse with burned-in subs. Audio is always 96k opus" + echo "e.g 'script.sh input.mkv output.webm 13:20 50 500k'" + exit 1 +fi + +unset COLUMNS + +COL="\e[32m" # Green +RESET="\e[0m" # Remove formatting + +INPUTFILE=$1 +OUTPUTFILE=$2 +START=$3 +END=$4 +BITRATE=$5 +HEIGHT="360" +ADDITIONAL="-loglevel error -hide_banner -stats" + +THREADS=$(expr $(cat /proc/cpuinfo | grep "model name" | wc -l) - 1) + +echo -e "${COL}Using $THREADS threads${RESET}\n" + +echo -e "${COL}Extracting subs${RESET}" +ffmpeg -i "$INPUTFILE" $ADDITIONAL -y /tmp/subs.ass +echo -e "${COL}Performing first pass${RESET}" +ffmpeg -i "$INPUTFILE" -ss $START -vf scale=-1:${HEIGHT},ass=/tmp/subs.ass -c:v libvpx-vp9 -b:v $BITRATE -t $END -threads $THREADS $ADDITIONAL -pass 1 -an -sn -f webm -y /dev/null +echo -e "${COL}Encoding actual video${RESET}" +ffmpeg -i "$INPUTFILE" -ss $START -vf scale=-1:${HEIGHT},ass=/tmp/subs.ass -c:v libvpx-vp9 -b:v $BITRATE -c:a libopus -b:a 96k -t $END -threads $THREADS $ADDITIONAL -pass 2 -sn -f webm -y $OUTPUTFILE +rm -rf /tmp/subs.ass