Looking for a cheap solution to encode videos I created a docker container and an encoding script to automate this.

Dockerfile:

FROM ubuntu
RUN /bin/bash -c 'apt update && apt -y install handbrake-cli cpulimit psmisc'
COPY ./encode.sh /
RUN /bin/bash -c 'chmod +x encode.sh;mkdir /media/downloads'
VOLUME /media/downloads
ENTRYPOINT ["/bin/bash"]

encode.sh:

#!/bin/bash
SRC="/media/downloads/sources"
DEST="/media/downloads/encoded"
DEST_EXT=mp4
HANDBRAKE_CLI=HandBrakeCLI
PRESET="Universal"
cpulimit -e $HANDBRAKE_CLI -l 80 -b
for FILE in "$SRC"/*
do
filename=$(basename "$FILE")
extension=${filename##*.}
filename=${filename%.*}
$HANDBRAKE_CLI -i "$FILE" -o "$DEST"/"$filename".$DEST_EXT "$PRESET" --subtitle-lang-list fre --all-subtitles
echo $FILE
echo "DONE"
done
killall cpulimit
echo $DEST
echo "Encoding task(s) finished"

How it works?

To start encoding job, launch the encode.sh script

./encode.sh

The encode.sh script will look for files into the /media/downloads/sources and will encode each of them using the "universal" preset and french subtitles.

The new file will be stored in the /media/downloads/encoded folder.

The cpulimit is here to make sure the container is not eating all resources.

The container has the /media/downloads volume linked to a host folder.