LinHES Forums
http://forum.linhes.org/

archive DVD to x264 and mkv
http://forum.linhes.org/viewtopic.php?f=24&t=21922
Page 1 of 1

Author:  penguinpwr [ Sun Dec 05, 2010 11:23 pm ]
Post subject:  archive DVD to x264 and mkv

I really enjoyed the DVD Import function but it was becoming old technology. My DVDs were archived in XviD and avi. I prefer x264 and mkv. I was also having issues archiving some of my DVDs with the bad track issues. I tried using dvdbackup but still had problems with the bad track issue. I was able to use vobcopy to make it do what I wanted. Here is what I did and the script I used.

First install make.
sudo pacman -S make
Then download vobcopy from http://vobcopy.org/projects/c/c.shtml
tar -zxvf vobcopy-1.1.2.tar.gz
cd vobcopy-1.1.2
./configure.sh
make
sudo make install

I then coaxed my son to help me write the DVD2mkv.sh script. Two liters of Mountain Dew and two boxes of Oreos later this is what we had.


Code:
#!/bin/bash
#Usage DVD2mkv.sh <MovieName>

# Checks for stupidity
if [[ -z $1 ]]; then
   echo "Please enter the movie name."
   exit;
fi

# Creates temporary directory and moves there
NAME=$1
mkdir /myth/tmp/DVD
cd /myth/tmp/DVD
i=0
ERROR=1

# Copies the main track video and audio file from the DVD
# while checking for bad tracks
while [ $ERROR -ne 0 ]; do
   UNITS="m"     # b=bytes, k=kilobytes, m=megabytes, g=gigabytes
   BADTRACK="${i}${UNITS}"
   /usr/local/bin/vobcopy -f -b ${BADTRACK} -F 64 -l -i /dev/dvd
   ERROR=$?
   rm *.partial 2>/dev/null   # since the vobcopy -x switch doesn't work
   if [ $i -eq 50 ]; then
      echo "Too many bad tracks."
      exit
   fi
   let "i++"
done

# Rename file because vobcopy -t switch doesn't work
OLDNAME=`ls *.vob`
mv "$OLDNAME" "$NAME.vob"

# copies original track 1 audio file
nice -n19 mplayer "$NAME.vob" -aid 128 -dumpaudio -dumpfile "$NAME.ac3"

# Re-encodes the video file to X264
nice -n19 mencoder "$NAME.vob" -passlogfile TWOPASSFILE -ofps 24000/1001 -vf lavcdeint,scale=720:-3 -oac copy -ovc x264 -x264encopts threads=auto:pass=1:turbo=1:subq=1:frameref=1:bframes=3:bitrate=1000 -of rawvideo -o /dev/null
nice -n19 mencoder "$NAME.vob" -passlogfile TWOPASSFILE -ofps 24000/1001 -vf lavcdeint,scale=720:-3 -oac copy -ovc x264 -x264encopts threads=auto:pass=2:subq=5:8x8dct:frameref=3:bframes=3:b_pyramid:weight_b:bitrate=1000 -of rawvideo -o "$NAME.264"
rm "$NAME.vob"
rm TWOPASSFILE

# Moves the re-encoded video file into a mp4 container
MP4Box -add "$NAME.264" -fps 23.976023976 "$NAME.mp4"
rm "$NAME.264"

# Joins the video from the mp4 container with the original audio
mkvmerge -o "$NAME.mkv" -A "$NAME.mp4" "$NAME.ac3"

# Moves the mkv file to the archive folder and deletes the temp folder
mv "$NAME.mkv" "/myth/video/archive/$NAME.mkv"
cd /home/mythtv
rm -R /myth/tmp/DVD


The script seems to work well on my system. It has even archived some of my more difficult DVDs. There are a few things to be careful of if you use it. The first is I'm not a coder. I really don't have a clue. Also the -l switch in vobcopy is for hard drive partitions that support files greater than 4 gig. Make sure you have such a partition. I'm using ext4. This sequence requires a lot of hard drive space. It can use up to 20 gig. Also vobcopy is not fast. I used the -F 64 switch and it helped speed it up but it's not fast. I also ran into troubles getting vobcopy to see my dvd. So I used the -i /dev/dvd switch. It is definitely not the way to do it but it works. That may just be a issue on my machine. The mencoder setting are from brfransen's great script myth2x264. The script works in the /myth/tmp directory and transfers the end product to the /myth/video archive directory. The script I run from the /home/mythtv directory.

My system is a LINHES 6.03 box with a MSI 890 board and a X2 Phenom with all 4 cores unlocked and 2 gig of memory. This scripts runs on it without and issue so far.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/