#!/bin/bash
# default values

factor=""                     # requantization factor (e.g. from streamanalyze)
title=1                       # 
audio=0x80
video=0x1e0
device=/dev/dvd               # input device (could be anything)
name=goobar                  # name of the output 

function getchapters {
    get_title=$1
    get_device=$2
    tcprobe -i /dev/dvd -T 1 -H 10 2>&1 | egrep "\[Chapter ..\] " | cut -d " " -f 3 | perl -pi -e 's/\n/ /' | perl -pi -e 's/,$//' | perl -pi -e 's/\]//g'
}



getchapters $title $device > $name.chapters
list=`cat $name.chapters`
for chapter in $list
do
echo doing $chapter

mkfifo src1.fifo
mkfifo src2.fifo

tcdemux -i src1.fifo -A $audio > aud.tmp &
tcdemux -i src2.fifo -s $video > vid.tmp &
tccat -i $device -T $title,$chapter | tee src1.fifo src2.fifo > /dev/null
ffmpeg -y -i aud.tmp -i vid.tmp -f mov -s 320x240 -qscale 3 -ab 128000 -ac 2 -threads 4 $name.$chapter.mov

rm -f *.fifo
rm -f *.tmp


done

