Click to See Complete Forum and Search --> : Looping Statement
Vectorman
02-14-2006, 01:00 AM
I am writing a script that will help me automate me ripping my DVD collection.
Here's how I currently do the rip and encode
Insert the DVD and run lsdvd
With this command I get output to the terminal window like this
Disc Title: DVD_VIDEO
Title: 01, Length: 00:45:11 Chapters: 06, Cells: 06, Audio streams: 02, Subpictures: 00
Title: 02, Length: 00:44:25 Chapters: 06, Cells: 06, Audio streams: 02, Subpictures: 00
Title: 03, Length: 00:44:25 Chapters: 06, Cells: 06, Audio streams: 02, Subpictures: 00
Title: 04, Length: 00:44:28 Chapters: 06, Cells: 06, Audio streams: 02, Subpictures: 00
Longest track: 1
After looking at this and deciding that I want to rip every title on this disk I run the following script for every title
mplayer dvd://<titlenumber> -dvd-device /dev/hdc -dumpstream -dumpfile <dirname>/<moviename>
After the Dump is finished
I run the following script to encode the raw dump to an AVI file.
mencoder <moviename> -ffourcc divx -aid 128 -ni -oac aac -ovc lavc -lavcopts \
vcodec=mpeg4:abitrate=128:vbitrate=<rate>:vhq:vpass=1:vqmin=2:vqmax=31:threads=2 -vf scale=320:240 -ofps <output> <dirname>/<moviename>.avi
mencoder <moviename> -ffourcc divx -aid 128 -ni -oac aac -ovc lavc -lavcopts \
vcodec=mpeg4:abitrate=128:vbitrate=<rate>:vhq:vpass=2:vqmin=2:vqmax=31:threads=2 -vf scale=320:240 -ofps <output> <dirname>/<moviename>.avi
What I would like to do is to have a script that will go through the lsdvd output and set up the script to rip and encode all Titles on the Disk to a directory that I choose.
Any Help would be greatly Appreaciated
joel
dkeav
02-14-2006, 01:10 AM
not as easy as you think, since in all practicality most dvd's have a bunch of usesless titles, and one main title for the movie, however "episode" based dvd's like from a tv-series have the epsiodes split into seperate titles, so having one broad and generic script for both is kind of a pain, its easier to write two scripts, one for movie dvd's and one for multi title dvd's
Vectorman
02-14-2006, 01:15 AM
I'm Sorry. It's been a long day. I meant to specify that I am only working on the TV Series's that I have.
The script doesn't have to be completly Automatic.
it should probly ask me that titles I want to rip. and the names of those titles. Then take that information and create a script that will rip and encode the DVD's
After I get a handle on this I will be creating a script to do the Theatrical Movies. But not yet.
Thank you for the prompt response
joel
je_fro
02-14-2006, 02:00 AM
Unless you have a smp box, take threads=2 out of that script...
DVD's vary widely in their structure, so writing a script, to me, is pointless. I'd do it by hand...
mplayer dvd://1 -chapter 2-2 -dumpstream -dumpfile blah # for title 1 chapter 2 only
or something like that....
Vectorman
02-16-2006, 01:41 PM
Thanks for the advise about the threads=2 command... I'm not running this on a SMP machine.
The reason I wanted a script to automate the ripping and encoding is that I would like the computer to work through the night and have the entire DVD ripped by the time I awake the next morning. Same with while I'm at work. I have A LOT of TV series that I would like to rip and do not want to sit at the computer every hour typeing commands into the computer to rip them.
I think I have a handle on the Script so far. Unfortunatly I'm at work right now so I can't post the script. I will post it up here when I get home.
I do however have a couple more questions.
The Command lsdvd output looks like this
Title: 01, Length: 00:45:11 Chapters: 06, Cells: 06, Audio streams: 02, Subpictures: 00
Does anyone know the SED or AWK syntax to get the time out of it so I can associate it with a variable?
Also je_fro,
in your script you use ask the user to input the time in minutes. Is there a way to use the time gathered from the above sed script and use that for the calculations your script uses?
So far I have the basic script set up to do the TV series but it needs a few modifications and enhancments. I'll post what I have here when I get home.
Thanks for any help and advise.
joel
je_fro
02-16-2006, 02:22 PM
Title: 01, Length: 00:45:11 Chapters: 06, Cells: 06, Audio streams: 02, Subpictures: 00
[/code]
Does anyone know the SED or AWK syntax to get the time out of it so I can associate it with a variable?
Also je_fro,
in your script you use ask the user to input the time in minutes. Is there a way to use the time gathered from the above sed script and use that for the calculations your script uses?
l
If you find a way, be sure to let me know :D
dkeav
02-16-2006, 04:07 PM
btw, i updated my xvid script to have manual title support menc -title 2 for example, no -title option will use the lsdvd output for the largest title
http://dkeav.homeunix.org/menc.sh.txt
Vectorman
02-16-2006, 05:43 PM
I looked into the Time thing a little more. Now I do not have Linux or Bash at work but I'm thinking this will work.
Take a look at this and tell me if it will work
This is the output from lsdvd -t 01
Title: 01, Length: 00:45:11 Chapters: 06, Cells: 06, Audio streams: 02, Subpictures: 00
Here is the script that I believe will remove the time code from the above output and calculate the Number of Seconds.
$hours=$(lsdvd -t 01 | cut -c 20-21)
$minutes=$(lsdvd -t 01 | cut -c 23-24)
$seconds=$(lsdvd -t 01 | cut -c 26-27)
$calctime=$((($hours*3600)+($minutes*60))+($second s))
Thanks for all the help
joel
Vectorman
02-16-2006, 11:50 PM
As promised I am posting the Script that I am working on.
The Portion of the script dealing with TV series works beautifully. Unfortunatly I am having some problem with the Theatrical Movie Portion (the portion of which rips the chapters)
here is the lsdvd output for when I do the Theatrical Movie telling it to break it up into chapters
Title: 01, Length: 00:45:11.266 Chapters: 06, Cells: 06, Audio streams: 02, Subpictures: 00
Chapter: 01, Length: 00:03:36.266, Start Cell: 01
Chapter: 02, Length: 00:10:21.276, Start Cell: 02
Chapter: 03, Length: 00:09:08.076, Start Cell: 03
Chapter: 04, Length: 00:08:43.220, Start Cell: 04
Chapter: 05, Length: 00:12:47.200, Start Cell: 05
Chapter: 06, Length: 00:00:33.286, Start Cell: 06
and here is the error I get
libdvdread: Using libdvdcss version 1.2.5 for DVD access
libdvdread: Using libdvdcss version 1.2.5 for DVD access
./dvdrip: line 165: 08: value too great for base (error token is "08")
I can get it to work for the first two chapters on the title but after that I get the above error.
Any ideas?
joel
Here is the Script that I am useing.
#!/bin/bash
echo "Enter your DVD Device Name"
echo "i.e. /dev/hdc"
echo "DO NOT ENTER THE TRAILING SLASH"
read dvddevice
echo "Is This a TV Series or Theatrical Presentation"
echo "TV Series: Press 1"
echo "Theatrical Presentation: Press 2"
read dvdtype
dumpdir="/media/videos/tv"
echo "DVDType is $dvdtype"
if [ "$dvdtype" = 1 ] ;
then
output="30000/1001"
echo "What is the Name of the Television Series"
echo "DO NOT ENTER SPACES IN THE TITLE"
read tvseriestitle
echo "What is the Season Number is this"
echo "i.e. Season 01"
echo "DO NOT ENTER SPACES IN THE SEASON NUMBER"
read seasonnumber
lsdvd
echo "How Many Episodes Are On This Disk"
echo "Enter A Two Digit Number"
read numberofepisodes
x=0
until [ "$x" -ge "$numberofepisodes" ] ; do
echo "What is the Title Number of the $x Project"
echo "THIS IS A TWO DIGIT NUMBER"
read titlenumber
echo "What is the Episode Number for this Episode"
echo "i.e. Episode 101"
echo "DO NOT ENTER SPACES IN THE EPISODE NUMBER"
read episodenumber
echo "What is the Title Of This Episode"
echo "i.e Episode_101_The_Great_Escape"
echo "DO NOT ENTER SPACES IN THE TITLE"
read episodename
lsdvd -t "$titlenumber"
hours=$(lsdvd -t "$titlenumber" | grep "Title: $titlenumber" | cut -c 20-21)
calchours=$(($hours*3600))
minutes=$(lsdvd -t "$titlenumber" | grep "Title: $titlenumber" | cut -c 23-24)
calcminutes=$(($minutes*60))
seconds=$(lsdvd -t "$titlenumber" | grep "Title: $titlenumber" | cut -c 26-27)
if [ "$hours" = 00 ] ; then
movietime=$(($calcminutes + $seconds))
else
movietime=$(($calchours + $calcminutes + $seconds))
fi
echo "Length of Movie: $hours:$minutes:$seconds"
echo "Enter the approximate output size of the movie in MB"
echo "i.e. 700"
echo "This is the size of the finial file you would like to have"
echo "DO NOT INCLUDE SIZE ABRIEVATIONS MB GB KB ETC"
read moviesize
FINALKBSIZE=$(($moviesize*1000))
SECONDS="$movietime"
AUDIOSIZE=$(($SECONDS*8))
DIFFERENCE=$(($FINALKBSIZE - $AUDIOSIZE))
RATE=$((($DIFFERENCE*8) / $SECONDS))
moviepath="$dumpdir"/"$tvseriestitle"/"$seasonnumber"/"$episodenumber"
if [ ! -d "$moviepath" ] ;
then
mkdir -p "$moviepath"
fi
echo "mplayer dvd://$titlenumber -dvd-device $dvddevice -dumpstream -dumpfile $moviepath/$episodename" >> rip.txt
echo "mencoder $moviepath/$episodename -ffourcc divx -aid 128 -ni -oac copy -ovc lavc -lavcopts \
vcodec=mpeg4:abitrate=128:vbitrate=$RATE:vhq:vpass =1:vqmin=2:vqmax=31 -vf scale=320:240 -ofps $output $movietitle.avi" >> encode.txt
echo "mencoder $moviepath/$episodename -ffourcc divx -aid 128 -ni -oac copy -ovc lavc -lavcopts \
vcodec=mpeg4:abitrate=128:vbitrate=$RATE:vhq:vpass =2:vqmin=2:vqmax=31 -vf scale=320:240 -ofps $output $movietitle.avi" >> encode.txt
echo "mv test.avi $moviepath/$movietitle.avi" >> encode.txt
x=$(expr $x + 1)
sleep 1
done
elif [ "$dvdtype" = 2 ] ; then
output="24000/1001"
echo "Which is the name of the movie you are ripping"
echo "DO NOT ENTER SPACES IN THE TITLE"
read movietitle
lsdvd
echo "Which track would you like to rip"
echo "Enter A Two Digit Number"
read titlenumber
echo "Do you want to rip this movie to a single file"
echo "or break it up by chapters"
echo "For a Single File Press 1"
echo "Too Break It Up Press 2"
read fullchap
if [ "$fullchap" = 1 ] ; then
hours=$(lsdvd -t "$titlenumber" | grep "Title: $titlenumber" | cut -c 20-21)
calchours=$(($hours*3600))
minutes=$(lsdvd -t "$titlenumber" | grep "Title: $titlenumber" | cut -c 23-24)
calcminutes=$(($minutes*60))
seconds=$(lsdvd -t "$titlenumber" | grep "Title: $titlenumber" | cut -c 26-27)
if [ "$hours" = 00 ] ; then
movietime=$(($calcminutes + $seconds))
else
movietime=$(($calchours + $calcminutes + $seconds))
fi
echo "Length of Movie: $hours:$minutes:$seconds"
echo "Enter the approximate output size of the movie in MB"
echo "i.e. 700"
echo "This is the size of the finial file you would like to have"
echo "DO NOT INCLUDE SIZE ABRIEVATIONS MB GB KB ETC"
read moviesize
moviepath="$dumpdir"/"$movietitle"
if [ ! -d "$moviepath" ] ;
then
mkdir -p "$moviepath"
fi
FINALKBSIZE=$(($moviesize*1000))
SECONDS="$movietime"
AUDIOSIZE=$(($SECONDS*8))
DIFFERENCE=$(($FINALKBSIZE - $AUDIOSIZE))
RATE=$((($DIFFERENCE*8) / $SECONDS))
echo "mplayer dvd://$titlenumber -dvd-device $dvddevice -dumpstream -dumpfile $moviepath/$movietitle" >> rip.txt
echo "mencoder $moviepath/$movietitle -ffourcc divx -aid 128 -ni -oac copy -ovc lavc -lavcopts \
vcodec=mpeg4:abitrate=128:vbitrate=$RATE:vhq:vpass =1:vqmin=2:vqmax=31 -vf scale=320:240 -ofps $output $movietitle.avi" >> encode.txt
echo "mencoder $moviepath/$movietitle -ffourcc divx -aid 128 -ni -oac copy -ovc lavc -lavcopts \
vcodec=mpeg4:abitrate=128:vbitrate=$RATE:vhq:vpass =2:vqmin=2:vqmax=31 -vf scale=320:240 -ofps $output $movietitle.avi" >> encode.txt
echo "mv test.avi $moviepath/$movietitle.avi" >> encode.txt
elif [ "$fullchap" = 2 ] ; then
lsdvd -t "$titlenumber" -c
echo "How Many Chapters Are On This Disk"
echo "Enter A Two Digit Number"
read numberofchapters
x=0
until [ "$x" -ge "$numberofchapters" ] ; do
echo "What is the Title Number of the $x Project"
echo "THIS IS A TWO DIGIT NUMBER"
read chapternumber
hours=$(lsdvd -t "$titlenumber" -c | grep "Chapter: $chapternumber" | cut -c 23-24)
calchours=$(($hours*3600))
minutes=$(lsdvd -t "$titlenumber" -c | grep "Chapter: $chapternumber" | cut -c 26-27)
calcminutes=$(($minutes*60))
seconds=$(lsdvd -t "$titlenumber" -c | grep "Chapter: $chapternumber" | cut -c 29-30)
if [ "$hours" = 00 ] ; then
movietime=$(($calcminutes + $seconds))
else
movietime=$(($calchours + $calcminutes + $seconds))
fi
echo "Length of Chapter: $hours:$minutes:$seconds"
echo "Enter the approximate output size of the movie in MB"
echo "i.e. 700"
echo "This is the size of the finial file you would like to have"
echo "DO NOT INCLUDE SIZE ABRIEVATIONS MB GB KB ETC"
read moviesize
moviepath="$dumpdir"/"$movietitle"
if [ ! -d "$moviepath" ] ;
then
mkdir -p "$moviepath"
fi
FINALKBSIZE=$(($moviesize*1000))
SECONDS="$movietime"
AUDIOSIZE=$(($SECONDS*8))
DIFFERENCE=$(($FINALKBSIZE - $AUDIOSIZE))
RATE=$((($DIFFERENCE*8) / $SECONDS))
echo "mplayer dvd://$titlenumber -chapter $chapternumbers-$chapternumber -dvd-device $dvddevice -dumpstream -dumpfile $moviepath/$movietitle/Chapter-$chapternumber" >> rip.txt
echo "mencoder $moviepath/$movietitle/Chapter-$chapternumber -ffourcc divx -aid 128 -ni -oac copy -ovc lavc -lavcopts \
vcodec=mpeg4:abitrate=128:vbitrate=$RATE:vhq:vpass =1:vqmin=2:vqmax=31 -vf scale=320:240 -ofps $output Chapter-$chapternumber.avi" >> encode.txt
echo "mencoder $moviepath/$movietitle/Chapter-$chapternumber -ffourcc divx -aid 128 -ni -oac copy -ovc lavc -lavcopts \
vcodec=mpeg4:abitrate=128:vbitrate=$RATE:vhq:vpass =2:vqmin=2:vqmax=31 -vf scale=320:240 -ofps $output Chapter-$chapternumber.avi" >> encode.txt
echo "mv test.avi $moviepath/$movietitle/Chapter-$chapternumber.avi" >> encode.txt
x=$(expr $x + 1)
sleep 1
done
fi
fi
chmod +x rip.txt && chmod +x encode.txt
#./rip.txt
#./encode.txt
#rm rip.txt && rm encode.txt