Last active
May 11, 2020 11:20
-
-
Save mjtorn/482f35f3b5eb3b07b4f5cf09392857c0 to your computer and use it in GitHub Desktop.
Simple script to rip your DVDs
This file contains 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
#!/usr/bin/env bash | |
# vim: ts=4 sw=4 sts=4 et ai | |
set -eu | |
### Usage: mapfile arguments | |
### | |
### Mapfile format: | |
### 1 1x09 - Fire on the Mountain | |
### ^ ^ | |
### | +- Output file name (sans .mp4) | |
### +---- Title number | |
### | |
### | |
### Extra arguments are passed to HandBrakeCLI | |
### | |
### Recommendations: | |
### Transformers G1 | |
### -a2 -q19 | |
### | |
### | |
### Greetz and thankz to Con Kolivas for | |
### the HandBrake options! | |
### | |
IFS=" | |
" | |
HB=$(which HandBrakeCLI) || { | |
echo "HandBrakeCLI not found" | |
exit 1 | |
} | |
DVDW_DEVICE=${DVDW_DEVICE:-"/dev/sr0"} | |
DVDW_CPUCOUNT=${DVDW_CPUCOUNT:-$(nproc --all)} | |
DVDW_MODE=${DVDW_MODE:-"pal_4_3"} | |
OPT_720P="nombtree:keyint=1000:scenecut=10:ref=9:ip_factor=1:pb_factor=1:direct_pred=auto:weight_b:analyse=all:me=umh:mixed_refs:trellis=0:nofast_pskip:level_idc=41:threads=${DVDW_CPUCOUNT}:aq_mode=0:nodeterministic:psy-rd=0|0:b-adapt=2:level=4.1:direct=auto:fast-pskip=0:ipratio=1.00:pbratio=1.00:aq-mode=0:mbtree=0:cabac=0:no-dct-decimate=1:aq-strength=0:bframes=16" | |
function main () { | |
if [ "$#" -eq 0 ]; then | |
echo "USAGE: $0 mapfile ARGS" | |
exit 1 | |
fi | |
mapfile=$1 | |
shift 1 | |
args=$@ | |
case $DVDW_MODE in | |
pal_4_3) | |
width=720 | |
height=576 | |
fps=25 | |
;; | |
ntsc_4_3) | |
width=720 | |
height=480 | |
fps=30 | |
echo "NTSC not tested, consider not implemented" | |
exit 1 | |
;; | |
*) | |
echo "WTF ${DVDW_MODE}" | |
exit 1 | |
;; | |
esac | |
for line in $(cat $mapfile); do | |
tracknum=$(echo $line | awk '{print $1}') | |
trackname=$(echo $line | awk '{$1=""; print substr($0, 2)}') | |
echo $tracknum | |
echo $trackname | |
$HB -i $DVDW_DEVICE -e x264 -x $OPT_720P \ | |
-w${width} -l${height} r${fps} \ | |
--no-loose-crop --crop 0:0:0:0 \ | |
-t${tracknum} -o "${trackname}.mp4" \ | |
$args | |
done | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment