I have a batch conversion script to turn .mkvs of various dimensions into ipod/iphone sized .mp4s, cropping/scaling to suit. Determining the original dimensions, required crop, output file is all working fine. However, on successful completion of the first conversion, HandbrakeCLI causes the parent script to exit. Why would this be? And how can I stop it?
The code, as it currently stands:
#!/bin/bash
find . -name "*.mkv" | while read FILE
do
# What would the output file be?
DST=../Touch/$(dirname "$FILE")
MKV=$(basename "$FILE")
MP4=${MKV%%.mkv}.mp4
# If it already exists, don't overwrite it
if [ -e "$DST/$MP4" ]
then
echo "NOT overwriting $DST/$MP4"
else
# Stuff to determine dimensions/cropping removed for brevity
HandbrakeCLI --preset "iPhone & iPod Touch" --vb 900 --crop $crop -i "$FILE" -o "$DST/$MP4" > /dev/null 2>&1
if [ $? != 0 ]
then
echo "$FILE had problems" >> errors.log
fi
fi
done
I have additionally tried it with a trap, but that didn't change the behaviour (although the last trap did fire)
trap "echo Handbrake SIGINT-d" SIGINT
trap "echo Handbrake SIGTERM-d" SIGTERM
trap "echo Handbrake EXIT-d" EXIT
trap "echo Handbrake 0-d" 0