Created
September 20, 2020 18:05
-
-
Save polikeiji/c3a82f81a810b8c5168265ac12601c9b to your computer and use it in GitHub Desktop.
Export DVD chapters into separate movie files using HandBrakeCLI and jq.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SOURCE=$1 | |
DEST_BASE=$2 | |
if [ -z $3 ]; then | |
SCAN_RESULT=$(HandBrakeCLI -i $SOURCE --scan -t 0 --json | sed '1,/JSON Title Set/d') | |
SCAN_RESULT=$(echo "{" $SCAN_RESULT) | |
echo $SCAN_RESULT >$DEST_BASE.json | |
else | |
SCAN_RESULT=$(cat $3) | |
fi | |
TO=$4 | |
for i in $(echo $SCAN_RESULT | jq -r '.TitleList[1:][] | "\(.Index):\(.ChapterList | length)"'); do | |
INDEX=$(echo $i | cut -d : -f 1) | |
echo "($INDEX) Now scanning." | |
for c in $(seq 1 $(echo $i | cut -d : -f 2)); do | |
if [ -z $TO ] || [ $INDEX -le $TO ]; then | |
DEST=${DEST_BASE}-$(printf %02d $INDEX)-$(printf %02d $c).m4v | |
if [ ! -f "$DEST" ]; then | |
HandBrakeCLI -i $SOURCE -Z "HQ 1080p30 Surround" -t $INDEX -c $c -o ${DEST} | |
else | |
echo "Skipped ($DEST)." | |
fi | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment