LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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

Reply
 
Search this Thread
Old 05-12-2006, 06:44 PM   #1
bukzor
LQ Newbie
 
Registered: May 2006
Posts: 2

Rep: Reputation: 0
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
 
Old 05-12-2006, 08:37 PM   #2
xgreen
Member
 
Registered: Aug 2003
Distribution: Slackware,Ubuntu
Posts: 389

Rep: Reputation: 30
is this script can convert any format to DVD?
 
Old 05-13-2006, 01:24 AM   #3
bukzor
LQ Newbie
 
Registered: May 2006
Posts: 2

Original Poster
Rep: Reputation: 0
It will work with any format accepted by ffmpeg, which is most:

http://ffmpeg.sourceforge.net/ffmpeg-doc.html#SEC19

Last edited by bukzor; 05-13-2006 at 01:37 AM.
 
  


Reply

Tags
avi, burn, convert, dvd


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
convert & burn on the fly sharadshankar Linux - Software 1 01-27-2006 12:39 AM
Convert small dvd or cd files into to a single layer dvd? suse91pro General 0 09-27-2005 05:12 PM
Permission Denied to burn/erase DVD RW with DVD+RW tools themystic Linux - Hardware 2 08-30-2005 11:32 AM
How to burn the downloaded Fedora 3 DVD ISO onto DVD yaabaa Linux - Newbie 10 03-14-2005 05:14 AM
Dual Boot, RH Burn to DVD, & DWL-520+ VanZero Linux - General 3 03-13-2004 09:47 AM


All times are GMT -5. The time now is 06:49 AM.

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