#!/usr/local/bin/bash # dvd-menu # Copyright 2003-2006 Scott Dylewski # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # name='dvd-menu' version='0.7.5' echo "[dvd-menu] dvd-menu $version" echo "[dvd-menu] Licensed under the GNU GPL" echo "[dvd-menu] Copyright 2003-2006 by Scott Dylewski" echo "[dvd-menu] " ## TODO: # read in variables from ~/.dvd-menurc and local .dvd-menurc ## Known bugs: changes () { echo 'Changes: 0.7.5 Allow embedded .png to keep transparency Fix error message quotes when looking for XML file existing. 0.7.4 no changes 0.7.3 ** Changed output directory option to be the same as dvd-slideshow Spaces in filenames should work now. Checks that xml files exist before proceeding. Added option to pass an embedded image (-e image.jpg). Thanks Marcus Brown Added "upAction" option for use with dvd-bakery. Thanks Marcus Brown! Fixed bug in pal mode variable passing. (thanks Marcus Brown) Changed head 4 to head -n 4 Added variable "mpeg2enc_params" for easier changing of mpeg2enc parameters. Get rid of rpm checks. Added low quality mode -L for use with dvd-slideshow. Added -nocleanup option to save files in temp directory for debugging. Added "-compose src-over" to all composite lines for compatibility with Debian Etch. Added -H high-quality option as a placeholder for future use Added -smp option as a dummy option for compatibility with dvd-slideshow 0.7.2 Better checking for correct versions of required programs. Logfile output to dvd-menu.log Reads default variables from ~/.dvd-slideshowrc Obeys "autocrop" option Pixel aspect ratio should be correct now. 0.7.1 Automatically creates output directory if it does not exist. Added option -nomenu if you do not want to create a menu AC3 is default audio type now. Pass -mp2 if you want to force mp2 audio. 0.7.0 Added option -iso option to create the iso image (requires mkisofs) 0.6.2 Removed -c and -R 2 options from mpeg2enc because some versions do not have those switches. Works with toolame 0.2m now. Got rid of calls to NetPBM functions, so it is no longer required... 0.6.0 Added AC3 audio option (requires ffmpeg > 0.4.8). Mplexed files are now correctly labeled with the .vob extension. Better font searching (thanks Jim Crumley) 0.5.4 No changes. 0.5.2 Fixed audio bug when no audio was used. (re-mplex error) Added -c continuous play option ( jumps to next title). Added -D do not run dvdauthor option. Added -W do not create a 50% white background under menu text. dvdauthor xml structure changed slightly DVD Title (-n) is now optional. Added man page. Checks for nice fonts. 0.5.0 Changed name to "dvd-menu" Only requires lame or oggdec if you are using that file format. Fixed some audio bugs (sampling) so it should work better. Will automatically delete AUDIO_TS and VIDEO_TS directories in your output directory if they already exist. 0.4.6 Fixed bug when checking for toolame (thanks Scott Merrill) Removed -t option from toolame for better compatibility with old versions. 0.4.2 Changed location of main title slightly lower. Fixed one hardcoded 720x480 image so PAL option should work better. Added -depth 8 to ImageMagick calls to fix ppmtoy4m errors. Upgraded main menu background when no background is passed. 0.4 Fixed bug when no background file was passed. Works now. Ogg audio format supported now. Uses toolame for mp2 audio encoding when available. -p (PAL format option) added. Not tested, but should work. Menu button white background is now 50% transparent. 0.3 Added section to check for required programs If no background passed, a black one will be used. 0.2 Initial release' } help () { echo "dvd-menu is part of dvd-slideshow $version" echo "`basename $0`" echo "http://freshmeat.net/dvdslideshow/" echo 'Copyright 2003 Scott Dylewski Usage: dvd-menu -t ... -t -f ... -f [-o output_directory] [-n "menu title"] [-e ] [-L] [-b ] [ -a ] [-p] [-c] [-D] [-W] [-mp2] [-iso] [-nomenu] Description: Creates a simple vmgm menu with buttons that link to the mpeg files in the specified dvdauthor-compatible xml files. Options: -t -t ... -t Name of each title. Each string will be used for the button menu corresponding to each xmlfile. This sets the order of the menu buttons! -f ... Name of each titleset xml file. You can use dvd_slideshow to generate one for each slideshow or you can create your own for a simple mpeg2 file. [-e ] Embed a jpeg image in the middle of the screen. If one image is passed for each button text, That image will be shown as each button is active. [-o ] Directory where the output dvd file system resides [-b ] Image to put in the background of the menu. [-a ] Audio file to use in the background of the menu. The full audio file will keep looping. Supports mp3, ogg, or wav. [-mp2] Use MP2 audio by default. AC3 seems to be more stable in hardware players, but requires ffmpeg. [-n "dvd_title"] This string will be placed on the top of the menu page. [-p] Use PAL format instead of NTSC (untested initial support) [-c] Use continuous method. Each video plays one after another. [-W] Do not generate 50% white background behind menu text. [-L] Use low quality mode for compatibility with the same option in dvd-slideshow. This renders half-resolution menus. [-D] Do not call dvdauthor at the end. Useful when you want to edit your own xml file and pass it to dvdauthor by hand. [-iso] Create iso image with mkisofs when finished. [-nomenu] Do not create a menu. Useful for just finishing the dvdauthor xml file from one video that you want to just start playing when the user puts it into a dvd player. [-nocleanup] Save files in temp directory for debugging. -h or -help Prints this help. Requires: dvdauthor 0.6.11 sox mjpegtools (mp2enc, mpeg2enc, ppmtoy4m) ImageMagick (convert) ' } if [ $# -lt 1 ]; then help exit 1 fi # [-button ' >> "$outdir/vmgm.xml" let m=$m+1 else echo ' ' >> "$outdir/vmgm.xml" fi let i=$i+1 let m=$m+1 done echo ' jump vmgm menu 1; ' >> "$outdir/vmgm.xml" echo ' ' >> "$outdir/vmgm.xml" fi echo ' ' >> "$outdir/vmgm.xml" echo ' ' >> "$outdir/vmgm.xml" echo ' ' >> "$outdir/vmgm.xml" ## now cat the other ones into this file... let i=0 let title=1 let m=1 ## get rid of existing files: check_rm "$tmpdir/menus_vmgm.xml" ## every dvd has at least one title! echo ' ' > "$tmpdir/titles_vmgm.xml" total_files="${#xmlfile[*]}" for it in `seq2 1 1 $total_files` ; do if [ "$(( $i + 1 ))" -eq "$total_files" ] ; then continuous=0 ; fi let j=$i+2 myecho "[dvd-menu] file=${xmlfile[$i]}" suffix=`echo ${xmlfile[$i]} | awk -F. '{print $NF}'` file_base=`basename "${xmlfile[$i]}" .xml` nextmenu=$(( $m + 1 )) lastmenu=$(( $m - 1 )) # myecho "[dvd-menu] file=${xmlfile[$i]} file_base=$file_base suffix=$suffix" if [ "$suffix" == 'xml' ] ; then if [ -f "$file_base"_submenu.xml ] ; then if [ $m -eq 1 ] ; then ## first menu! echo ' ' > "$tmpdir/menus_vmgm.xml" echo ' ' >> "$tmpdir/menus_vmgm.xml" else echo ' ' >> "$tmpdir/menus_vmgm.xml" fi ## read in submenu for this title: cat "$file_base"_submenu.xml | sed -e "s/thetitle/title $title/g" \ | sed -e "s/nextmenu/$nextmenu/" >> "$tmpdir/menus_vmgm.xml" echo ' jump menu '$m'; ' >> "$tmpdir/menus_vmgm.xml" echo ' ' >> "$tmpdir/menus_vmgm.xml" let m=$m+1 nextmenu=$(( $m + 1 )) lastmenu=$(( $m - 1 )) fi # parse in either the chapter select menus or the # browsable slideshow for this title: let n=1 if [ -f "$file_base"_browse.xml ] ; then ## read in browsable slideshow ## read in chapter menu: cat "$file_base"_browse.xml >> "$tmpdir/menus_vmgm.xml" let m=$m+1 nextmenu=$(( $m + 1 )) lastmenu=$(( $m - 1 )) elif [ -f "$file_base"_chap_$n.xml ] ; then ## read in chapter select menu while [ -f "$file_base"_chap_$n.xml ] ; do if [ $m -eq 1 ] ; then ## first menu! echo ' ' > "$tmpdir/menus_vmgm.xml" echo ' ' >> "$tmpdir/menus_vmgm.xml" else echo ' ' >> "$tmpdir/menus_vmgm.xml" fi ## read in chapter menu: cat "$file_base"_chap_$n.xml | sed -e "s/title 1/title $title/g" \ | sed -e "s/nextmenu/$nextmenu/" | sed -e "s/lastmenu/$lastmenu/" >> "$tmpdir/menus_vmgm.xml" echo ' jump menu '$m'; ' >> "$tmpdir/menus_vmgm.xml" echo ' ' >> "$tmpdir/menus_vmgm.xml" let m=$m+1 let n=$n+1 nextmenu=$(( $m + 1 )) lastmenu=$(( $m - 1 )) done fi ## xml file exists: use it! # echo ' ' >> "$tmpdir/titles_vmgm.xml" # echo ' ' >> "$tmpdir/titles_vmgm.xml" echo ' ' >> "$tmpdir/titles_vmgm.xml" cat "${xmlfile[$i]}" >> "$tmpdir/titles_vmgm.xml" if [ "$continuous" -eq 1 ] ; then echo " jump title $j; " >> "$tmpdir/titles_vmgm.xml" elif [ "$no_menu" -eq 0 ] ; then echo ' call vmgm menu 1; ' >> "$tmpdir/titles_vmgm.xml" fi echo ' ' >> "$tmpdir/titles_vmgm.xml" # echo ' ' >> "$tmpdir/titles_vmgm.xml" elif [ "$suffix" == 'mpg' ] || [ "$suffix" == 'vob' ]; then ## assume user already made it vob compatible ## write the title xml: # echo ' ' >> "$tmpdir/titles_vmgm.xml" echo ' ' >> "$tmpdir/titles_vmgm.xml" echo ' ' >> "$tmpdir/titles_vmgm.xml" if [ "$continuous" -eq 1 ] ; then echo " jump title $j; " >> "$tmpdir/titles_vmgm.xml" elif [ "$no_menu" -eq 0 ] ; then echo ' call vmgm menu 1; ' >> "$tmpdir/titles_vmgm.xml" fi echo ' ' >> "$tmpdir/titles_vmgm.xml" # echo ' ' >> "$tmpdir/titles_vmgm.xml" else echo '[dvd-menu] error... filetype not supported!' exit fi let i=$i+1 let title=$title+1 done ## finish up menus tag: if [ $m -gt 1 ] ; then # only if we had submenus: echo ' ' >> "$tmpdir/menus_vmgm.xml" fi ## finish up titles tag: echo ' ' >> "$tmpdir/titles_vmgm.xml" ## join the menus and titles with the vmgm menu: if [ -f "$tmpdir/menus_vmgm.xml" ] ; then # only if submenus exist! cat "$tmpdir/menus_vmgm.xml" >> "$outdir/vmgm.xml" fi cat "$tmpdir/titles_vmgm.xml" >> "$outdir/vmgm.xml" echo '' >> "$outdir/vmgm.xml" echo '' >> "$outdir/vmgm.xml" myecho "[dvd-menu] ##############################" ## run dvdauthor? if [ "$no_dvdauthor" -eq 0 ] ; then myecho "[dvd-menu] Running dvdauthor..." # dvdauthor -o "$dvd_dir" -x "$outdir/vmgm.xml" >> "$logfile" 2>&1 dvdauthor -o "$dvd_dir" -x "$outdir/vmgm.xml" 2>> "$logfile" if [ $? -ne 0 ] ; then ## dvdauthor errored myecho "[dvd-menu] ERROR during dvdauthor execution!" myecho "[dvd-menu] see $logfile for details" exit 1 else myecho "[dvd-menu] dvdauthor ran ok. See logfile for details." fi if [ "$iso" -eq 1 ] ; then ## create iso image afterward: myecho "[dvd-menu] Creating iso image dvd.iso" mkisofs -dvd-video -udf -o dvd.iso "$dvd_dir" if [ $? -ne 0 ] ; then ## mkisofs errored myecho "[dvd-menu] ERROR during mkisofs execution!" myecho "[dvd-menu] see $logfile for details" exit 1 fi fi else myecho "[dvd-menu] Not running dvdauthor. Edit the vmgm.xml file" myecho "[dvd-menu] if you wish, and then run dvdauthor: " myecho "[dvd-menu] dvdauthor -x vmgm.xml" echo " " fi if [ "$nocleanup" -eq 0 ] ; then cleanup fi # cleanup the logfile a little bit: sed -e '/ bytes of data written[[:cntrl:]]INFO/d' "$logfile" > "$outdir"/tmp.txt mv "$outdir"/tmp.txt "$logfile" echo "[dvd-menu] Output directory is $outdir" echo "[dvd-menu] Logfile output is at $logfile" echo "[dvd-menu] The dvd filesystem is $dvd_dir" echo "[dvd-menu] " echo "[dvd-menu] You can play this video using one of the following commands:" echo "[dvd-menu] xine -g -u 0 dvd:\"$dvd_dir\"" echo "[dvd-menu] " echo "[dvd-menu] or, if you just want to watch the videos without the menus:" echo "[dvd-menu] mplayer -sid 0 dvd:// -dvd-device $dvd_dir" myecho "[dvd-menu] Done!" echo exit 0