#!/usr/bin/env bash
#
# usage: rip <device/dir> <title> <num chapters> <audio track> <scale factor>
#
# Note: the last chapter is usually not a valid track; delete if zero length.
#
# Probe with:
#   tcprobe -i <device/dir>
#   mplayer dvd://<title> -dvd-device <device/dir> -frames 0 -identify
#
# Scan for volume scale factor:
#   tccat -T 1,-1 -i <device/dir> -t dvd -a 0 -d 2 | tcextract -t vob -x pcm | tcscan -x pcm -d 1
#
# for ac3 only, change the tcextract to ac3 and add | tcdecode -x ac3

cha=1
until [ $cha -gt $3 ]
do
   transcode -i $1 -x null,auto -s $5 -a $4 -y null,raw -T $2,$cha,1 -m cha-$cha.mp3
   #mplayer dvd://$2 -dvd-device $1 -aid $4 -vc null -vo null -ao pcm:file='cha-$cha.wav' -chapter '$cha-$cha'
   # 
   cha=$(( $cha + 1 ))
done
