Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 06-25-2008, 10:22 AM   #1
LQ Newbie
Registered: Dec 2004
Location: KS
Distribution: Debian, with blackbox. the only way to compute.
Posts: 18

Rep: Reputation: 0
mass dvd conversion, need help and ideas

so we have hundreds of DVD's and are tired of carrying around folders, and hunting through them on shelves ect. im in the process of building a RAID 5 storage system on debian with a couple TB of storage. the problem is (as you might have guessed already) theres no easy way of getting dvd's digitally into this space.

my thoughts so far. its fairly quick to just raw rip the dvd onto the HD so ive started doing that to get 1 step out of the way. what i would like to do is be able to start some type of script or something that will run through and convert all of the raw rips into .AVI with xvid video, MP3 audio. would like them to b 2 pass converted and each complete file to be no bigger then 1.2gb.

ive been doing these one at a time with gui based apps (ogmrip on *nix and clonedvd mobile on windows) and while that works there is a lot of times when i cant sit there and babysit it to get the next one started, also it means i can only get one started before i go to sleep, when if there was some way to script or batch this it could run all night, getting several done.

the main problem here is that i have near zero scripting experience and really dont even know where to begin, i could probably edit a script with my info as needed but the complexity of writing this from scratch is overwhelming, so if anyone is willing to write a base for something like this i would apreciate it greatly. (on *nix only is fine, im in the process of converting my house over to linux only (my wife just doesnt know it yet))

thanx guys.
Old 06-25-2008, 06:19 PM   #2
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
I did this a while ago with around 200 of my DVD's. As you've hinted at, I had the ripping and re-encoding separate. Here's how I did it:
-Use mplayer to dump the raw dvd mpeg data to a file.
-Use mencoder to do the re-encode.

These are the scripts I used. Put them into a ripping directory. To rip, run 'ripdvd NAME_OF_FILM titlenumber'. The main title number is usually 1, so it's the default if you don't supply a number. (You can do the other titles too if you want, just provide a different name, e.g. './ripdvd moviename-track1', './ripdvd moviename-track2' etc.

While you're ripping, start up (in a new terminal) the 'multiencode' script. It doesn't have any arguments. It basically keeps scanning the directory to see if there are any new files to encode. If there are, it does it. Otherwise it goes to sleep for a bit then checks again. I'd run it with a high nice value. You can start up multiple instances of the 'multiencode' script, if you've got multiple cpus or cores. They shouldn't interfere with each other.

Overall, it cut the effective encode time (that which I had to spend in front of the machine) to about 5 minutes per disc.

Okay, first the ripping script, which is dead simple
#Arguments are name and title number (defaults to 1)
if [ $2 ]

echo "Dumping title $title from $basename"
mplayer -dumpstream -dumpfile ${basename}.dump dvd://${title}
touch ${basename}-ready
Now the encoder

#This sets some parameters for the encoding
targetsize=750  # Target size of the final xvid in MB
abitrate=192    # Audio bitrate (It'll come out as 2 channel 


#build up the global filter line here


aid=128 #This is the default audio language (english) to extract.

#This returns the crop values from cropdetect. Args are filename and position (in frames)
function cropparams {
  cropval=$(mplayer -vo null -ao null -vf cropdetect $1 -ss $2 -frames 3 2>&1 \
 | grep 'crop=[0-9]\+:[0-9]\+:[0-9]\+:[0-9]\+' -o \
 | sed -e 's/crop=//' )
  echo $cropval

#This gets a load of crop values and picks the most common (best?) one
#parameters are $1=base name     $2=length of file
function getbestcrop {
cropstep=$(( ${2%.*} / 10 ))

for (( x=0;x<=$length;x+=${cropstep%.*} ))
  cropparams ${1}.dump $x >> ${1}-crops
  uniquecrops=$( cat ${1}-crops | sort | uniq )
  for curcrop in ${uniquecrops}
     curcount=$( grep -c ${curcrop} ${1}-crops )
     if [[ $curcount -gt $bestcount ]] 
rm ${1}-crops
echo $bestcrop

#The main bit of the script. It loops endlessly, looking for new dump files
while [ 1 ]

 #Get list of all FINISHED rips
 for cur in `ls *-ready`

  #Have they been processed already? are they running at the moment?
  if [ -e ${curbase}-xvid.avi -o -e ${curbase}-working ]
    echo " Not processing $curbase "
    echo "Doing ${curbase}"
    touch ${curbase}-working
    vidlength=`midentify "${curbase}.dump" | grep 'ID_LENGTH=' | sed 's/ID_LENGTH=//'`
    cropparams=$(getbestcrop $curbase $vidlength)
    echo "Cropping parameters are $cropparams"

    echo "Current filters are $vfline"

#Calculate the bitrate
    audiosize=$(( $abitrate*1000*${vidlength%.*}/1024/1024/8 ))
    videosize=$(( ($targetsize-$audiosize)*1024 ))

    mencoder "${curbase}.dump" -ovc xvid -xvidencopts \
bitrate=-$videosize:vhq=$vhq:quant_type=h263:pass=1:turbo \
-vf "$vfline" -passlogfile "${curbase}-xvid.log" \
-oac copy -o /dev/null 

    mencoder "${curbase}.dump" -ovc xvid -xvidencopts \
bitrate=-$videosize:vhq=$vhq:quant_type=h263:pass=2 \
-vf "$vfline" -oac mp3lame -lameopts preset=$abitrate \
-aid $aid -passlogfile "${curbase}-xvid.log"  \
-o "${curbase}-xvid.avi"
  #Clean up
    rm ${curbase}-working
    rm ${curbase}-ready
    rm ${curbase}.dump
    rm ${curbase}-xvid.log
echo "Going to sleep, nothing to do"
sleep 10

echo "All done"
I should say that the script is very far from perfect. The 'autocropping' is a bit ugly, but worked for most of my discs. The quality settings are okay, but you can get better (with a longer encode time). Also, you might need a deinterlace filter for some discs (I did).
You'll probably want to tweak some things in it, since it was for backing my dvds up onto a cd so I could watch on my divx player. You might want to change the file size, use a fixed bitrate or whatever. Also, this encodes into xvid, you might want something else.

There's plenty of other encoding scripts around, have a search of this site.
Anyway, it should give you the idea, hope it helps.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
mass video conversion shell script frieza Linux - General 10 05-01-2008 07:33 PM
DVD conversion/compression the1sephiroth Linux - Software 3 05-18-2007 02:59 PM
dvd batch conversion layer1man Linux - Software 1 10-25-2005 09:06 AM
DVD to SVCD conversion with acidrip Cinematography Linux - Software 3 09-11-2005 04:57 AM
Powerpack 10.1 CDs to DVD conversion muneebs Mandriva 2 01-29-2005 06:39 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:28 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration