33 lines
1.2 KiB
Bash
Executable File
33 lines
1.2 KiB
Bash
Executable File
#! /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
|