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. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-12-2006, 06:44 PM
|
#1
|
|
LQ Newbie
Registered: May 2006
Posts: 2
Rep:
|
SCRIPT: Convert & Burn to DVD
I've written a script to convert and burn movies to DVD. Please try it out and post any suggestions / bugs that you have. Also if you see better ways to code what i have, please post a diff and i'll take a look at it.
Thanks,
bukzor
Required packages: ffmpeg, dvdauthor, dvd+rw-tools
Code:
#!/bin/bash
#packages used: ffmpeg, dvdauthor, dvd+rw-tools
#TODO
#somehow do length/size detection and split onto multiple dvd's
#port to VCD, SVCD
#FIXME
#cannot fast-forward through tracks
#Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#run <command>
#runs the command and prints it to stderr
#only prints if $dryrun=true
run(){
echo -n ">> " > /dev/stderr
if ! $dryrun; then
echo "$@" | tee /dev/stderr | sh -
return $?
else
echo "$@"
return 0;
fi
}
cleanup(){
if $cleanup && [ "$cleanuplist" ]; then
echo "# cleaning up..."
run rm -R $cleanuplist
fi
}
#Aspect-Ratio detection~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
getaspect(){
#2.350000 =Panavision (235:100)
#2.063888
#1.777777 =Widescreen (16:9)
#1.555555
#1.333333 =Normal (4:3)
#parses out `height x 10000 / width` from "ffmpeg -i"
#(no decimal numbers in bash)
aspect=`ffmpeg -i "$1" 2>&1 | grep "Stream\ #0.0"`
aspect=`echo "$aspect" | sed "s/.* \([1-9][0-9]*\)x\([0-9]*\).*/\10000 \/ \2/"`
echo ">> $aspect"
aspect=$(( $aspect ))
if [ $aspect -gt 20639 ]; then
#dvdauthor does not understand panavision aspect ratio (2.35)
#we must pad the video into widescreen (16:9)
aspect="16:9";
pana="-s 720x380 -padtop 50 -padbottom 50";
echo "# $1 is Panavision"
elif [ $aspect -lt 15555 ]; then
aspect="4:3"
echo "# $1 is Normal."
else
aspect="16:9"
echo "# $1 is Widescreen"
fi
}
#Encoding~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
encode(){
#TODO do a better checking for DVD format
for avi in "$@"; do
case $avi in
*.DVD.mpg )
echo "# $avi is in DVD format, skipping..."
mpglist="$mpglist \"$avi\"";;
* )
mpg=`echo "$avi" | sed "s/\.[^.]*$//g"`
mpg="$mpg.DVD.mpg"
mpglist="$mpglist \"$mpg\""
if ! [ -f "$mpg" ]; then
echo "# Encoding $mpg..."
if run "ffmpeg -i \"$avi\" -target $standard-dvd -y \
-aspect $aspect $pana $name.temp.DVD.mpg"; then
run "mv $name.temp.DVD.mpg \"$mpg\""
cleanuplist="$cleanuplist \"$mpg\""
else
echo "# ffmpeg ERROR WHILE ENCODING \"$avi\""
exit 1
fi
else
echo "# $avi already encoded! Skipping..."
fi;;
esac
done
echo "# Encoding complete!"
}
#Authoring~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
author(){
if run dvdauthor -o $dvddir -v $standard+$aspect $mpglist; then
cleanup;
cleanuplist="\"$dvddir\""
else
echo "# dvdauthor error"
exit 1;
fi
run dvdauthor -o "$dvddir" -T
}
#ISO creation~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
image(){
if run mkisofs -dvd-video -o $iso $dvddir; then
cleanup
cleanuplist="\"$iso\""
else
echo "# ERROR: mkisofs";
exit 1;
fi
#at this point you can view the iso with:
# mplayer dvd:// -dvd-device name.iso
}
#Burn~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
burn(){
if run growisofs -Z /dev/hdb=$iso -speed=8; then
cleanup
cleanuplist=""
else
echo "# ERROR: growisofs"
exit 1
fi
}
#displays help and exits
showhelp(){
helptext
exit 1
}
helptext(){
echo "Usage: `basename $0` [OPTIONS]... clip1.avi clip2.avi..." ;
echo "Convert each clip to .mpg, author to a folder, convert to .iso image,";
echo "then finally burn to DVD." ;
echo " -n, --name <base> base name for created files (recommended)" ;
echo " -c, --cleanup will cleanup intermediate files" ;
echo " -d, --dryrun will display but not execute commands";
echo " -h, --help show more options" ;
echo "";
echo "Target options:";
echo " -e, --encode only encode the clips.";
echo " -a, --author stop after encoding and authoring the clips";
echo " -i, --image only create a .iso image of a DVD, no burning.";
echo " -b, --burn <iso> only burn the specified image, no processing";
}
morehelptext(){
echo "";
echo "MORE OPTIONS:";
echo " -p, --pal the PAL tv standard will be used (default NTSC)";
echo ""
echo "Aspect options: (automatic aspect detection by default)";
echo " --norm clips will be encoded to normal 4:3";
echo " --wide clips will be encoded to widescreen 16:9";
echo " --pana clips will be encoded to panavision 2.35";
echo "";
echo "Process control options:";
echo " --no-encode - do not create DVD-compatible clips";
echo " --no-author - do not create a DVD-format directory tree"
echo " --no-image - do notcreate ISO image for burning";
echo " --no-burn - disable burning";
}
#Main~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Set defaults
encode="true"
author="true"
image="true"
burn="true"
dryrun="false"
cleanup="false"
standard="ntsc" #TV standard to use
#Option processing
if ! [ "$1" ]; then
showhelp
fi
while [ "$#" -gt 0 ]; do
case $1 in
-h|--help) helptext; morehelptext; exit 0;;
-d|--dryrun ) echo "Doing a dry-run."; dryrun="true"; shift;;
-c|--cleanup ) echo "Will cleanup files."; cleanup="true"; shift;;
-p|--pal ) standard="pal"; shift;;
--norm ) echo "Aspect set to Normal."; aspect="4:3"; shift;;
--wide ) echo "Aspect set to Widescreen."; aspect="16:9"; shift;;
--pana ) echo "Aspect set to Panavision."; aspect="16:9";
pana="-s 720x380 -padtop 50 -padbottom 50"; shift;;
--no-encode ) echo "Encoding disabled."; encode="false"; shift;;
--no-author ) echo "Authoring disabled."; author="false"; shift;;
--no-image ) echo "Imaging disabled."; image="false"; shift;;
--no-burn ) echo "Burning disabled."; burn="false"; shift;;
-e|--encode)
echo "Will only do encoding."
burn="false"; author="false"; image="false"; shift;;
-a|--author)
echo "Will only author DVD to '$name.dvd/'."
burn="false"; image="false"; shift;;
-i|--image)
echo "Will create but not burn '$name.iso'."
burn="false"; shift;;
-b|--burn)
echo "Will only burn $2."
iso="$2"; burn; exit 0 ;;
-n|--name )
echo "Setting base name to '$2'."
name="$2"; dvddir="$name.dvd"; iso="$name.iso"; shift 2;;
-* ) echo "ERROR: option = $1";showhelp;;
* ) break;;
esac
done
shift $(($OPTIND - 1)) #takes the processed options out of $@
#More defaults...
if ! [ "$name" ]; then
#basename for files to be created
#strips non-alphanumeric characters and the extension
name=`echo "$1" | sed -e "s/\.[^.]*$//" -e "s/[^[:alnum:]]/./g"`
dvddir="$name.dvd" #folder to put DVD in
iso="$name.iso" #iso file to be created & burned
fi
#main processing
if $encode; then
if ! [ "$aspect" ]; then
getaspect "$1";
fi
encode "$@"
else
for mpg in "$@"; do
mpglist="$mpglist \"$mpg\""
done
fi
if $author; then
author;
else
cleanuplist=""
fi
if $image; then
image ;
else
cleanuplist=""
fi
if $burn; then
burn;
fi
exit 0
|
|
|
|
05-12-2006, 08:37 PM
|
#2
|
|
Member
Registered: Aug 2003
Distribution: Slackware,Ubuntu
Posts: 389
Rep:
|
is this script can convert any format to DVD?
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 03:38 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|