xanas3712
24th August 2007, 04:23
Ok, this script.. "mostly" works but the problem is there is a slight drift over the course of the dvd I just can't figure out.
The way I"m accounting for multiple angles might not be completely accurate. What I'm doing is whenever there are duplicate timecodes present I subtract the timecodes of one of the cells in order to create a resulting corrected chapterfile.
The drift (as most drifts are) happens over time. I thought maybe this was due to a minor addition problem in the psecs but that doesn't appear to be the case, because I've examined that thoroughly and it seems the addition/subtraction is going just fine..
I'd appreciate any help
#!/bin/bash
#lsdvd /dev/sr0 -t 4 -c | grep Chapter: > chapterfile
#lsdvd /dev/sr0 -t 4 -d | grep Cell: > cellfile
#cat chapterfile | sed s'/.*: \([0-9]*\),.*/CHAPTER\1NAME=Chapter \1/'
#cat chapterfile | sed s'/.*Length: \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9].*\),.*/\1/'
#cat chapterfile | sed s'/.*Length: #\([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9].*\),.*/\2/'
#cat chapterfile | sed s'/.*Length: \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9].*\),.*/\3/'
#cat chapterfile | sed s'/.*Cell: \([0-9].*\).*/\1/'
i=0
while read line; do
cellpscs[${i}]=`echo $line | sed 's/.*\([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).\([0-9]*\).*/\4/'`
#remove leading 0s to stop that octal math!!!!
cellpscs[${i}]=`echo ${cellpscs[${i}]} | sed 's/^0//'`
cellsecs[${i}]=`echo $line | sed 's/.*\([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).*/\3/'`
cellsecs[${i}]=`echo ${cellsecs[${i}]} | sed 's/^0//'`
cellmins[${i}]=`echo $line | sed 's/.*\([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).*/\2/'`
cellmins[${i}]=`echo ${cellmins[${i}]} | sed 's/^0//'`
cellhrs[${i}]=`echo $line | sed 's/.*\([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).*/\1/'`
cellhrs[${i}]=`echo ${cellhrs[${i}]} | sed 's/^0//'`
#echo "${cellhrs[${i}]}:${cellmins[${i}]}:${cellsecs[${i}]}.${cellpscs[${i}]}"
((i++))
done < <(cat cellfile)
i=0
while read line; do
#get # of cells & difference between last cell so I can calc correct length
cellnumcur=`echo ${line} | sed 's/.*Cell: \([0-9].*\).*/\1/'`
#remove leading 0s to stop that octal math!!!!
cellnumcur=`echo ${cellnumcur} | sed 's/^0//'`
if [ "${i}" = "0" ]; then
#the very first loop will get the first chapter, thus 0 0 0 0
spsecs[${i}]=0
sseconds[${i}]=0
sminutes[${i}]=0
shours[${i}]=0
else
#add previous start to previous length to get current start
celldif=$((${cellnumcur}-${cellnum}))
#echo $celldif
#calc length based on cells passed..
subtractpscs=0
subtractsecs=0
subtractmins=0
subtracthrs=0
for((j=0;${j}<$((${celldif}-1));j=${j}+1)); do
#we start from 0 as the cell loop starts from 0, so adding 0 actually gets the next cell, not the start cell
cellid=$((${cellnum}+${j}))
#only add to the subtractvars on those where the current cell duplicates the timecodes
#of the previous cell, because these duplications
#are due to the multiple angles
if [ ${cellpscs[${cellid}]} = ${cellpscs[$((${cellid}-1))]} ] && \
[ ${cellsecs[${cellid}]} = ${cellsecs[$((${cellid}-1))]} ] && \
[ ${cellmins[${cellid}]} = ${cellmins[$((${cellid}-1))]} ] && \
[ ${cellhrs[${cellid}]} = ${cellhrs[$((${cellid}-1))]} ]; then
subtractpscs=$((${subtractpscs}+${cellpscs[${cellid}]}))
if [ "${subtractpscs}" -gt "999" ]; then
subtractpscs=$((${subtractpscs}-1000))
addone=1
else
addone=0
fi
subtractsecs=$((${subtractsecs}+${cellsecs[${cellid}]}+${addone}))
if [ "${subtractsecs}" -gt "59" ]; then
subtractsecs=$((${subtractsecs}-60))
addone=1
else
addone=0
fi
subtractmins=$((${subtractmins}+${cellmins[${cellid}]}+${addone}))
if [ "${subtractmins}" -gt "59" ]; then
subtractmins=$((${subtractmins}-60))
addone=1
else
addone=0
fi
subtracthrs=$((${subtracthrs}+${cellhrs[${cellid}]}+${addone}))
fi
done
#echo $subtracthrs $subtractmins $subtractsecs $subtractpscs
id=$(($i+1))
echo "before: ${id} $lpsecs"
lpsecs=$((${lpsecs}-${subtractpscs}))
if [ "${lpsecs}" -lt "0" ]; then
lpsecs=$((${lpsecs}+1000))
subone=1
else
subone=0
fi
echo "after: ${id} $lpsecs"
lseconds=$((${lseconds}-${subtractsecs}-${subone}))
if [ "${lseconds}" -lt "0" ]; then
lseconds=$((${lseconds}+60))
subone=1
else
subone=0
fi
lminutes=$((${lminutes}-${subtractmins}-${subone}))
if [ "${lminutes}" -lt "0" ]; then
lminutes=$((${lminutes}+60))
subone=1
else
subone=0
fi
lhours=$((${lhours}-${subtracthrs}-${subone}))
#echo "${i} $lhours $lminutes $lseconds $lpsecs"
echo "before: ${id} ${spsecs[${prev}]}"
spsecs[${i}]=$((${spsecs[${prev}]}+${lpsecs}))
if [ "${spsecs[${i}]}" -gt "999" ]; then
spsecs[${i}]=$((${spsecs[${i}]}-1000))
addone=1
else
addone=0
fi
echo "after: ${id} ${spsecs[${i}]}"
sseconds[${i}]=$((${sseconds[${prev}]}+${lseconds}+${addone}))
if [ "${sseconds[${i}]}" -gt "59" ]; then
sseconds[${i}]=$((${sseconds[${i}]}-60))
addone=1
else
addone=0
fi
sminutes[${i}]=$((${sminutes[${prev}]}+${lminutes}+${addone}))
if [ "${sminutes[${i}]}" -gt "59" ]; then
sminutes[${i}]=$((${sminutes[${i}]}-60))
addone=1
else
addone=0
fi
shours[${i}]=$((${shours[${prev}]}+${lhours}+${addone}))
fi
#get current length after getting start, since we need this for next loop...
lpsecs=`echo ${line} | sed 's/.*Length: \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).\([0-9]*\).*/\4/'`
#remove leading 0s to stop that octal math!!!!
lpsecs=`echo ${lpsecs} | sed 's/^0//'`
lseconds=`echo ${line} | sed 's/.*Length: \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).*/\3/'`
lseconds=`echo ${lseconds} | sed 's/^0//'`
lminutes=`echo ${line} | sed 's/.*Length: \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).*/\2/'`
lminutes=`echo ${lminutes} | sed 's/^0//'`
lhours=`echo ${line} | sed 's/.*Length: \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).*/\1/'`
lhours=`echo ${lhours} | sed 's/^0//'`
#echo $lhours $lminutes $lseconds $lpsecs
#set current cell after getting start, need it on the next loop
cellnum=${cellnumcur}
# lol, like i really need to store this????
#these I may use after, or I could cat them out individually to avoid storing... either works...
#chapternum[${i}]=`echo ${line} | sed 's/.*: \([0-9]*\),.*/\1/'`
#chaptername[${i}]="CHAPTER${chapternum[${i}]}NAME=Chapter ${chapternum[${i}]}"
prev=${i}
((i++))
done < <(cat chapterfile)
for((i=0;$i<${#spsecs[@]};i=$i+1)); do
spsecs=${spsecs[${i}]}
if [ "${spsecs}" -lt "10" ]; then
spsecs=00${spsecs}
else
if [ "${spsecs}" -lt "100" ]; then
spsecs=0${spsecs}
fi
fi
sseconds=${sseconds[${i}]}
if [ "${sseconds}" -lt "10" ]; then
sseconds=0${sseconds}
fi
sminutes=${sminutes[${i}]}
if [ "${sminutes}" -lt "10" ]; then
sminutes=0${sminutes}
fi
shours=${shours[${i}]}
if [ "${shours}" -lt "10" ]; then
shours=0${shours}
fi
c=$(($i+1))
if [ $c -lt "10" ]; then
c=0$c
fi
echo "CHAPTER${c}=${shours}:${sminutes}:${sseconds}.${spsecs}" >> newchap.txt
echo "CHAPTER${c}NAME=Chapter ${c}" >> newchap.txt
done
The way I"m accounting for multiple angles might not be completely accurate. What I'm doing is whenever there are duplicate timecodes present I subtract the timecodes of one of the cells in order to create a resulting corrected chapterfile.
The drift (as most drifts are) happens over time. I thought maybe this was due to a minor addition problem in the psecs but that doesn't appear to be the case, because I've examined that thoroughly and it seems the addition/subtraction is going just fine..
I'd appreciate any help
#!/bin/bash
#lsdvd /dev/sr0 -t 4 -c | grep Chapter: > chapterfile
#lsdvd /dev/sr0 -t 4 -d | grep Cell: > cellfile
#cat chapterfile | sed s'/.*: \([0-9]*\),.*/CHAPTER\1NAME=Chapter \1/'
#cat chapterfile | sed s'/.*Length: \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9].*\),.*/\1/'
#cat chapterfile | sed s'/.*Length: #\([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9].*\),.*/\2/'
#cat chapterfile | sed s'/.*Length: \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9].*\),.*/\3/'
#cat chapterfile | sed s'/.*Cell: \([0-9].*\).*/\1/'
i=0
while read line; do
cellpscs[${i}]=`echo $line | sed 's/.*\([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).\([0-9]*\).*/\4/'`
#remove leading 0s to stop that octal math!!!!
cellpscs[${i}]=`echo ${cellpscs[${i}]} | sed 's/^0//'`
cellsecs[${i}]=`echo $line | sed 's/.*\([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).*/\3/'`
cellsecs[${i}]=`echo ${cellsecs[${i}]} | sed 's/^0//'`
cellmins[${i}]=`echo $line | sed 's/.*\([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).*/\2/'`
cellmins[${i}]=`echo ${cellmins[${i}]} | sed 's/^0//'`
cellhrs[${i}]=`echo $line | sed 's/.*\([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).*/\1/'`
cellhrs[${i}]=`echo ${cellhrs[${i}]} | sed 's/^0//'`
#echo "${cellhrs[${i}]}:${cellmins[${i}]}:${cellsecs[${i}]}.${cellpscs[${i}]}"
((i++))
done < <(cat cellfile)
i=0
while read line; do
#get # of cells & difference between last cell so I can calc correct length
cellnumcur=`echo ${line} | sed 's/.*Cell: \([0-9].*\).*/\1/'`
#remove leading 0s to stop that octal math!!!!
cellnumcur=`echo ${cellnumcur} | sed 's/^0//'`
if [ "${i}" = "0" ]; then
#the very first loop will get the first chapter, thus 0 0 0 0
spsecs[${i}]=0
sseconds[${i}]=0
sminutes[${i}]=0
shours[${i}]=0
else
#add previous start to previous length to get current start
celldif=$((${cellnumcur}-${cellnum}))
#echo $celldif
#calc length based on cells passed..
subtractpscs=0
subtractsecs=0
subtractmins=0
subtracthrs=0
for((j=0;${j}<$((${celldif}-1));j=${j}+1)); do
#we start from 0 as the cell loop starts from 0, so adding 0 actually gets the next cell, not the start cell
cellid=$((${cellnum}+${j}))
#only add to the subtractvars on those where the current cell duplicates the timecodes
#of the previous cell, because these duplications
#are due to the multiple angles
if [ ${cellpscs[${cellid}]} = ${cellpscs[$((${cellid}-1))]} ] && \
[ ${cellsecs[${cellid}]} = ${cellsecs[$((${cellid}-1))]} ] && \
[ ${cellmins[${cellid}]} = ${cellmins[$((${cellid}-1))]} ] && \
[ ${cellhrs[${cellid}]} = ${cellhrs[$((${cellid}-1))]} ]; then
subtractpscs=$((${subtractpscs}+${cellpscs[${cellid}]}))
if [ "${subtractpscs}" -gt "999" ]; then
subtractpscs=$((${subtractpscs}-1000))
addone=1
else
addone=0
fi
subtractsecs=$((${subtractsecs}+${cellsecs[${cellid}]}+${addone}))
if [ "${subtractsecs}" -gt "59" ]; then
subtractsecs=$((${subtractsecs}-60))
addone=1
else
addone=0
fi
subtractmins=$((${subtractmins}+${cellmins[${cellid}]}+${addone}))
if [ "${subtractmins}" -gt "59" ]; then
subtractmins=$((${subtractmins}-60))
addone=1
else
addone=0
fi
subtracthrs=$((${subtracthrs}+${cellhrs[${cellid}]}+${addone}))
fi
done
#echo $subtracthrs $subtractmins $subtractsecs $subtractpscs
id=$(($i+1))
echo "before: ${id} $lpsecs"
lpsecs=$((${lpsecs}-${subtractpscs}))
if [ "${lpsecs}" -lt "0" ]; then
lpsecs=$((${lpsecs}+1000))
subone=1
else
subone=0
fi
echo "after: ${id} $lpsecs"
lseconds=$((${lseconds}-${subtractsecs}-${subone}))
if [ "${lseconds}" -lt "0" ]; then
lseconds=$((${lseconds}+60))
subone=1
else
subone=0
fi
lminutes=$((${lminutes}-${subtractmins}-${subone}))
if [ "${lminutes}" -lt "0" ]; then
lminutes=$((${lminutes}+60))
subone=1
else
subone=0
fi
lhours=$((${lhours}-${subtracthrs}-${subone}))
#echo "${i} $lhours $lminutes $lseconds $lpsecs"
echo "before: ${id} ${spsecs[${prev}]}"
spsecs[${i}]=$((${spsecs[${prev}]}+${lpsecs}))
if [ "${spsecs[${i}]}" -gt "999" ]; then
spsecs[${i}]=$((${spsecs[${i}]}-1000))
addone=1
else
addone=0
fi
echo "after: ${id} ${spsecs[${i}]}"
sseconds[${i}]=$((${sseconds[${prev}]}+${lseconds}+${addone}))
if [ "${sseconds[${i}]}" -gt "59" ]; then
sseconds[${i}]=$((${sseconds[${i}]}-60))
addone=1
else
addone=0
fi
sminutes[${i}]=$((${sminutes[${prev}]}+${lminutes}+${addone}))
if [ "${sminutes[${i}]}" -gt "59" ]; then
sminutes[${i}]=$((${sminutes[${i}]}-60))
addone=1
else
addone=0
fi
shours[${i}]=$((${shours[${prev}]}+${lhours}+${addone}))
fi
#get current length after getting start, since we need this for next loop...
lpsecs=`echo ${line} | sed 's/.*Length: \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).\([0-9]*\).*/\4/'`
#remove leading 0s to stop that octal math!!!!
lpsecs=`echo ${lpsecs} | sed 's/^0//'`
lseconds=`echo ${line} | sed 's/.*Length: \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).*/\3/'`
lseconds=`echo ${lseconds} | sed 's/^0//'`
lminutes=`echo ${line} | sed 's/.*Length: \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).*/\2/'`
lminutes=`echo ${lminutes} | sed 's/^0//'`
lhours=`echo ${line} | sed 's/.*Length: \([0-9][0-9]\):\([0-9][0-9]\):\([0-9][0-9]\).*/\1/'`
lhours=`echo ${lhours} | sed 's/^0//'`
#echo $lhours $lminutes $lseconds $lpsecs
#set current cell after getting start, need it on the next loop
cellnum=${cellnumcur}
# lol, like i really need to store this????
#these I may use after, or I could cat them out individually to avoid storing... either works...
#chapternum[${i}]=`echo ${line} | sed 's/.*: \([0-9]*\),.*/\1/'`
#chaptername[${i}]="CHAPTER${chapternum[${i}]}NAME=Chapter ${chapternum[${i}]}"
prev=${i}
((i++))
done < <(cat chapterfile)
for((i=0;$i<${#spsecs[@]};i=$i+1)); do
spsecs=${spsecs[${i}]}
if [ "${spsecs}" -lt "10" ]; then
spsecs=00${spsecs}
else
if [ "${spsecs}" -lt "100" ]; then
spsecs=0${spsecs}
fi
fi
sseconds=${sseconds[${i}]}
if [ "${sseconds}" -lt "10" ]; then
sseconds=0${sseconds}
fi
sminutes=${sminutes[${i}]}
if [ "${sminutes}" -lt "10" ]; then
sminutes=0${sminutes}
fi
shours=${shours[${i}]}
if [ "${shours}" -lt "10" ]; then
shours=0${shours}
fi
c=$(($i+1))
if [ $c -lt "10" ]; then
c=0$c
fi
echo "CHAPTER${c}=${shours}:${sminutes}:${sseconds}.${spsecs}" >> newchap.txt
echo "CHAPTER${c}NAME=Chapter ${c}" >> newchap.txt
done