mass video conversion shell script

hopper

Member
Messages
225
Reaction score
0
Points
16
this is a shell script i did that takes a range of sequentially numbered videos (numbered "_#") and converts them to avi format then DVD mpeg2 using mencoder and ffmpeg, even generates the .xml file for dvdauthor, then masters the dvd with DVDauthor and even burns the dvd, all you have to do is run it with the first file and the last file as arguments

Code:
#initialize the variable to increment for the jump statement in the xml file
let y=1
#remove the old xml file
rm -f ../mpgs/naruto.xml
#generate the static part at the begining of the xml file
echo "<dvdauthor dest=\"DVD\">" > ../mpgs/naruto.xml
echo "    <vmgm />" >> ../mpgs/naruto.xml
echo "    <titleset>" >> ../mpgs/naruto.xml
echo "        <titles>" >> ../mpgs/naruto.xml
echo "            <video aspect=\"16:9\" format=\"ntsc\" widescreen=\"nopanscan\" />" >> ../mpgs/naruto.xml
#set the upper bounds for the jump statement to one higher then the number of the last title
a=$1
b=$2
let c=$b-$a
let z=$c+2 
#repeat from the first number until the second in sequence
for ((x=$1;x<=$2;x++))
do
#increment the jump variable
let y=$y+1
#if on the last title set it to jump to title 1 (loop the dvd)
if [ \"$y\" = \"$z\" ]
then 
let y=1
fi
#convert from divx to standard avi then remove the divx
mencoder -ovc lavc -oac lavc *_$x* -o episode$x.avi
rm -f *_$x*
#convert from avi to mpeg2 for dvd then remove the avi
ffmpeg -i episode$x.avi -target dvd ../mpgs/episode$x.mpg
rm -f episode$x.avi
#generate the title part of the xml file
echo "            <pgc>" >> ../mpgs/naruto.xml
echo "            <vob file=\"episode$x.mpg\" chapters=\"0,5:00,10:00,15:00,20:00,25:00\"/>" >> ../mpgs/naruto.xml
echo "                <post> jump title $y; </post>" >> ../mpgs/naruto.xml
echo "            </pgc>" >> ../mpgs/naruto.xml
done
#add the closing tags to the divx
echo "        </titles>" >> ../mpgs/naruto.xml
echo "    </titleset>" >> ../mpgs/naruto.xml
echo "</dvdauthor>" >> ../mpgs/naruto.xml
#switch to the mpgs directory
cd ../mpgs
#generate the raw DVD image from the mpgs
dvdauthor -x naruto.xml
#burn the dvd
growisofs -Z /dev/dvd -dvd-video DVD/
#clean up
rm -rf *.mpg
rm -rf DVD
edit: note the rm -f commands in the script are optional i just put them in there because of lack of space on my harddrive, but if you leave them in make sure you are working on a COPY of the original because otherwise youll lose the original wether it worked or not
 
Last edited:
Top