Debian Codegraph @

dvd-menu

raw ◀ ▶
2 Debian patches touch this file
1 #!/bin/bash
2 # dvd-menu
3 # Copyright 2003-2008 Scott Dylewski <scott at dylewski.com>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #
19
20 name='dvd-menu'
21 version='0.8.6-1'
22
23 echo "[dvd-menu] dvd-menu $version"
24 echo "[dvd-menu] Licensed under the GNU GPL"
25 echo "[dvd-menu] Copyright 2003-2015 by Scott Dylewski"
26 echo "[dvd-menu] "
27
28 ## TODO:
29 # read in variables from ~/.dvd-menurc and local .dvd-menurc
30 # relative paths in xine output suggestion
31
32 ## Known bugs:
33
34 ## set up bash variables
35 LANG="POSIX"
36
37 changes ()
38 {
39 echo 'Changes:
40 0.8.6
41 Need to fix sox errors for newer versions, "warning Option -s depreciated"
42 Change ac3 encoding to ac3_fixed in ffmpeg to avoid core dump
43 0.8.4
44 Fix sox arguments to work with both old and new versions of sox.
45 Added "unset CDPATH to full_path function. (Thanks Bob!)
46 Add explicit PAL or NTSC in .xml files for dvdauthor 0.7.0
47 Add totem and VLC playback examples
48 0.8.2
49 Change imagemagick calls with -type TrueColor to -type TrueColorMatte for latest version
50 Sox v. > 13 changes -w to -2 and -e to -n (thanks Ludovic)
51 Font path follows links. Thanks Jim Potter!
52 AC3 audio created with ffmpeg needs k added to bitrate
53 Changed -depth 16 to -depth 8 in background gradient creation.
54 Fix embedded image help text.
55 Default layout will switch to two columns of buttons (no embedded image) if the button
56 list is long.
57 Change LANG=C to LANG=POSIX to try to fix radix problems with printf
58 Add menu fix so "dvd menu" button works on dvd players (thanks will guaraldi)
59 0.8.0
60 pre9:
61 Added 6image layout option. It can also read the title and icon from
62 the .xml file output from dvd-slideshow. more testing is needed.
63 Added many more variables to control the layout of the menu also.
64 pre8:
65 Added -vcd and -svcd modes. Works! tested -vcd a little.
66 Audio automatically fades in/out for 2 seconds
67 Reads variables correctly from ~/.dvd-slideshow/dvd-slideshowrc
68 Updated variables. See dvd-slideshowrc example file
69 Better control of fonts and variables.
70 Deletes temp directory when finished.
71 -nocleanup works
72 Reads -theme files
73 Added -fadein and -fadeout for menus.
74 Remove seq calls for compatibility with FreeBSD (Thanks David Mulcahy)
75 Remove wc --chars calls for compatibility with FreeBSD
76 0.2 Initial release'
77 }
78
79 help ()
80 {
81 echo "dvd-menu is part of dvd-slideshow $version"
82 echo "`basename $0`"
83 echo "http://freshmeat.net/dvdslideshow/"
84 echo 'Copyright 2003 Scott Dylewski <scott at dylewski.com>
85
86 Usage:
87 dvd-menu -t <titleset1> ... -t <titlesetN>
88 -f <xmlfile1> ... -f <xmlfileN> [-o output_directory]
89 [-n "menu title"] [-e <embed image>] [-L]
90 [-b <background jpeg>] [ -a <menu audio file> ] [-p]
91 [-c] [-D] [-W] [-mp2] [-iso] [-w] [-theme <themefile>] [-nomenu]
92
93 Description:
94 Creates a simple vmgm menu with buttons that
95 link to the mpeg files in the specified
96 dvdauthor-compatible xml files.
97
98 Options:
99 -t <titleset1> -t <titleset2> ... -t <titlesetN>
100 Name of each title. Each string will be used for
101 the button menu corresponding to each xmlfile.
102 This sets the order of the menu buttons!
103
104 -f <xmlfile1> <xmlfile2> ...
105 Name of each titleset xml file. You can use
106 dvd_slideshow to generate one for each slideshow
107 or you can create your own for a simple mpeg2
108 file.
109
110 [-o <output directory>]
111 Directory where the output dvd file system resides
112
113 [-n "dvd_title"]
114 This string will be placed on the top of the
115 menu page.
116
117 [-b <background jpeg>]
118 Image to put in the background of the menu.
119
120 [-e <embedded image>]
121 Embed a jpeg image in the middle of the screen.
122 The image shows up as a thumnail to the left of the
123 menu buttons.
124 Only one image is allowed.
125
126 [-a <audiofile>]
127 Audio file to use in the background of the
128 menu. The full audio file will keep looping.
129 Supports mp3, ogg, or wav.
130
131 [-mp2]
132 Use MP2 audio by default. AC3 seems to be more stable
133 in hardware players, but requires ffmpeg.
134
135 [-p]
136 Use PAL format instead of NTSC (untested initial support)
137
138 [-c]
139 Use continuous method. Each video plays one after another.
140
141 [-W]
142 Do not generate 50% white background behind menu text.
143
144 [-w]
145 Use widescreen mode (16:9) instead of default 4:3 aspect ratio.
146
147 [-L]
148 Use low quality mode for compatibility with the same option
149 in dvd-slideshow. This renders half-resolution menus.
150
151 [-D]
152 Do not call dvdauthor at the end. Useful when you want
153 to edit your own xml file and pass it to dvdauthor by hand.
154
155 [-theme themename]
156 Use the given theme when setting variables/colors/etc. Themes are
157 installed in /opt/dvd-slideshow/themes or in a local directory
158 ~/.dvd-slideshow/themes
159
160 [-vcd]|[-svcd] [ALPHA!]
161 Create vcd .cue and .bin files (requires vcdimager)
162
163 [-iso]
•164 Create iso image with genisoimage when finished.
165
166 [-nomenu]
167 Do not create a menu. Useful for just finishing the
168 dvdauthor xml file from one video that you want to just
169 start playing when the user puts it into a dvd player.
170
171 [-nocleanup]
172 Save files in temp directory for debugging.
173
174 -h or -help
175 Prints this help.
176
177 -v or -version
178 Prints this help.
179
180 Requires:
181 dvdauthor 0.6.11
182 sox >= 14.0.0
183 mjpegtools (mp2enc, mpeg2enc, ppmtoy4m)
184 ImageMagick (convert)
185 ffmpeg
186
187 Variables:
188 dvd-menu will read the following variables out of your ~/.dvd-slideshow/dvd-slideshowrc file.
189 The default values are shown
190
191 menu_bg_color='steelblue' # imagemagick colors or a hex #rrggbb value.
192 menu_title_font_size=40
193 menu_title_white_height=125
194 menu_title_location_x=80
195 menu_title_location_y=50
196 menu_panel_height=28 # height of each button. Default is slightly bigger than font size
197 menu_panel_width=400 # goes all the way to the right of the screen
198 menu_panel_location_x=420
199 menu_panel_location_y=175 # distance of the top of the first menu item to the top of the screen
200 menu_button_font_size=21
201 menu_title_justify=left
202 mpeg_encodr='ffmpeg' # or mpeg2enc
203 '
204 }
205
206 if [ $# -lt 1 ]; then
207 help
208 exit 1
209 fi
210
211 # [-button <button image.jpg>]
212 # Use image.jpg for a highlight image button.
213 # The text from -t <titleset> will be placed underneath.
214 # Pass one -b <image.jpg> for each titleset xml file.
215 #
216
217
218 ##################################################################
219 ## Functions:
220
221 myecho ()
222 {
223 ## use this version of echo to write to screen and to the logfile:
224 echo "$*"
225 echo "$*" >> "$logfile"
226 }
227
228 logecho ()
229 {
230 ## use this version of echo to write to the logfile:
231 echo "$*" >> "$logfile"
232 }
233
234 myechon ()
235 {
236 ## use this version of echo to write to screen and to the logfile:
237 echo -n "$*"
238 echo -n "$*" >> "$logfile"
239 }
240
241
242 #check_rm () # check_rm checks to see if the file exists before it's deleted:
243 #{
244 # if [ -f "${1}" ] ; then
245 # rm "${1}"
246 # fi
247 #}
248
249 cleanup ()
250 {
251 if [ "$nocleanup" -eq 0 ] ; then
252 ## clean up temporary files
253 myecho "[dvd-menu] cleanup..."
254 rm -f "$tmpdir/slideshow_background.ppm"
255 # rm -f "$tmpdir/silence.mp2"
256 rm -f "$tmpdir/title_background_mask.png"
257 rm -f "$tmpdir/button_background_mask.png"
258 rm -f "$tmpdir/button_text.png"
259 rm -f "$tmpdir/button_mask.png"
260 rm -f "$tmpdir/button_mask_trans.png"
261 rm -f "$tmpdir/menu.ppm"
262 rm -f "$tmpdir/fadein.mpg"
263 rm -f "$tmpdir/bg_fade.ppm"
264 rm -f "$tmpdir/fadeout.mpg"
265 rm -f "$tmpdir/menu.mpg"
266 rm -f "$tmpdir/menu.spumux"
267 rm -f "$tmpdir/menu_mask.png"
268 rm -f "$tmpdir/menu_t.vob"
269 rm -f "$tmpdir/menu_audio.wav"
270 rm -f "$tmpdir/fade_audio.wav"
271 rm -f "$tmpdir/fade_audio.ac3"
272 rm -f "$tmpdir/fade_audio.mp2"
273 rm -f "$tmpdir/audio.mp2"
274 rm -f "$tmpdir/audio.wav"
275 rm -f "$tmpdir/audio.ac3"
276 rm -f "$tmpdir/embed.jpg"
277 rm -f "$tmpdir/dvd_title.png"
278 rm -f "$tmpdir/titles_vmgm.xml"
279 rm -f "$tmpdir/embed.png"
280 rm -f "$tmpdir/black.ppm"
281 [ -f "$tmpdir"/fade_0001.ppm ] && rm "$tmpdir"/fade_*.ppm
282 k=0
283 dk=0
284 for file in "${title[@]}"; do
285 [ $k -lt 10 ] && dk="0$k" || dk=$k
286 # echo "k=$k dk=$dk"
287 rm -f "$tmpdir"/title_"$dk"_mask.png
288 rm -f "$tmpdir"/title_"$k"_mask.png
289 rm -f "$tmpdir/title_$dk.ppm"
290 rm -f "$tmpdir/title_$k.ppm"
291 let k=$k+1
292 done
293 rmdir "$tmpdir"
294 fi
295 }
296
297 forcequit () ## function gets run when we have some sort of forcequit...
298 {
299 ## clean up temporary files
300 cleanup
301 exit 1
302 }
303
304 trap 'forcequit' INT
305 trap 'forcequit' KILL
306 trap 'forcequit' TERM
307
308 ## check for the necessary programs:
309 checkforprog ()
310 {
311 it=`which $1`
312 if [ -z "$it" ] ; then
313 myecho "[dvd-menu] ERROR: $1 not found! "
314 myecho "[dvd-menu] Check the dependencies and make sure everything is installed."
315 exit 1
316 fi
317 }
318
319 rpmversion ()
320 ## don't use this since most machines don't have rpm!
321 {
322 if [ -z `which rpm 2> /dev/null` ] ; then
323 ver=''
324 else
325 ver=`rpm -q $1`
326 fi
327 if [ `echo $ver | awk -F- '{print $1}'` == "$1" ] ; then
328 # rpm returned version of program
329 version=`echo $ver | awk -F- '{print $2}'`
330 # myecho "[dvd-menu] Found $1 version $version"
331 else
332 # no rpm, try other methods
333 version=0 # no version found (yet)
334 # myecho "[dvd-menu] Found $1"
335 fi
336 echo "$version" # returns 0 if no version found, but executable exists
337 }
338
339 hms ()
340 {
341 ## pass a number in hundreths of seconds and get back a
342 ## time code of the form HR:MM:SS:HU
343 hours=$(( $1 / 360000 ))
344 it=$(( $1 - $hours * 360000 ))
345 minutes=$(( $it / 6000 ))
346 it=$(( $1 - $minutes * 6000 ))
347 seconds=$(( $it / 100 ))
348 hundreths=$(( $it - $seconds * 100 ))
349 it="$hours:$minutes:$seconds.$hundreths"
350 echo "${it}"
351 }
352
353 white_title_mask ()
354 {
355 convert -size "$dvd_width"x600 -quality 100 xc:transparent -depth 8 -fill white -draw "Rectangle 0,0,$dvd_width,$title_white_height" -background none -blur 0x4 -crop $resolution-0-0 "$1"
356 }
357
358 white_button_mask ()
359 {
360 # white_button_mask outfile
361 # convert -size "$dvd_width"x$menuh -quality 100 xc:transparent -depth 8 -fill white -draw "roundRectangle $menu_panel_location_x,$menu_panel_location_y,$menuright,$menubottom $radius,$radius" -draw "Rectangle 0,0,$dvd_width,$title_white_height" -crop $resolution-0-0 "$1"
362 convert -size "$dvd_width"x$menuh -quality 100 xc:transparent -depth 8 -fill white -draw "roundRectangle $menu_panel_location_x,$menu_panel_location_y,$menuright,$menubottom $radius,$radius" -background none -blur 0x4 -crop $resolution-0-0 "$1"
363 }
364
365 title_text ()
366 {
367 # title_text outfile
368 echo "[dvd-menu] Creating title: $dvd_title"
369 [ "$title_justify" == 'left' ] && title_justify=NorthWest
370 [ "$title_justify" == 'right' ] && title_justify=NorthEast
371 [ "$title_justify" == 'center' ] && title_justify=North
372 echo "[dvd-menu] title justified $title_justify"
373 convert -depth 8 -size $resolution xc:transparent -fill "$title_font_color" -pointsize $title_font_size -gravity $title_justify -font "$title_font" -draw "text $title_location_x,$title_location_y \"${dvd_title}\"" "$1"
374 }
375
376 imagewidth () # IMAGEWIDTH
377 {
378 it="`identify -format %w "$1"`"
379 it="$(( $it * $sq_pixel_multiplier / 1000 ))"
380 echo "$it"
381 }
382
383 imagewidth_sq () # IMAGEWIDTH_SQ
384 {
385 it="`identify -format %w "$1"`"
386 echo "$it"
387 }
388
389
390 imageheight ()
391 {
392 it="`identify -format %h "$1"`"
393 echo "$it"
394 }
395
396
397 checkforautocrop ()
398 {
399 if [ "$autocrop" == 1 ] ; then
400 # figure out whether to autocrop the image or not
401 image_width=`imagewidth "$1"`
402 image_height=`imageheight "$1"`
403 ratio="$(( 100* $image_width / $image_height ))"
404 out_ratio="$(( 100* $dvd_width / $dvd_height ))"
405 do_autocrop_w=0 ; do_autocrop_h=0
406 if [ "$ratio" -lt "$(( $out_ratio ))" ] ; then
407 do_autocrop_h=1 # image too wide, crop height
408 elif [ "$ratio" -gt "$(( $out_ratio ))" ] ; then
409 do_autocrop_w=1 # image too tall, crop width
410 fi
411 [ $debug -ge 2 ] && myecho "[dvd-menu:checkforautocrop] image_width=$image_width image_height=$image_height ratio=$ratio out_ratio=$out_ratio"
412 [ $debug -ge 2 ] && myecho "[dvd-menu:checkforautocrop] do_autocrop_w=$do_autocrop_w do_autocrop_h=$do_autocrop_h"
413 else
414 do_autocrop_h=0 ; do_autocrop_w=0
415 fi
416 }
417
418 background ()
419 {
420 ## input is: $1 = effect/image
421 # output is written to "$tmpdir"/slideshow_background.ppm
422 bg="$1"
423 if [ -z "$2" ] ; then
424 local outfile_bg="$tmpdir"/slideshow_background.ppm
425 else
426 local outfile_bg="$2"
427 fi
428 if [ -f "$bg" ] ; then # if effect is a background file
429 myecho "[dvd-menu] Creating background image $( truncate_filename "$bg")"
430 checkforautocrop "$bg"
431 if [ "$do_autocrop_w" -eq 1 ]; then
432 # autocrop background image width (width too large)
433 convert "${bg}" -resize "$sq_to_dvd_pixels" -resize x"$dvd_height" \
434 -gravity center -crop "$dvd_width"x"$dvd_height"'+0!+0!' -type TrueColorMatte -depth 8 "$outfile_bg"
435 elif [ "$do_autocrop_h" -eq 1 ]; then
436 # autocrop background image height (height too large)
437 convert "${bg}" -resize "$sq_to_dvd_pixels" -resize "$dvd_width"x \
438 -gravity center -crop "$dvd_width"x"$dvd_height"'+0!+0!' -type TrueColorMatte -depth 8 "$outfile_bg"
439 else
440 echo "no autocrop background"
441 #don't autorop
442 convert "${bg}" -resize "$sq_to_dvd_pixels" -resize x"$dvd_height" -bordercolor black -border "$dvd_width"x240 \
443 -gravity center -crop "$dvd_width"x"$dvd_height"'+0!+0!' -type TrueColorMatte -depth 8 "$outfile_bg"
444 fi
445 bgfile="$bg"
446 elif [ "$bg" == 'black' ] ; then # I guess we could add other types of backgrounds here!
447 ## use plain black background with no picture
448 myecho "[dvd-menu] Creating black background"
449 convert -size "$dvd_width"'x'"$dvd_height" xc:black -type TrueColorMatte -depth 8 "$outfile_bg"
450 bgfile="black"
451 elif [ "$bg" == 'white' ] ; then # I guess we could add other types of backgrounds here!
452 ## use plain white background with no picture
453 myecho "[dvd-menu] Creating white background"
454 convert -size "$dvd_width"'x'"$dvd_height" xc:white -type TrueColorMatte -depth 8 "$outfile_bg"
455 bgfile="white"
456 elif [ "${bg:0:1}" == '#' ] ; then # user passed a #RRGGBB hex color
457 myecho "[dvd-menu] Creating $bg color background"
458 convert -size "$dvd_width"'x'"$dvd_height" xc:"$bg" -type TrueColorMatte -depth 8 "$outfile_bg"
459 bgfile="hex"
460 fi
461 }
462
463 set_variables ()
464 {
465 ## check for config variables:
466 config1=`echo "$1" | cut -d= -f1 | tr -d [:blank:]`
467 # config2=`echo "$1" | awk -F' #' '{print $2}' | cut -d= -f2 | tr -d '\047' | tr -d '\042' | tr -d [:blank:]`
468 config2=`echo "$1" | tr '\t' ' ' | cut -d= -f2 | awk -F' #' '{print $1}' | tr -d '\047' | tr -d '\042'`
469 [ -n "$2" -a "$2" == 1 ] && noecho=1 || noecho=0
470 ## check for global configuration variables:
471 case "$config1" in
472 debug) debug="$config2" ; [ "$noecho" -eq 0 ] && echo "debug=$debug" ;;
473 pal) pal="$config2" ; [ "$noecho" -eq 0 ] && echo "pal=$pal" ;;
474 ac3) ac3="$config2" ; [ "$noecho" -eq 0 ] && echo "ac3=$ac3" ;;
475 mpeg_encoder) mpeg_encoder="$config2" ; [ "$noecho" -eq 0 ] && echo "mpeg_encoder=$mpeg_encoder" ;;
476 # menus always autocrop? autocrop) autocrop="$config2" ; [ "$noecho" -eq 0 ] && echo "autocrop=$autocrop" ;;
477 font) font="$config2" ; [ "$noecho" -eq 0 ] && echo "font=$font" ;; #global font
478 menu_font) font="$config2" ; [ "$noecho" -eq 0 ] && echo "font=$font" ;; #global font
479 # title
480 menu_background) bgfile="$config2" ; [ "$noecho" -eq 0 ] && echo "bgfile=$bgfile" ;;
481 menu_bg_color) bg_color="$config2" ; [ "$noecho" -eq 0 ] && echo "bg_color=$bg_color" ;;
482 menu_panel_height) panel_height="$config2" ; [ "$noecho" -eq 0 ] && echo "panel_height=$panel_height" ;;
483 menu_panel_width) panel_width="$config2" ; [ "$noecho" -eq 0 ] && echo "panel_width=$panel_width" ;;
484 menu_panel_location_x) menu_panel_location_x="$config2" ; [ "$noecho" -eq 0 ] && echo "menu_panel_location_x=$menu_panel_location_x" ;;
485 menu_panel_location_y) menu_panel_location_y="$config2" ; [ "$noecho" -eq 0 ] && echo "menu_panel_location_y=$menu_panel_location_y" ;;
486 menu_button_font) button_font="$config2" ; [ "$noecho" -eq 0 ] && echo "button_font=$button_font" ;;
487 menu_button_font_size) button_font_size="$config2" ; [ "$noecho" -eq 0 ] && echo "button_font_size=$button_font_size" ;;
488 menu_button_font_color) button_font_color="$config2" ; [ "$noecho" -eq 0 ] && echo "button_font_color=$button_font_color" ;;
489 menu_button_hilight_color) button_hilight_color="$config2" ; [ "$noecho" -eq 0 ] && echo "button_hilight_color=$button_hilight_color" ;;
490 menu_title_font) title_font="$config2" ; [ "$noecho" -eq 0 ] && echo "title_font=$title_font" ;;
491 menu_title_font_size) title_font_size="$config2" ; [ "$noecho" -eq 0 ] && echo "title_font_size=$title_font_size" ;;
492 menu_title_font_color) title_font_color="$config2" ; [ "$noecho" -eq 0 ] && echo "title_font_color=$title_font_color" ;;
493 menu_title_white_height) title_white_height="$config2" ; [ "$noecho" -eq 0 ] && echo "title_white_height=$title_white_height" ;;
494 menu_title_location_x) title_location_x="$config2" ; [ "$noecho" -eq 0 ] && echo "title_location_x=$title_location_x" ;;
495 menu_title_location_y) title_location_y="$config2" ; [ "$noecho" -eq 0 ] && echo "title_location_y=$title_location_y" ;;
496 menu_title_justify) title_justify="$config2" ; [ "$noecho" -eq 0 ] && echo "title_justify=$title_justify" ;;
497 theme) theme="$config2" ; [ "$noecho" -eq 0 ] && echo "theme=$theme" ;;
498 theme_designed_for) theme_designed_for="$config2" ; [ "$noecho" -eq 0 ] && echo "theme_designed_for=$theme_designed_for" ;;
499 menu_type) menu_type="$config2" ; [ "$noecho" -eq 0 ] && echo "menu_type=$menu_type" ;;
500 menu_audio) audiofile="$config2" ; [ "$noecho" -eq 0 ] && echo "audiofile=$audiofile" ;;
501 menu_continuous_play) continuous="$config2"; continuous_method="$config2" ; [ "$noecho" -eq 0 ] && echo "continuous=$continuous" ;;
502 menu_fadein) fadein="$config2" ; [ "$noecho" -eq 0 ] && echo "menu_fadein=$menu_fadein" ;;
503 menu_fadeout) fadeout="$config2" ; [ "$noecho" -eq 0 ] && echo "menu_fadeout=$menu_fadeout" ;;
504 menu_fade_to_image) fade_to_image="$config2" ; [ "$noecho" -eq 0 ] && echo "fade_to_image=$fade_to_image" ;;
505 menu_panel_mask) panel_mask="$config2" ; [ "$noecho" -eq 0 ] && echo "panel_mask=$panel_mask" ;;
506
507
508 esac
509 }
510
511 set_theme ()
512 {
513 ## check for config variables: only specified once per menu
514 config=`echo "$1" | cut -d= -f1 | tr -d [:blank:]`
515 config2=`echo "$1" | tr '\t' ' ' | tr -d '\047' | tr -d '\042' | cut -d= -f2 | awk -F' #' '{print $1}' | tr -d [:blank:]`
516 # config2=`echo "$1" | cut -d= -f2 | awk -F' #' '{print $1}' | tr -d [:blank:]`
517 [ -n "$2" -a "$2" == 1 ] && local noecho=1 || local noecho=0
518 ## check for global configuration variables:
519 case "$config" in
520 theme) theme="$config2" ; [ "$noecho" -eq 0 ] && echo "$theme" ;; #global font
521 esac
522 }
523
524
525 read_theme ()
526 # read_theme $theme
527 {
528 local theme=$1
529 [ -n "$2" -a "$2" == 1 ] && local noecho=1 || local noecho=0
530 ## read in theme file if it exists:
531 if [ -n "$theme" ] ; then
532 # check if directory
533 if [ -d "$theme" ] ; then
534 themedir="$theme"
535 themefile="`ls -1 "$theme"/*.theme 2> /dev/null | tail -n 1`"
536 [ "$noecho" == '0' ] && myecho "[dvd-menu] Using theme file to $(truncate_filename "$themefile")"
537 elif [ -f "$theme" ] ; then
538 themefile="`full_path "$theme"`"
539 themedir="`dirname "$theme"`"
540 [ "$noecho" == '0' ] && myecho "[dvd-menu] Using theme file to $(truncate_filename "$themefile")"
541 [ "$noecho" == '0' ] && myecho "[dvd-menu] Using theme file $theme"
542 else
543 # check in default theme directory:
544 if [ -d "$themedir"/"$theme" ] ; then
545 themedir="$themedir"/"$theme"
546 themefile="`ls -1 "$themedir"/*.theme 2> /dev/null | tail -n 1`"
547 [ "$noecho" == '0' ] && myecho "[dvd-menu] Using theme file to $(truncate_filename "$themefile")"
548 # check in local theme directory:
549 elif [ -d "$local_themedir"/"$theme" ] ; then
550 themedir="$local_themedir"/"$theme"
551 themefile="`ls -1 "$themedir"/*.theme 2> /dev/null | tail -n 1`"
552 [ "$noecho" == '0' ] && myecho "[dvd-menu] Using theme file to $(truncate_filename "$themefile")"
553 else
554 [ "$noecho" == '0' ] && myecho "[dvd-menu] ERROR! Bad theme name (not found)"
555 exit 1
556 fi
557 fi
558 [ "$noecho" == '0' ] && myecho "[dvd-menu] Reading theme file..."
559 while read thisline
560 do
561 set_variables "${thisline}" 1
562 it=`set_variables "${thisline}" 0`
563 if [ -n "$it" ] ; then
564 [ "$noecho" == '0' ] && myecho "[dvd-menu] Set variable $it"
565 fi
566 done < "$themefile"
567 ## now, fix paths to background files and such if they were local paths:
568 if [ -n "$bgfile" ] ; then
569 if [ ! -f "$bgfile" ] ; then
570 bgfile2="$themedir"/"$bgfile"
571 if [ -f "$bgfile2" ] ; then
572 bgfile="$bgfile2"
573 else
574 # try hex color.
575 if [ "${bgfile:0:1}" == '#' ] ; then # user passed a #RRGGBB hex color
576 bgfile="$bgfile"
577 else
578 echo "[dvd-menu] Error: bad background filename in theme."
579 echo "[dvd-menu] Using default background instead."
580 bgfile=''
581 fi
582 fi
583 fi
584 fi
585 if [ -n "$fade_to_image" ] ; then
586 # add color option
587 if [ ! -f "$fade_to_image" ] ; then
588 fade_to_image="$themedir"/"$fade_to_image"
589 if [ ! -f "$fade_to_image" ] ; then
590 echo "Error: bad fade_to_image filename in theme."
591 fi
592 fi
593 fi
594 if [ -n "$audiofile" ] ; then
595 if [ ! -f "$audiofile" ] ; then
596 audiofile="$themedir"/"$audiofile"
597 if [ ! -f "$audiofile" ] ; then
598 echo "Error: bad audio filename in theme"
599 audiofile=''
600 fi
601 fi
602 fi
603 if [ -n "$font" ] ; then
604 if [ ! -f "$font" ] ; then
605 font="$themedir"/"$font"
606 if [ ! -f "$font" ] ; then
607 echo "Error: bad font filename in theme"
608 fi
609 fi
610 fi
611 if [ -n "$button_font" ] ; then
612 if [ ! -f "$button_font" ] ; then
613 button_font="$themedir"/"$button_font"
614 if [ ! -f "$button_font" ] ; then
615 echo "Error: bad button_font filename in theme"
616 fi
617 fi
618 fi
619 if [ -n "$title_font" ] ; then
620 if [ ! -f "$title_font" ] ; then
621 title_font="$themedir"/"$title_font"
622 if [ ! -f "$title_font" ] ; then
623 echo "Error: bad title_font filename in theme"
624 fi
625 fi
626 fi
627 fi
628 }
629
630 full_path () # from Shea Martin, modified by scott dylewski
631 {
632 unset CDPATH
633 if [ -f "$1" ]; then
634 DIR="$(dirname "$1")"
635 DIR=$(cd "$DIR" && pwd)
636 FILE="$(basename $1)"
637 RSLT=$?
638 echo "$DIR/$FILE"
639 return $RSLT
640
641 elif [ -d "$1" ]; then
642 DIR="$1"
643 FILE="$( cd "$DIR" && pwd)"
644 RSLT=$?
645 echo "$FILE"
646 return $RSLT
647 else
648 echo "unknown file: $1"
649 return 1
650 fi
651 }
652
653 function fade ()
654 # fade image1.jpg image2.jpg duration[s]
655 {
656 local image1="$1"
657 local image2="$2"
658 local duration="$3" # in seconds
659 local frames="$(( $frames_per_sec * $(seconds2ms $duration) / 1000 / 1000 ))"
660 # echo frames="$frames duration=$duration"
661 # for fr in `seq 1 1 $frames`; do # fade from buttons to background
662 for (( fr=1 ; fr<=frames ; fr++ )) ; do
663 dj=`addzeros $fr`
664 percent=$(( 100 * $fr / $frames ))
665 (composite -compose src-over -gravity center -type TrueColorMatte -depth 8 -dissolve $percent "$image1" "$image2" "$tmpdir/fade_$dj.ppm" )
666 done
667 if [ "$mpeg_encoder" == 'mpeg2enc' ] ; then
668 find "$tmpdir" -name "fade*.ppm" -type f -print0 | sort -z -d | xargs -0 cat | ppmtoy4m -v 0 -n 0 -S "$subsample" -F $ppmtoy4m_frc -A $ppmtoy4m_aspect -I p | mpeg2enc $mpeg2enc_params -o "$tmpdir/fade.mpg" >> "$logfile" 2>&1
669 else
670 find "$tmpdir" -name "fade*.ppm" -type f -print0 | sort -z -d | xargs -0 cat | ppmtoy4m -v 0 -n 0 -S "$subsample" -F $ppmtoy4m_frc -A $ppmtoy4m_aspect -I p | ffmpeg -f yuv4mpegpipe -i - -target $ffmpeg_target -r $framerate -an -aspect $aspect_ratio -s "$dvd_width"x"$dvd_height" -y -f mpeg2video "$tmpdir/fade.mpg" >> "$logfile" 2>&1
671 fi
672 find "$tmpdir" -name "fade*.ppm" -type f -print0 | xargs -0 rm
673 }
674
675 function seconds2ms ()
676 {
677 ## break up the duration into the integer seconds and ms:
678 out_duration=`echo $1 | awk '{ print $1 * 1000 }'`
679 echo "$out_duration"
680 }
681
682 addzeros ()
683 {
684 [ $1 -lt 1000 ] && dj2="0$1" || dj2=$1
685 [ $1 -lt 100 ] && dj2="00$1" || dj2=$dj2
686 [ $1 -lt 10 ] && dj2="000$1" || dj2=$dj2
687 echo "$dj2"
688 }
689
690
691 hms ()
692 {
693 ## pass a number in thousandths of seconds and get back a
694 ## time code of the form HR:MM:SS.XXX
695 if [ -z "$1" ] ; then
696 myecho "[dvd-slideshow] Error in hms function"
697 function_error=1
698 else
699 hours=$(( $1 / 3600000 )) ; [ $hours -eq 0 ] && hours="0"
700 it=$(( $1 - $hours * 3600000 ))
701 minutes=$(( $it / 60000 )) ; [ $minutes -eq 0 ] && minutes="0"
702 it=$(( $1 - $minutes * 60000 ))
703 seconds=$(( $it / 1000 )) ; [ $seconds -eq 0 ] && seconds="0"
704 thousandths_out=$( printf %3.3d $(( $it - $seconds * 1000 )) );
705 it="$hours:$minutes:$seconds.$thousandths_out"
706 echo "${it}"
707 fi
708 }
709
710 wavlength ()
711 # wavlength $file
712 # returns song length in ms
713 {
714 sox "$1" $sox_nop stat 2> "$tmpdir"/trash.txt
715 song_length=`cat "$tmpdir"/trash.txt | grep 'Length (seconds):' | awk -F: '{print $2}' | tr -d [:blank:]`
716 song_length_seconds=`echo $song_length | awk -F. '{print $1}'`
717 if [ -z "$song_length_seconds" ] ; then song_length_seconds=0 ; fi
718 song_length_ms=`echo $song_length | awk -F. '{printf ("%3.3f",$0)}' | awk -F. '{print $2}'`
719 ## make sure we have two decimal places?
720 if [ -z "$song_length_ms" ] ; then song_length_ms=0 ; fi
721 song_length=$( echo "scale=0; 1000 * $song_length_seconds + $song_length_ms" | bc )
722 rm "$tmpdir"/trash.txt
723 echo "$song_length"
724 }
725
726 truncate_filename ()
727 {
728 # truncate filenames so they're not longer than 40 characters:
729 local length="${#1}"
730 if [ $length -gt 40 ] ; then
731 local pos=$(( $length - 40 ))
732 echo "...${1:$pos}"
733 else
734 echo "$1"
735 fi
736 }
737
738
739 ########################################### end of functions
740
741
742 ###################################################################
743 # Default variables
744 # order of perference:
745 # program defaults --> ~/.dvd-slideshow/dvd-slideshowrc command-line options --> .txtfile settings
746
747 ## setup program default variables (user configurable)
748 debug=0 # 1 or 0
749 pal=0
750 continuous=0 ; continuous_method=0
751 no_dvdauthor=0
752 ac3=1
753 mpeg_encoder='ffmpeg' # or 'mpeg2enc'
754 iso=0
755 no_menu=0
756 autocrop=1
757 upAction=0
758 nocleanup=0
759 subtitle_code="EN"
760
761 # define some possible fonts:
762 font_dir="/usr/share/fonts/"
763 default_font1='n019004l.pfb' # helvetica bold URW fonts
764 default_font2='helb____.ttf' # helvetica bold truetype
765
766 ## other cool colors: cadetblue cornflowerblue midnightblue
767 bg_color='steelblue' # imagemagick colors
768 # panel_width=400
769 panel_width=''
770 panel_height='' # will be set later from the button_font_size
771 button_font_size=21
772 button_font_color="black"
773 button_hilight_color="red"
774 menu_panel_location_x=420
775 menu_panel_location_y=175 # distance of the top of the first menu item to the top of the screen
776 title_font_size=40
777 title_font_color="black"
778 title_white_height=125
779 radius=20
780 button_radius=10
781 title_location_x=80
782 title_location_y=50
783 title_justify=NorthWest
784
785 hilight_spacing_x=50
786 hilight_spacing_y=50
787 hilight_font_size=12
788
789 embed_image_width=260
790 embed_image_height=240
791
792 menu_type='textbar'
793 panel_mask=1
794
795 frames=20 # number of frames in the menu mpg file.
796 # I guess this only really needs to be 1 frame
797 # but 30 is easier to debug so we can play it.
798 ## don't forget that the audio is fixed at 1 second!
799
800 # soon to be user configurable:
801 logfilename='dvd-menu.log'
802 low_quality=0
803 high_quality=0
804 vcd=0 ; svcd=0
805 widescreen=0
806 themedir='/opt/dvd-slideshow/themes' # LSB/FHS compliant: see http://www.pathname.com/fhs/pub/fhs-2.3.html#OPTADDONAPPLICATIONSOFTWAREPACKAGES
807 local_themedir=~/.dvd-slideshow/themes # local theme directory
808 fadein=0
809 fadeout=0
810 fade_to_image=''
811
812 # end of default variables
813
814 #####################################################################
815 # read command-line options:
816
817 let n=0
818 let m=0
819 let q=0
820 let p=0
821 for arg
822 do
823 case "$arg" in
824 ## config variables:
825 -p) shift; commandline_pal=1 ;;
826 -ac3) shift; commandline_ac3=1 ;; # use ac3 audio
827 -mp2) shift; commandline_ac3=0 ;; # use mp2 audio
828 ## not config variables:
829 -t) shift ; title[$n]="${1}"; let n=$n+1; shift ;; # each title
830 -f) shift ; xmlfile[$m]="$1"; let m=$m+1; shift ;; # each titleset
831 -e) shift ; embedfile[$p]="${1}"; let p=$p+1; shift ;; # the menu hilight images
832 -button) shift ; buttonfile[$q]="${1}"; let q=$q+1; shift ;; # each button hilight images
833 -u) shift; upAction="1" ;;
834 # -action) shift; Action="1" ;; # do manual button navigation later
835 -o) shift; outdir="${1%%/}"; shift ;; # dvd directory
836 -b) shift; commandline_bgfile="$1"; shift ;; # background jpeg
837 -theme) shift; commandline_theme="$1"; shift ;; #
838 -n) shift; dvd_title="$1"; shift ;; # name of DVD disk
839 -c) shift; continuous=1 ; continuous_method=1 ;;
840 -D) shift; no_dvdauthor=1 ;;
841 # -W) shift; no_white=1 ;;
•842 -w) shift; widescreen=1 ;; # not supported in dvdauthor
843 -L) shift; low_quality=1 ;;
844 -H) shift; high_quality=1 ;; # not used yet...
845 -M) shift; high_quality=0 ; low_quality=0 ;; # Force normal quality
846 -vcd) shift; vcd=1 ;; # not used yet...
847 -svcd) shift; svcd=1 ;; # not used yet...
848 -fadein) shift; commandline_fadein=1 ;; # not used yet...
849 -fadeout) shift; commandline_fadeout=1 ;; # not used yet...
850 -smp) shift ;; # not used yet...
851 -nomenu) shift; no_menu=1 ;;
852 -nocleanup) shift; nocleanup=1 ;;
853 -a) shift; audiofile="$1"; shift;; # audio file playing during menu
854 -iso) shift; iso=1 ;; # make iso image when finished
855 -h) help ; exit 0 ; shift ;;
856 -help) help ; exit 0 ; shift ;;
857 -\?) help ; exit 0 ; shift ;;
858 -v) echo "$version" ; exit 0 ; shift ;;
859 -version) echo "$version" ; exit 0 ; shift ;;
860 esac
861 done
862
863 # verify output directory exists:
864 if [ -z "$outdir" ] ; then
865 if [ -w "`pwd`" ] ; then
866 echo "[dvd-menu] Output directory not specified."
867 echo "[dvd-menu] Using `pwd`"
868 outdir="`pwd`"
869 else
870 echo '[dvd-menu] ERROR: Output directory not specified.'
871 exit 1
872 fi
873 else # specified output directory. make sure it exists:
874 mkdir -p "$outdir"
875 outdir="$( full_path "$outdir" )"
876 echo "[dvd-menu] Using output directory $outdir"
877 fi
878
879 ## dvdbaker doesn't use or need the autual xml or vob files!
880 #if [ -z "$xmlfile" ] && [ -n "$1" ] ; then
881 # echo "using xml file $1".
882 # xmlfile="$1"
883 # if [ -z "$xmlfile" ] ; then
884 # echo "[dvd-menu] ERROR: No xml file passed."
885 # echo "[dvd-menu] use -f <filename> to pass a .xml, .vob, or .mpg file"
886 # exit 1
887 # fi
888 #fi
889
890 #for it in "${xmlfile[@]}"; do
891 # # verify xml file exists:
892 # echo "xmlfile=$it"
893 # if [ -n "$it" ] && [ ! -r "$it" ] ; then
894 # echo "[dvd-menu] ERROR: XML file $it does not exist."
895 # exit 1
896 # fi
897 #done
898
899 # verify that the number of buttons (-t) is equal to the number of files (-f)
900 #echo "xmlfiles=${#xmlfile[@]}"
901 #echo "xmlfiles=${xmlfile[@]}"
902 #if [ "${#xmlfile[@]}" -ge 1 ] ; then
903 # if [ ${#xmlfile[@]} -ne ${#title[@]} ] ; then
904 # echo "[dvd-menu] ERROR: The number of buttons does not match the number of files!"
905 # echo "[dvd-menu] buttons=${title[@]}"
906 # echo "[dvd-menu] files=${xmlfile[@]}"
907 # exit 1
908 # fi
909 #fi
910
911 tmpdir="$outdir"/"dvd-menu_temp_$$"
912 if [ ! -d "$tmpdir" ] ; then
913 mkdir -p "$tmpdir"
914 fi
915 dvd_dir="$outdir"/"dvd_fs"
916 if [ -d "$dvd_dir" ] ; then
917 ## output directory already exists. Delete old files
918 # echo "[dvd-menu] Output directory already exists. "
919 echo "[dvd-menu] Deleting existing AUDIO_TS and VIDEO_TS directories..."
920 if [ -d "$dvd_dir/AUDIO_TS" ] ; then rm -r "$dvd_dir/AUDIO_TS" ; fi
921 if [ -d "$dvd_dir/VIDEO_TS" ] ; then rm -r "$dvd_dir/VIDEO_TS" ; fi
922 else
923 mkdir -p "$dvd_dir"
924 fi
925
926 ## initialize log file:
927 logfile="$outdir"/"$logfilename"
928 echo "[dvd-menu] `date`" > "$logfile"
929 echo "[dvd-menu] dvd-menu version $version" >> "$logfile"
930 echo "[dvd-menu] `uname -a`" >> "$logfile"
931 echo "[dvd-menu] Output directory=$outdir" >> "$logfile"
932
933 #############################################################
934 ## Now, read in the ~/.dvd-slideshow/dvd-slideshowrc file if it exists:
935 if [ -f "${HOME}/.dvd-slideshow/dvd-slideshowrc" ] ; then
936 echo "[dvd-menu] Reading default variables in ${HOME}/.dvd-slideshow/dvd-slideshowrc"
937 total_lines=`wc -l "${HOME}/.dvd-slideshow/dvd-slideshowrc" | awk '{print $1}'` total_lines=$(( $total_lines + 1 ))
938 line=1
939 while [ $line -ne $total_lines -a $total_lines -ne 0 ];
940 do
941 thisline=`sed -n "$line"p "${HOME}/.dvd-slideshow/dvd-slideshowrc"`
942 set_variables "${thisline}" 1
943 it=`set_variables "${thisline}" 0`
944 if [ -n "$it" ] ; then
945 myecho "[dvd-menu] Set variable $it"
946 fi
947 line=$(( $line + 1 ))
948 done
949 fi
950
951
952 ################################################################
953 ## Now, set the variables that were passed on the command-line:
954 [ -n "$commandline_pal" ] && pal=$commandline_pal
955 [ -n "$commandline_autocrop" ] && autocrop=$commandline_autocrop
956 [ -n "$commandline_ac3" ] && ac3=$commandline_ac3
957 [ -n "$commandline_debug" ] && debug=$commandline_debug
958 [ -n "$commandline_theme" ] && theme=$commandline_theme
959 [ -n "$commandline_fadein" ] && fadein=$commandline_fadein
960 [ -n "$commandline_fadeout" ] && fadeout=$commandline_fadeout
961 if [ -n "$commandline_bgfile" ] ; then
962 if [ -f "$commandline_bgfile" ] ; then
963 bgfile="$(full_path "$commandline_bgfile")"
964 else
965 bgfile="$commandline_bgfile"
966 myecho "[dvd-menu] WARNING: $bgfile is not a known file"
967 myecho "[dvd-menu] WARNING: If you pass a color on the command-line,"
968 myecho "[dvd-menu] WARNING: you'd better know what you're doing"
969 ## must be a color or not exist?
970 fi
971 fi
972
973 ## now, read the theme file if it was passed on the commandline:
974 if [ -n "$theme" ] && [ "$theme" != 'default' ] ; then
975 read_theme "$theme" 0
976 fi
977
978 # button_text_location=$(( $panel_height/2 + $button_font_size/2 ))
979 menu_button_location_y=$(( $menu_panel_location_y + $button_font_size/2 )) # y-location of first button
980
981 if [ "$panel_mask" == "none" ] ; then
982 no_white=1
983 elif [ "$panel_mask" == "default" ] ; then
984 no_white=0
985 else
986 no_white=0 # this will change later to allow specific panel masks...
987 fi
988
989 if [ "$vcd" -eq 1 ] ; then
990 # setup audio parameters
991 ac3=0
992 audio_bitrate=224
993 audio_sample_rate=44100
994 mplex_type=1
995 ffmpeg_target='vcd'
996 elif [ "$svcd" -eq 1 ] ; then
997 # setup audio parameters
998 ac3=0
999 audio_bitrate=224
1000 audio_sample_rate=44100
1001 mplex_type=4
1002 ffmpeg_target='svcd'
1003 else
1004 audio_bitrate=128
1005 audio_sample_rate=48000
1006 mplex_type=8
1007 ffmpeg_target='dvd'
1008 fi
1009
1010 if [ "$pal" -eq 1 ] ; then
1011 framerate='25'
1012 frames_per_sec=25000 # in ms
1013 sq_pixel_multiplier=$(( 1000 * 540 / 576 ))
1014 ppmtoy4m_frc='25:1'
1015 ppmtoy4m_aspect='59:54'
1016 if [ "$low_quality" -eq 1 ] || [ "$vcd" -eq 1 ] ; then
1017 dvd_width='352' ; dvd_height='288'
1018 resolution='352x288'
1019 elif [ "$svcd" -eq 1 ] ; then
1020 dvd_width='480' ; dvd_height='576'
1021 resolution='480x576'
1022 elif [ "$high_quality" -eq 1 ] ; then
1023 dvd_width='720' ; dvd_height='576'
1024 resolution='720x576'
1025 else
1026 dvd_width='720' ; dvd_height='576'
1027 resolution='720x576'
1028 fi
1029 else ## NTSC
1030 framerate='29.97'
1031 frames_per_sec=29970 # in ms
1032 sq_pixel_multiplier=$(( 1000 * 540 / 480 ))
1033 ppmtoy4m_frc='30000:1001'
1034 ppmtoy4m_aspect='10:11'
1035 if [ "$low_quality" -eq 1 ] || [ "$vcd" -eq 1 ] ; then
1036 dvd_width='352' ; dvd_height='240'
1037 resolution='352x240'
1038 elif [ "$svcd" -eq 1 ] ; then
1039 dvd_width='480' ; dvd_height='480'
1040 resolution='480x480'
1041 elif [ "$high_quality" -eq 1 ] ; then
1042 dvd_width='720' ; dvd_height='480'
1043 resolution='720x480'
1044 else
1045 dvd_width='720' ; dvd_height='480'
1046 resolution='720x480'
1047 fi
1048 fi
1049
1050 if [ -z "$panel_width" ] ; then
1051 panel_width="$(( $dvd_width - $menu_panel_location_x ))"
1052 logecho "menu_panel_location_x=$menu_panel_location_x"
1053 logecho "panel_width=$panel_width"
1054 fi
1055 if [ -z "$panel_height" ] ; then
1056 panel_height="$(( $button_font_size * 125 / 100 +2 ))" # 25% larger than fontsize
1057 fi
1058
1059 #######################################################3
1060 # Summarize settings:
1061 myecho "[dvd-menu] Final dvd filesystem is in $dvd_dir"
1062 [ "$pal" -eq 1 ] && ntsc_or_pal="PAL" || ntsc_or_pal="NTSC"
1063 [ -n "$VIDEO_FORMAT" ] && original_video_format="$VIDEO_FORMAT" || original_video_format=''
1064 export VIDEO_FORMAT="$ntsc_or_pal"
1065 [ "$ac3" -eq 1 ] && mp2_or_ac3="AC3" || mp2_or_ac3="MP2"
1066 [ "$vcd" -eq 1 ] && myecho "[dvd-menu] Using VCD mode."
1067 [ "$svcd" -eq 1 ] && myecho "[dvd-menu] Using SVCD mode."
1068 myecho "[dvd-menu] Video: $ntsc_or_pal $resolution $framerate $aspect_ratio"
1069 myecho "[dvd-menu] Audio: $mp2_or_ac3 $audio_bitrate $audio_sample_rate"
1070 [ "$debug" -gt 0 ] && myecho "[dvd-menu] Debug=$debug"
1071 if [ "$nocleanup" == 1 ] ; then
1072 myecho "[dvd-menu] Leaving all temporary files in temp directory"
1073 myecho "[dvd-menu] Temporary directory is $tmpdir"
1074 fi
1075 myecho "[dvd-menu] buttons=${#title[@]}"
1076 #echo "[dvd-menu] audio files=$audiofile"
1077 #echo "[dvd-menu] menu titles:"
1078 #echo "[dvd-menu] ${title[@]}"
1079
1080 if [ -z "${title[0]}" ] ; then # arrays start at index 0
1081 # no titles passed! assume user wants no menu
1082 no_menu=1
1083 echo "[dvd-menu] WARNING: No button titles passed! Not creating menu."
1084 fi
1085
1086 #############################################################
1087
1088 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then
1089 aspect_ratio="4:3"
1090 mpeg2enc_params="-v 0 -a 2 -4 2 -2 1 -b 1150 -n n -s -f $mplex_type"
1091 elif [ "$widescreen" -eq 1 ] ; then
1092 aspect_ratio="16:9"
1093 mpeg2enc_params="-v 0 -a 3 -q 4 -4 2 -2 1 -s -M 0 -f $mplex_type -E -N -R 2"
1094 else
1095 aspect_ratio="4:3"
1096 # mpeg2enc_params="-v 0 -a 2 -q 4 -4 2 -2 1 -s -M 0 -f $mplex_type"
1097 mpeg2enc_params="-v 0 -a 2 -q 4 -4 2 -2 1 -s -M 0 -f $mplex_type -E -N -R 2"
1098 fi
1099
1100 #resize_factor=`awk -vw=$dvd_width -vh=$dvd_height -var=$aspect_ratio 'BEGIN{if (ar=="4:3"){ar=4/3} else {ar=16/9};printf "%0.2f", (100/((h/w)*(ar)));exit;}'`
1101 resize_factor=`awk -vw=$dvd_width -vh=$dvd_height -var=$aspect_ratio 'BEGIN{if (ar=="4:3"){ar=4/3} else {ar=16/9};printf "%0.2f", (100/((h/w)*(ar)));exit;}' | sed 's/,/\./g'`
1102 sq_to_dvd_pixels="${resize_factor}x100%"
1103
1104 hilight_height=$(( ( $dvd_height - $hilight_spacing_y -$title_location_y - $title_font_size - 2*$hilight_spacing_y - 2*$hilight_font_size)/2 ))
1105 hilight_width=$(( $hilight_height * $dvd_width / $dvd_height )) # assume this aspect ratio.
1106 hilight_start_location_x=$(( ($dvd_width - 3*$hilight_width - 2*$hilight_spacing_x )/2 ))
1107 hilight_start_location_y=$(( $title_location_y + $title_font_size + $hilight_spacing_y ))
1108
1109 if [ "$low_quality" -eq 1 ] || [ "$vcd" -eq 1 ] ; then
1110 panel_height=$(( $panel_height / 2 ))
1111 panel_width=$(( $panel_width / 2 ))
1112 button_font_size=$(( $button_font_size / 2 ))
1113 # button_text_location=$(( $panel_height/2 + $button_font_size/2 ))
1114 menu_panel_location_x=$(( $menu_panel_location_x / 2 ))
1115 menu_panel_location_y=$(( $menu_panel_location_y / 2 ))
1116 menu_button_location_y=$(( $menu_button_location_y / 2 ))
1117 title_font_size=$(( $title_font_size / 2 ))
1118 title_white_height=$(( $title_white_height / 2 ))
1119 radius=$(( $radius / 2 ))
1120 button_radius=$(( $button_radius / 2 ))
1121 title_location_x=$(( $title_location_x / 2 ))
1122 title_location_y=$(( title_location_y / 2 ))
1123
1124 embed_image_width=$(( $embed_image_width / 2 ))
1125 embed_image_height=$(( $embed_image_height / 2 ))
1126
1127 hilight_spacing_x=$(( $hilight_spacing_x / 2 ))
1128 hilight_spacing_y=$(( $hilight_spacing_y / 2 ))
1129 hilight_font_size=$(( $hilight_font_size / 2 ))
1130 fi
1131
1132 ############################################################3
1133 ## Check for required programs
1134
1135 # ppmtoy4m
1136 it=`which ppmtoy4m 2> /dev/null`
1137 if [ -z "$it" ] ; then # no ppmtoy4m
1138 myecho "[dvd-menu] ERROR: no mjpegtools found for audio processing"
1139 myecho "[dvd-menu] You need to download and install mjpegtools."
1140 myecho "[dvd-menu] http://mjpegtools.sourceforge.net"
1141 cleanup ; exit 0
1142 fi
1143 progver=`mplex 2>&1 | grep version | awk '{ print $4 }'`
1144 logecho "[dvd-menu] Found mjpegtools version $progver"
1145 if ppmtoy4m -S 420mpeg2 xxxxx 2>&1 | grep -q xxxxx; then
1146 logecho "[dvd-menu] Using mjpegtools subsampling -S 420mpeg2"
1147 subsample='420mpeg2'
1148 else
1149 logecho "[dvd-menu] Using mjpegtools subsampling -S 420_mpeg2"
1150 subsample='420_mpeg2'
1151 fi
1152
1153 # sox
1154 it=`which sox 2> /dev/null`
1155 if [ -z "$it" ] ; then # no sox
1156 myecho "[dvd-menu] ERROR: no sox found for audio processing"
1157 myecho "[dvd-menu] You need to download and install sox."
1158 myecho "[dvd-menu] http://sox.sourceforge.net"
1159 cleanup ; exit 0
1160 fi
1161 progver=`sox -h 2>&1 | head -n 1 | awk '{ print $3 }'`
1162 logecho "[dvd-menu] Found sox version $progver"
1163 progver1="$( echo ${progver#v} | awk -F. '{print $1}' )"
1164 if [ $progver1 -lt 14 ] ; then # use old sox commands:
1165 sox_word='-w'
1166 sox_nop='-e'
1167 sox_int='-s' # signed integer
1168 soxi=0
1169 else # use new commands ( > 14.0.0 )
1170 # sox_word='-2' # depreciated
1171 sox_word='-b 16'
1172 sox_int='-e signed-integer'
1173 sox_nop='-n'
1174 soxi=1
1175 fi
1176 logecho "[dvd-menu] using sox options $sox_word $sox_int $sox_nop"
1177
1178 # ImageMagick
1179 it=`which convert 2> /dev/null`
1180 if [ -z "$it" ] ; then # no convert
1181 myecho "[dvd-menu] ERROR: no ImageMagick found for audio processing"
1182 myecho "[dvd-menu] You need to download and install ImageMagick."
1183 myecho "[dvd-menu] http://ImageMagick.sourceforge.net"
1184 cleanup ; exit 0
1185 fi
1186 progver=`convert -help | head -n 1 | awk '{ print $3 }'`
1187 logecho "[dvd-menu] Found ImageMagick version $progver"
1188
1189 # dvdauthor
1190 it=`which dvdauthor 2> /dev/null`
1191 if [ -z "$it" ] ; then # no dvdauthor
1192 myecho "[dvd-menu] ERROR: no dvdauthor found for audio processing"
1193 myecho "[dvd-menu] You need to download and install dvdauthor."
1194 myecho "[dvd-menu] http://dvdauthor.sourceforge.net"
1195 cleanup ; exit 0
1196 fi
1197 progver=`dvdauthor -h 2>&1 | head -n 1 | awk '{ print $3 }'`
1198 logecho "[dvd-menu] Found dvdauthor version $progver"
1199
1200
1201 # ffmpeg
1202 it=`which ffmpeg 2> /dev/null`
1203 if [ -z "$it" ] ; then
1204 # no ffmpeg! use mp2 audio instead:
1205 myecho "[dvd-menu] Warning: no ffmpeg found for AC3 audio encoding."
1206 myecho "[dvd-menu] Using MP2 audio instead."
1207 myecho "[dvd-menu] MP2 audio is less compatible with DVD player hardware."
1208 myecho "[dvd-menu] http://ffmpeg.sourceforge.net"
1209 ac3=0
1210 mpeg_encoder='mpeg2enc'
1211 else
1212 # found ffmpeg
1213 logecho "`ffmpeg -version 2>&1`"
1214 ## check to see if we have mpeg2video output option:
1215 it=`ffmpeg -f mpeg2video 2>&1 | grep 'Unknown input or output format: mpeg2video'`
1216 if [ -z "$it" ] ; then
1217 # mpeg2video should be ok
1218 [ "$mpeg_encoder" == 'ffmpeg' ] && mpeg_encoder='ffmpeg'
1219 else
1220 [ "$mpeg_encoder" == 'ffmpeg' ] && mpeg_encoder='mpeg2enc'
1221 myecho "[dvd-menu] Warning: ffmpeg is not compiled with the mpeg2video option"
1222 myecho "[dvd-menu] required for making dvds! Using mpeg2enc instead."
1223 mpeg_encoder='mpeg2enc'
1224 fi
1225 fi
1226
1227 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then
1228 checkforprog vcdimager
1229 ac3=0; mp2=1
1230 fi
1231
•1232 # genisoimage
1233 checkforprog genisoimage
1234
1235 ################################################## done finding programs
1236
1237 #Find the fonts
1238 default_font1=`find -L $font_dir -name $default_font1 | head -n 1`
1239 default_font2=`find -L $font_dir -name $default_font2 | head -n 1`
1240
1241 # verify fonts exist:
1242 if [ -f "$default_font1" ] ; then
1243 default_font="$default_font1"
1244 elif [ -f "$default_font2" ] ; then
1245 default_font="$default_font2"
1246 else
1247 echo "[dvd-menu] Cannot find required fonts. Using default ImageMagick font."
1248 default_font=""
1249 fi
1250 if [ -z "$font" ] ; then # global font
1251 font="$default_font"
1252 else
1253 if [ -f "$font" ] ; then
1254 font="$font"
1255 else
1256 font="$default_font"
1257 fi
1258 fi
1259 if [ -z "$title_font" ] ; then
1260 title_font="$font"
1261 else
1262 if [ -f "$title_font" ] ; then
1263 title_font="$title_font"
1264 else
1265 title_font="$font"
1266 fi
1267 fi
1268 if [ -z "$button_font" ] ; then
1269 button_font="$font"
1270 else
1271 if [ -f "$button_font" ] ; then
1272 button_font="$button_font"
1273 else
1274 button_font="$default_font"
1275 fi
1276 fi
1277
1278 logecho "[dvd-menu] title_font=$title_font"
1279 logecho "[dvd-menu] button_font=$button_font"
1280
1281 ###############################
1282
1283 myecho "[dvd-menu] ###################################"
1284
1285 ###########################################################
1286 # Start creating menus:
1287 if [ "$no_menu" -eq 0 ] ; then
1288 myecho "[dvd-menu] Creating menu"
1289 ## first, do the background image, then do the alpha mask:
1290 if [ -f "$bgfile" ] ; then
1291 echo "[dvd-menu] Using background image $( truncate_filename "$bgfile")"
1292 background "$bgfile"
1293 # convert "${bgfile}" -resize x"$dvd_height" -bordercolor black -border "$dvd_width"x240 -gravity center -crop "$dvd_width"x"$dvd_height"'+0+0!' -depth 8 -quality 100 "$tmpdir"/slideshow_background.ppm
1294 mv "$tmpdir/slideshow_background.ppm" "$tmpdir/menu.ppm"
1295 else
1296 if [ -n "$bgfile" ] ; then
1297 # assume user passed a color that imagemagick can understand
1298 bg_color="$bgfile" # over-rides internal setting
1299 fi
1300 ## need to write out a blank image of the given size:
1301 echo "[dvd-menu] Creating background image gradient"
1302 convert -depth 8 -size "$dvd_width"'x'"$dvd_height" gradient:white-$bg_color -type TrueColorMatte "$tmpdir/menu.ppm"
1303 fi
1304 ## save this menu background as the "background" for fadin/fadeout:
1305 cp "$tmpdir/menu.ppm" "$tmpdir/slideshow_background.ppm"
1306
1307 ## create overlay transparent image:
1308 convert -depth 8 -colors 3 +antialias -size "$dvd_width"'x'"$dvd_height" xc:transparent "$tmpdir"/button_background_mask.png
1309 cp "$tmpdir/button_background_mask.png" "$tmpdir/menu_mask.png"
1310
1311 if [ -n "$dvd_title" ] ; then
1312 echo "[dvd-menu] Creating white title mask"
1313 white_title_mask "$tmpdir/title_background_mask.png"
1314 composite -compose src-over -type TrueColorMatte -depth 8 -dissolve 60 "$tmpdir/title_background_mask.png" "$tmpdir/menu.ppm" "$tmpdir/menu.ppm"
1315 title_text "$tmpdir/dvd_title.png"
1316 composite -compose src-over -depth 8 -type TrueColorMatte "$tmpdir/dvd_title.png" "$tmpdir/menu.ppm" "$tmpdir/menu.ppm"
1317 fi
1318
1319 ## so, we have a few different layouts:
1320 ## 1. straight text on the right side
1321 ## 2. 6 icon buttons with text underneath (not working)
1322 ## 3. 6 icon buttons per page, multiple pages (not working)
1323 ## 4. 15 icon buttons per page, no text? (not working)
1324
1325 # if [ "${#buttonfile[@]}" -gt 1 ] ; then
1326 # menu_type="6images" ## don't use this yet!!!
1327 # else
1328 # menu_type="textbar"
1329 # fi
1330
1331 if [ "${#xmlfile[@]}" == 0 ] ; then
1332 echo "[dvd-menu] no xml files passed"
1333 i=0
1334 for it in "${title[@]}" ; do
1335 total_titles[$i]="${title[$i]}"
1336 i=$(( $i + 1 ))
1337 done
1338 else
1339 i=0
1340 for it in "${xmlfile[@]}" ; do
1341 total_titles[$i]="${xmlfile[$i]}"
1342 i=$(( $i + 1 ))
1343 done
1344 fi
1345 number_of_titles="$i"
1346 if [ $number_of_titles -gt 10 ] && [ "$menu_type" == 'textbar' ] ; then
1347 # use two-column layout by default:
1348 menu_type='2textbar'
1349 echo "using 2textbar layout"
1350 fi
1351 ## case 1: old layout:
1352 if [ "$menu_type" == 'textbar' ] ; then # plain text on right side
1353 menuright=$(( $menu_panel_location_x + $panel_width))
1354 menubottom=$(( $dvd_height + 50 )) ## add 50 so we can chop off the bottom later
1355 menuh=$(( $dvd_height + 50 ))
1356 if [ "$no_white" -eq 0 ] ; then
1357 echo "[dvd-menu] Creating white button mask"
1358 white_button_mask "$tmpdir/button_background_mask.png"
1359 composite -compose src-over -type TrueColorMatte -depth 8 -dissolve 50 "$tmpdir/button_background_mask.png" "$tmpdir/menu.ppm" "$tmpdir/menu.ppm"
1360 fi
1361 ## create embedded image if defined:
1362 if [ -f "${embedfile[0]}" ]; then # only one embedfile possible
1363 echo "[dvd-menu] using image highlight ${embedfile[0]}"
1364 # Resize to 240x320 (max), keep aspect ratio.
1365 embed_height=$(identify -format %h "${embedfile[0]}")
1366 embed_width=$(identify -format %w "${embedfile[0]}")
1367 if [ $embed_width -gt $embed_height ]; then
1368 embed_resolution=$embed_image_width"x"$embed_image_height
1369 else
1370 embed_resolution=$embed_image_height"x"$embed_image_width
1371 fi
1372 # echo "[dvd-menu] running convert"
1373 convert "${embedfile[0]}" -resize "$sq_to_dvd_pixels" -resize "$embed_image_width"x"$embed_image_height" "$tmpdir"/embed.png
1374 # Add embed image to menu background
1375 embed_offset_y=$[ ( ($dvd_height-$menu_panel_location_y) - $(identify -format %h "$tmpdir"/embed.png) ) / 3 ]
1376 embed_offset_x=$[ ( ($dvd_width-$menu_panel_location_x) - $(identify -format %w "$tmpdir"/embed.png) ) /2 ]
1377 composite -compose src-over -geometry +$embed_offset_x+$[$menu_panel_location_y+$embed_offset_y] -type TrueColorMatte -depth 8 -dissolve 100 "$tmpdir"/embed.png "$tmpdir"/menu.ppm "$tmpdir"/menu.ppm
1378 fi
1379 ## loop over each title:
1380 let i=0
1381 for this_title in "${total_titles[@]}"; do
1382 echo "[dvd-menu] Title=${title[$i]}"
1383 # make each individual button:
1384 # to be fancy, let's add the button layers in two steps. first the
1385 # button background, then the text:
1386 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then
1387 # add numbers to each line for VCD
1388 convert -size "$panel_width"x"$panel_height" xc:transparent -quality 100 -font "$button_font" -pointsize $button_font_size -gravity West -fill "$button_font_color" -draw "text 20,0 \"$(( $i + 1 )). ${title[$i]}\"" "$tmpdir"/button_text.png
1389 else
1390 convert -size "$panel_width"x"$panel_height" xc:transparent -quality 100 -font "$button_font" -pointsize $button_font_size -gravity West -fill "$button_font_color" -draw "text 20,0 \"${title[$i]}\"" "$tmpdir"/button_text.png
1391 fi
1392 # make each individual button mask (for when it's selected)
1393 convert -size "$panel_width"x"$panel_height" xc:transparent -quality 100 -font "$button_font" -pointsize $button_font_size -fill $button_hilight_color -gravity West +antialias -colors 3 -draw "text 20,0 \"${title[$i]}\"" "$tmpdir"/button_mask.png
1394
1395 ## add each button as necessary, and increment the location downward
1396 echo "[dvd-menu] adding title button ${title[$i]} at $menu_panel_location_x , $menu_button_location_y"
1397 composite -compose src-over -depth 8 -geometry +$menu_panel_location_x+$menu_button_location_y "$tmpdir/button_text.png" "$tmpdir/menu.ppm" "$tmpdir/menu.ppm"
1398 ## add each overlay mask for the selection of buttons:
1399 composite -compose src-over -depth 8 -colors 3 -quality 100 -geometry +$menu_panel_location_x+$menu_button_location_y "$tmpdir/button_mask.png" "$tmpdir/menu_mask.png" "$tmpdir/menu_mask.png"
1400
1401 ## now record the button location:
1402 right[$i]="$(( $menu_panel_location_x + $panel_width ))"
1403 [ "${right[$i]}" -gt "$dvd_width" ] && right[$i]=$(( $dvd_width - 10 ))
1404 left[$i]="$(( $menu_panel_location_x ))"
1405 top[$i]="$(( $menu_button_location_y +1 ))"
1406 bottom[$i]="$(( $menu_button_location_y + $panel_height ))"
1407 [ "${bottom[$i]}" -gt "$dvd_height" ] && bottom[$i]=$(( $dvd_height - 10 ))
1408
1409 echo "[dvd-menu] setting button mask l,r,t,b = ${left[$i]} ${right[$i]} ${top[$i]} ${bottom[$i]}"
1410
1411 vts="$(( $i + 1 ))"
1412 # echo "[dvd-menu] i=$i vts=$vts"
1413
1414 let menu_button_location_y=$menu_button_location_y+$panel_height
1415 let i=$i+1
1416 done
1417 elif [ "$menu_type" == '2textbar' ] ; then # two columns of text. no hilight?
1418 menuright=$(( $menu_panel_location_x + $panel_width))
1419 menubottom=$(( $dvd_height + 50 )) ## add 50 so we can chop off the bottom later
1420 menuh=$(( $dvd_height + 50 ))
1421 if [ "$no_white" -eq 0 ] ; then
1422 echo "[dvd-menu] Creating white button mask"
1423 white_button_mask "$tmpdir/button_background_mask.png"
1424 composite -compose src-over -type TrueColorMatte -depth 8 -dissolve 50 "$tmpdir/button_background_mask.png" "$tmpdir/menu.ppm" "$tmpdir/menu.ppm"
1425 convert "$tmpdir/button_background_mask.png" -flop "$tmpdir/button_background_mask.png"
1426 composite -compose src-over -type TrueColorMatte -depth 8 -dissolve 50 "$tmpdir/button_background_mask.png" "$tmpdir/menu.ppm" "$tmpdir/menu.ppm"
1427 fi
1428 # split the titles between the left and right:
1429 menu_panel_location_x_l=0
1430 menu_panel_location_x_r=$menu_panel_location_x
1431 menu_panel_location_x=$menu_panel_location_x_l # default starting point
1432 menu_button_location_y_orig=$menu_button_location_y
1433 button_alignment="East"
1434 ## loop over each title:
1435 let i=0
1436 for this_title in "${total_titles[@]}"; do
1437 echo "[dvd-menu] Title $i = ${title[$i]}"
1438 # make each individual button:
1439 # to be fancy, let's add the button layers in two steps. first the
1440 # button background, then the text:
1441 if [ "$i" -eq "$(( $number_of_titles / 2 + 1 ))" ] ; then
1442 # switch to right panel and reset the height:
1443 menu_panel_location_x=$menu_panel_location_x_r
1444 menu_button_location_y=$menu_button_location_y_orig
1445 button_alignment="West"
1446 fi
1447 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then
1448 # add numbers to each line for VCD
1449 convert -size "$panel_width"x"$panel_height" xc:transparent -quality 100 -font "$button_font" -pointsize $button_font_size -gravity $button_alignment -fill "$button_font_color" -draw "text 20,0 \"$(( $i + 1 )). ${title[$i]}\"" "$tmpdir"/button_text.png
1450 else
1451 convert -size "$panel_width"x"$panel_height" xc:transparent -quality 100 -font "$button_font" -pointsize $button_font_size -gravity $button_alignment -fill "$button_font_color" -draw "text 20,0 \"${title[$i]}\"" "$tmpdir"/button_text.png
1452 fi
1453 # make each individual button mask (for when it's selected)
1454 convert -size "$panel_width"x"$panel_height" xc:transparent -quality 100 -font "$button_font" -pointsize $button_font_size -fill $button_hilight_color -gravity $button_alignment +antialias -colors 3 -draw "text 20,0 \"${title[$i]}\"" "$tmpdir"/button_mask.png
1455
1456 ## add each button as necessary, and increment the location downward
1457 echo "[dvd-menu] adding title button ${title[$i]} at $menu_panel_location_x , $menu_button_location_y"
1458 composite -compose src-over -depth 8 -geometry +$menu_panel_location_x+$menu_button_location_y "$tmpdir/button_text.png" "$tmpdir/menu.ppm" "$tmpdir/menu.ppm"
1459 ## add each overlay mask for the selection of buttons:
1460 composite -compose src-over -depth 8 -colors 3 -quality 100 -geometry +$menu_panel_location_x+$menu_button_location_y "$tmpdir/button_mask.png" "$tmpdir/menu_mask.png" "$tmpdir/menu_mask.png"
1461
1462 ## now record the button location:
1463 right[$i]="$(( $menu_panel_location_x + $panel_width ))"
1464 [ "${right[$i]}" -gt "$dvd_width" ] && right[$i]=$(( $dvd_width - 10 ))
1465 left[$i]="$(( $menu_panel_location_x ))"
1466 top[$i]="$(( $menu_button_location_y ))"
1467 bottom[$i]="$(( $menu_button_location_y + $panel_height ))"
1468 [ "${bottom[$i]}" -gt "$dvd_height" ] && bottom[$i]=$(( $dvd_height - 10 ))
1469
1470 echo "[dvd-menu] setting button mask l,r,t,b = ${left[$i]} ${right[$i]} ${top[$i]} ${bottom[$i]}"
1471
1472 vts="$(( $i + 1 ))"
1473 # echo "[dvd-menu] i=$i vts=$vts"
1474
1475 let menu_button_location_y=$menu_button_location_y+$panel_height
1476 let i=$i+1
1477 done
1478
1479 elif [ "$menu_type" == '6images' ] ; then ### don't use this yet!
1480 ## loop over each title:
1481 let i=0
1482 let embed=1 # embedfile is for normal menu type
1483 let embed_row=1
1484
1485 # grab any info from .xml file comment lines:
1486 for this_title in "${total_files[@]}"; do
1487 suffix=`echo "${xmlfile[$i]}" | awk -F. '{print $NF}'`
1488 if [ "$suffix" == 'xml' ] ; then
1489 xml_button[$i]=$( grep '<!-- button=' "${xmlfile[$i]}" | awk -F= '{print $2}' | awk -F' -->' '{print $1}' | tr -d '\047' | tr -d '\042' )
1490 #echo "xml_button[$i]=${xml_button[$i]}"
1491 [ -n "${xml_button[$i]}" ] && echo "[dvd-menu] xml_button $i = $( truncate_filename "${xml_button[$i]}" )"
1492 xml_title[$i]=$( grep '<!-- title="' "${xmlfile[$i]}" | awk -F= '{print $2}' | awk -F'" -->' '{print $1}' | tr -d '\047' | tr -d '\042' )
1493 #echo "xml_title[$i]=${xml_title[$i]}"
1494 [ -n "${xml_title[$i]}" ] && echo "[dvd-menu] xml_title $i = ${xml_title[$i]}"
1495 fi
1496 # make each individual button:
1497 # to be fancy, let's add the button layers in two steps. first the
1498 # button background, then the text:
1499 ## create embedded image hilight if required:
1500 dvd_width_scaled=$(( $dvd_width * $sq_pixel_multiplier / 1000 ))
1501 hilight_height=90
1502 hilight_width=135
1503 # hilight_height=$(( ( $dvd_height - $title_white_height - 3 * $hilight_spacing_y - 2*$hilight_font_size)/2 ))
1504 # hilight_width=$(( $hilight_height * $dvd_width / $dvd_height ))
1505 buttons="${#xmlfile[@]}"
1506 if [ "$buttons" -gt 6 ] ; then
1507 echo "[dvd-menu] ERROR: too many buttons for this menu type!"
1508 exit 1
1509 elif [ "$buttons" == 4 ] ; then
1510 hilight_spacing_x=100
1511 hilight_start_location_x=$(( ($dvd_width - 2*$hilight_width - 1*$hilight_spacing_x )/2 ))
1512 hilight_start_location_y=$(( $title_white_height + $hilight_spacing_y / 2 ))
1513 elif [ "$buttons" -gt 3 ] ; then
1514 hilight_start_location_x=$(( ($dvd_width - 3*$hilight_width - 2*$hilight_spacing_x )/2 ))
1515 hilight_start_location_y=$(( $title_white_height + $hilight_spacing_y / 2 ))
1516 else
1517 [ "$buttons" == 2 ] && hilight_spacing_x=100
1518 hilight_start_location_x=$(( ($dvd_width - $buttons * $hilight_width - ( $buttons - 1 )*$hilight_spacing_x )/2 ))
1519 hilight_start_location_y=$(( $title_white_height + $hilight_spacing_y ))
1520 fi
1521 ## size constraint seems to be vertically when we have a title.
1522 ## so, eventually, we could have different situations, depending on whether or not
1523 ## a title exists, etc... let's assume it does for now!
1524
1525 [ -z "${buttonfile[$i]}" ] && buttonfile[$i]="${xml_button[$i]}"
1526 [ -z "${title[$i]}" ] && title[$i]="${xml_title[$i]}"
1527 echo "[dvd-menu] Title=${title[$i]}"
1528 echo "[dvd-menu] Image=${buttonfile[$i]}"
1529 button_text_white=1
1530 if [ "$button_text_white" == 1 ] ; then
1531 text_height=$(( 3* $hilight_font_size ))
1532 text_width=$(( $hilight_width + $hilight_spacing_x / 2 ))
1533 convert -size "$text_width"x$text_height xc:transparent -depth 8 "$tmpdir"/button_mask_trans.png
1534 convert -size "$text_width"x$text_height xc:transparent -depth 8 -fill white -draw "roundRectangle 0,0,$text_width,$text_height $button_radius,$button_radius" -background none -blur 0x3 "$tmpdir"/button_mask.png
1535 composite -compose src-over -type TrueColorMatte -depth 8 -dissolve 60 "$tmpdir"/button_mask.png "$tmpdir"/button_mask_trans.png "$tmpdir"/button_mask.png
1536
1537 convert -size ${text_width}x$text_height xc:transparent -quality 100 -font "$button_font" -fill "$button_font_color" -pointsize $button_font_size -gravity center -draw "text 0,0 \"${title[$i]}\"" "$tmpdir"/button_text.png
1538 composite -compose src-over -type TrueColorMatte -depth 8 "$tmpdir"/button_text.png "$tmpdir"/button_mask.png "$tmpdir"/button_text.png
1539 fi
1540 #echo "buttonfile=${buttonfile[$i]}".
1541 if [ -e "${buttonfile[$i]}" ]; then
1542 echo "[dvd-menu] using image $( truncate_filename "${buttonfile[$i]}" )"
1543 # echo "[dvd-menu] hilight_width=$hilight_width hilight_height=$hilight_height"
1544 convert "${buttonfile[$i]}" -resize "$hilight_width"x"$hilight_height" -quality 100 "$tmpdir/embed.jpg"
1545 actual_hilight_width=$( imagewidth_sq "$tmpdir"/embed.jpg )
1546 actual_hilight_height=$( imageheight "$tmpdir"/embed.jpg )
1547 # make each individual button mask (for when it's selected)
1548 convert -colors 3 +antialias -size "$actual_hilight_width"x"$actual_hilight_height" xc:transparent -fill transparent -stroke $button_hilight_color -strokewidth 5 -draw "rectangle 0,0 $actual_hilight_width,$actual_hilight_height" -quality 100 "$tmpdir/button_mask.png"
1549
1550 ## calculate location of this image:
1551 if [ "$buttons" == "4" ] ; then
1552 [ $embed -ge 3 ] && embed_row=2 || embed_row=1
1553 [ $embed -ge 3 ] && embed_col=$(( $embed - 2 )) || embed_col=$embed
1554 elif [ "$buttons" -gt 3 ] ; then
1555 [ $embed -ge 4 ] && embed_row=2 || embed_row=1
1556 [ $embed -ge 4 ] && embed_col=$(( $embed - 3 )) || embed_col=$embed
1557 elif [ "$buttons" -le 3 ] ; then
1558 embed_row=1
1559 embed_col=$embed
1560 fi
1561 hilight_x=$(( $hilight_start_location_x + ($embed_col - 1)*($hilight_spacing_x + $hilight_width) ))
1562 hilight_y=$(( $hilight_start_location_y + ($embed_row - 1)*($hilight_spacing_y + $hilight_height + $hilight_font_size ) ))
1563 button_text_location_x=$(( $hilight_x - $hilight_spacing_x / 4 ))
1564 button_text_location_y=$(( $hilight_y + $hilight_height ))
1565 echo "[dvd-menu] r,c=$embed_row,$embed_col hilight_x_loc=$hilight_x hilight_y_loc=$hilight_y"
1566
1567 ## add each button as necessary, and increment the location
1568 composite -compose src-over -type TrueColorMatte -depth 8 -geometry +$button_text_location_x+$button_text_location_y "$tmpdir/button_text.png" "$tmpdir/menu.ppm" "$tmpdir/menu.ppm"
1569
1570 # Add embed image to menu background
1571 difference_x=$(( ( $hilight_width - $actual_hilight_width )/2 ))
1572 difference_y=$(( ( $hilight_height - $actual_hilight_height )/2 ))
1573 ## adjust hilight location:
1574 hilight_x=$(( $hilight_x + $difference_x ))
1575 hilight_y=$(( $hilight_y + $difference_y ))
1576 composite -compose src-over -type TrueColorMatte -depth 8 -geometry +$hilight_x+$hilight_y "$tmpdir/embed.jpg" "$tmpdir/menu.ppm" "$tmpdir/menu.ppm"
1577 ## add each overlay mask for the selection of buttons:
1578 composite -compose src-over -depth 8 -colors 3 -quality 100 -geometry +$hilight_x+$hilight_y "$tmpdir/button_mask.png" "$tmpdir/menu_mask.png" "$tmpdir/menu_mask.png"
1579
1580 ## now record the button location:
1581 right[$i]="$(( $hilight_x + $hilight_width ))"
1582 left[$i]="$(( $hilight_x ))"
1583 top[$i]="$(( $hilight_y ))"
1584 bottom[$i]="$(( $hilight_y + $hilight_height ))"
1585 let embed=$embed+1
1586 fi
1587 ##################################################################33
1588
1589 vts="$(( $i + 1 ))"
1590 echo "[dvd-menu] i=$i vts=$vts"
1591
1592 let i=$i+1
1593 done
1594 fi # end of different menu types
1595
1596 ## now convert the menu background to a mpg
1597 if [ "$mpeg_encoder" == 'mpeg2enc' ] ; then
1598 ppmtoy4m -v 0 -n "$frames" -r -S "$subsample" -F $ppmtoy4m_frc -A $ppmtoy4m_aspect -I p "$tmpdir/menu.ppm" | mpeg2enc $mpeg2enc_params -o "$tmpdir/menu.mpg"
1599 else
1600 ppmtoy4m -v 0 -n "$frames" -r -S "$subsample" -F $ppmtoy4m_frc -A $ppmtoy4m_aspect -I p "$tmpdir/menu.ppm" | ffmpeg -f yuv4mpegpipe -i - -target $ffmpeg_target -r $framerate -an -aspect $aspect_ratio -s "$dvd_width"x"$dvd_height" -y -f mpeg2video "$tmpdir/menu.mpg" >> "$logfile" 2>&1
1601 fi
1602 ## or, for a background video, cat all the frame through a composite call to add the button text and mask
1603 ## all at once. (and, use transparent background for button text)
1604
1605
1606 if [ "$fade_to_image" == 'black' ] ; then
1607 background black "$tmpdir"/bg_fade.ppm
1608 elif [ -f "$fade_to_image" ] ; then
1609 background "$fade_to_image" "$tmpdir"/bg_fade.ppm
1610 fi
1611 if [ "$fadein" -eq 1 ] ; then
1612 if [ "$fade_to_image" == 'black' ] ; then
1613 echo "[dvd-menu] Creating fadein from black..."
1614 fade "$tmpdir/menu.ppm" "$tmpdir"/bg_fade.ppm 2
1615 elif [ -f "$fade_to_image" ] ; then
1616 echo "[dvd-menu] Creating fadein from image..."
1617 fade "$tmpdir/menu.ppm" "$tmpdir"/bg_fade.ppm 2
1618 else
1619 echo "[dvd-menu] Creating fadein from background..."
1620 fade "$tmpdir/menu.ppm" "$tmpdir/slideshow_background.ppm" 2
1621 fi
1622 mv "$tmpdir/fade.mpg" "$tmpdir/fadein.mpg"
1623 fi
1624 if [ "$fadeout" -eq 1 ] ; then
1625 if [ "$fade_to_image" == 'black' ] ; then
1626 echo "[dvd-menu] Creating fadeout to black..."
1627 fade "$tmpdir"/bg_fade.ppm "$tmpdir"/menu.ppm 2
1628 elif [ -e "$fade_to_image" ] ; then
1629 echo "[dvd-menu] Creating fadeout to image..."
1630 fade "$tmpdir"/bg_fade.ppm "$tmpdir"/menu.ppm 2
1631 else
1632 echo "[dvd-menu] Creating fadeout to background..."
1633 fade "$tmpdir/slideshow_background.ppm" "$tmpdir/menu.ppm" 2
1634 fi
1635 mv "$tmpdir/fade.mpg" "$tmpdir/fadeout.mpg"
1636 fi
1637
1638 # optionally fade out at a certain time?
1639 if [ -n "$audiofile" ] ; then
1640 ## get type of file: mp3, ogg, or wav
1641 suffix=`echo "$audiofile" | awk -F. '{print $NF}'`
1642 echo "[dvd-menu] Decoding $suffix audio file"
1643 if [ "$suffix" == "mp3" ] ; then
1644 checkforprog lame
1645 lame --decode "$audiofile" "$tmpdir/audio_tmp.wav" >> "$logfile" 2>&1
1646 # convert it to 48khz:
1647 song_length_ms=`wavlength "$tmpdir/audio_tmp.wav"`
1648 song_length_hms=`hms $song_length_ms`
1649 sox -v 0.90 "$tmpdir/audio_tmp.wav" -r $audio_sample_rate "$tmpdir/audio.wav" fade t 2 "$song_length_hms" 2
1650 rm "$tmpdir/audio_tmp.wav"
1651 elif [ "$suffix" == "ogg" ] ; then
1652 checkforprog oggdec
1653 oggdec -o "$tmpdir/audio_tmp.wav" "$audiofile" >> "$logfile" 2>&1
1654 song_length_ms=`wavlength "$tmpdir/audio_tmp.wav"`
1655 song_length_hms=`hms $song_length_ms`
1656 echo "song=$audiofile"
1657 # convert it to 48khz:
1658 sox -v 0.90 "$tmpdir/audio_tmp.wav" -r $audio_sample_rate "$tmpdir/audio.wav" fade t 2 "$song_length_hms" 2
1659 rm "$tmpdir/audio_tmp.wav"
1660 elif [ "$suffix" == "wav" ] ; then
1661 # convert it to 48khz:
1662 song_length_ms=`wavlength "$audiofile"`
1663 song_length_hms=`hms $song_length_ms`
1664 echo "song=$audiofile"
1665 sox -v 0.90 "$audiofile" -r $audio_sample_rate "$tmpdir/audio.wav" fade t 2 "$song_length_hms" 2
1666 else
1667 echo "[dvd-menu] ERROR: Unknown audio file format. Must be .mp3, .ogg, or .wav"
1668 fi
1669 else
1670 ## create silence:
1671 echo "[dvd-menu] creating silent audio track"
1672 ## create audio for 1 second:
1673 sox -t raw $sox_int $sox_word -c 2 -r $audio_sample_rate /dev/zero -t wav - trim 0 0:01.000 > "$tmpdir/audio.wav"
1674 fi
1675
1676 if [ "$fadein" -eq 1 ] || [ "$fadeout" -eq 1 ] ; then
1677 # create slience .wav file for 1 second for fadein/fadeout
1678 sox -t raw $sox_int $sox_word -c 2 -r $audio_sample_rate /dev/zero -t wav - trim 0 0:02.000 > "$tmpdir/fade_audio.wav"
1679 fi
1680
1681
1682 if [ "$ac3" -eq 1 ] ; then
1683 echo "[dvd-menu] Creating ac3 audio..."
1684 rm -f "$tmpdir/audio.ac3"
1685 ffmpeg -i "$tmpdir/audio.wav" -vn -y -ab "$audio_bitrate"k -acodec ac3_fixed -ar $audio_sample_rate -ac 6 "$tmpdir/audio.ac3" >> "$logfile" 2>&1
1686 if [ "$fadein" -eq 1 ] || [ "$fadeout" -eq 1 ] ; then
1687 ffmpeg -i "$tmpdir/fade_audio.wav" -vn -y -ab "$audio_bitrate"k -acodec ac3_fixed -ar $audio_sample_rate -ac 6 "$tmpdir/fade_audio.ac3" >> "$logfile" 2>&1
1688 fi
1689 else
•1690 ## twolame is way faster! (3x in my test)
1691 it=`which twolame`
1692 if [ -n "$it" ] ; then
•1693 twolame_version=`twolame -h | head -n 4 | grep version | awk '{ print $3 }'`
1694 echo "[dvd-menu] using twolame $twolame_version..."
1695 if [ "$twolame_version" == '0.2m' ] ; then
1696 twolame -s $audio_sample_rate -b $audio_bitrate "$tmpdir/audio.wav" "$tmpdir/audio.mp2" >> "$logfile" 2>&1
1697 else
1698 ## need to hard code in the sample rate here because the syntax is bad
1699 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then
•1700 twolame -s 44100 -b $audio_bitrate "$tmpdir/audio.wav" "$tmpdir/audio.mp2" >> "$logfile" 2>&1
1701 else
•1702 twolame -s 48000 -b $audio_bitrate "$tmpdir/audio.wav" "$tmpdir/audio.mp2" >> "$logfile" 2>&1
1703 fi
1704 fi
1705 else
1706 myecho "[dvd-menu] using mp2enc"
1707 mp2enc -v 0 -b $audio_bitrate -r $audio_sample_rate -s -o "$tmpdir/audio.mp2" < "$tmpdir/audio.wav"
1708 fi
1709 if [ "$fadein" -eq 1 ] || [ "$fadeout" -eq 1 ] ; then
1710 mp2enc -v 0 -b $audio_bitrate -r $audio_sample_rate -s -o "$tmpdir/fade_audio.mp2" < "$tmpdir/fade_audio.wav"
1711 fi
1712 fi
1713
1714 ## now multiplex the audio and video:
1715 myecho "[dvd-menu] mplexing the files............."
1716 if [ "$ac3" -eq 1 ] ; then
1717 mplex -v 0 -f $mplex_type -o "$tmpdir/menu_t.vob" "$tmpdir/menu.mpg" "$tmpdir"/audio.ac3
1718 if [ "$fadein" -eq 1 ] ; then
1719 mplex -v 0 -f $mplex_type -o "$outdir/fadein.vob" "$tmpdir/fadein.mpg" "$tmpdir"/fade_audio.ac3
1720 fi
1721 if [ "$fadeout" -eq 1 ] ; then
1722 mplex -v 0 -f $mplex_type -o "$outdir/fadeout.vob" "$tmpdir/fadeout.mpg" "$tmpdir"/fade_audio.ac3
1723 fi
1724 else
1725 mplex -v 0 -f $mplex_type -o "$tmpdir/menu_t.vob" "$tmpdir/menu.mpg" "$tmpdir"/audio.mp2
1726 if [ "$fadein" -eq 1 ] ; then
1727 mplex -v 0 -f $mplex_type -o "$outdir/fadein.vob" "$tmpdir/fadein.mpg" "$tmpdir"/fade_audio.mp2
1728 fi
1729 if [ "$fadeout" -eq 1 ] ; then
1730 mplex -v 0 -f $mplex_type -o "$outdir/fadeout.vob" "$tmpdir/fadeout.mpg" "$tmpdir"/fade_audio.mp2
1731 fi
1732 fi
1733
1734 ## start of button subpicture XML file creation for spumux:
1735 ## now define the buttons:
1736 echo '<subpictures>' > "$tmpdir/menu.spumux"
1737 echo ' <stream>' >> "$tmpdir/menu.spumux"
1738 echo -n ' <spu start="00:00:00.00" end="00:00:00.00" highlight="' >> "$tmpdir/menu.spumux"
1739 echo "$tmpdir/menu_mask.png"'" force="yes" >' >> "$tmpdir/menu.spumux"
1740 ## now loop over the buttons:
1741 let i=0
1742 for it in "${left[@]}"; do
1743 echo -n ' <button ' >> "$tmpdir/menu.spumux"
1744 # insert an up link to the upAction for the first button
1745 if [ $i -eq 0 ] && [ "$upAction" -eq 1 ]; then
1746 echo -n ' up="upAction" ' >> "$tmpdir/menu.spumux"
1747 fi
1748 echo 'x0="'${left[$i]}'" y0="'${top[$i]}'" x1="'${right[$i]}'" y1="'${bottom[$i]}'" />' >> "$tmpdir/menu.spumux"
1749
1750 let i=$i+1
1751 done
1752 # append an up action to the button list
1753 if [ "${upAction}" -eq 1 ] ; then
1754 echo ' <action name="upAction" />' >> "$tmpdir/menu.spumux"
1755 fi
1756 echo ' </spu>' >> "$tmpdir/menu.spumux"
1757 echo ' </stream>' >> "$tmpdir/menu.spumux"
1758 echo '</subpictures>' >> "$tmpdir/menu.spumux"
1759
1760 myecho "[dvd-menu] ###############################################"
1761 myecho "[dvd-menu] spumuxing the files............."
1762 ## using spumux now:
1763 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then
1764 mv "$tmpdir/menu_t.vob" "$outdir/menu.mpg"
1765 else # DVD
1766 # spumux -v 0 -P "$tmpdir/menu.spumux" < "$tmpdir/menu_t.vob" > "$outdir/menu.vob" >> "$logfile" 2>&1
1767 spumux -v 0 -P "$tmpdir/menu.spumux" < "$tmpdir/menu_t.vob" > "$outdir/menu.vob" 2>> "$logfile"
1768 if [ $? -ne 0 ] ; then
1769 ## spumux errored
1770 myecho "[dvd-menu] ERROR during spumux execution!"
1771 myecho "[dvd-menu] see $logfile for details"
1772 exit 1
1773 fi
1774 fi
1775 fi
1776 # end if we're actually making a menu. otherwise, just to the stuff below
1777
1778 #############################################################
1779 ## menu part of .xml file:
1780
1781 # write header:
1782 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then
1783 # vcd menus:
1784 echo "[dvd-menu] Creating vcd menu"
1785 echo '<?xml version="1.0"?>
1786 <!DOCTYPE videocd PUBLIC "-//GNU//DTD VideoCD//EN" "http://www.gnu.org/software/vcdimager/videocd.dtd">' > "$outdir/vmgm.xml"
1787 if [ "$vcd" -eq 1 ] ; then
1788 echo '<videocd xmlns="http://www.gnu.org/software/vcdimager/1.0/" class="vcd" version="2.0">' >> "$outdir/vmgm.xml"
1789 elif [ "$svcd" -eq 1 ] ; then
1790 echo '<videocd xmlns="http://www.gnu.org/software/vcdimager/1.0/" class="svcd" version="1.0">' >> "$outdir/vmgm.xml"
1791 else
1792 echo '[dvd-menu] ERROR: Bad vcd type' ; exit 1
1793 fi
1794 echo '<info>
1795 <album-id>666</album-id>
1796 <volume-count>1</volume-count>
1797 <volume-number>1</volume-number>
1798 <restriction>0</restriction>
1799 </info>
1800 <pvd>
1801 <volume-id>VIDEOCD</volume-id>
1802 <system-id>CD-RTOS CD-BRIDGE</system-id>
1803 <preparer-id>scott_preparer</preparer-id>
1804 <publisher-id></publisher-id>
1805 </pvd>' >> "$outdir/vmgm.xml"
1806 echo '<sequence-items>' >> "$outdir/vmgm.xml"
1807 echo ' <sequence-item src="'"$outdir/menu.mpg"'" id="seq-menu"/>' >> "$outdir/vmgm.xml"
1808 total_files="${#xmlfile[*]}" ; i=0
1809 # for it in `seq 1 1 $total_files` ; do
1810 for (( it=1 ; it<=total_files ; it++ )) ; do
1811 if [ "$(( $i + 1 ))" -eq "$total_files" ] ; then continuous=0 ; fi
1812 myecho "[dvd-menu] sequencefile=${xmlfile[$i]}"
1813 suffix=`echo "${xmlfile[$i]}" | awk -F. '{print $NF}'`
1814 if [ "$suffix" == 'xml' ] ; then
1815 file_base=`basename "${xmlfile[$i]}" .xml`
1816 xml_button[$i]=$( grep '<!-- button=' "${xmlfile[$i]}" | awk -F= '{print $2}' | awk -F' -->' '{print $1}' )
1817 # [ -n "${xml_button[$i]}" ] && echo "[dvd-menu] xml_button $i = ${xml_button[$i]}"
1818 xml_title[$i]=$( grep '<!-- title=' "${xmlfile[$i]}" | awk -F= '{print $2}' | awk -F' -->' '{print $1}' )
1819 # [ -n "${xml_title[$i]}" ] && echo "[dvd-menu] xml_title $i = ${xml_title[$i]}"
1820 elif [ "$suffix" == 'mpg' ] ; then
1821 file_base=`basename "${xmlfile[$i]}" .mpg`
1822 elif [ "$suffix" == 'vob' ] ; then
1823 file_base=`basename "${xmlfile[$i]}" .vob`
1824 else
1825 echo '[dvd-menu] error... filetype not supported!'
1826 exit
1827 fi
1828 # myecho "[dvd-menu] file=${xmlfile[$i]} file_base=$file_base suffix=$suffix"
1829 ## create <sequence-items> at the same time:
1830 echo ' <sequence-item src="'"$(cat ${xmlfile[$i]})"'" id="'"$file_base"_$(($i+1))'"/>' >> "$outdir/vmgm.xml"
1831 i=$(($i+1))
1832 done
1833 echo '</sequence-items>' >> "$outdir/vmgm.xml"
1834
1835 else # dvd menus:
1836 ## now build the dvdauthor xml file:
1837 ## do we need "jumppad"?
1838 echo '<dvdauthor dest="'$dvd_dir'" jumppad="0">' > "$outdir/vmgm.xml"
1839 echo ' <vmgm>' >> "$outdir/vmgm.xml"
1840 echo ' <menus>' >> "$outdir/vmgm.xml"
1841 echo ' <video format="'$ntsc_or_pal'" />' >> "$outdir/vmgm.xml"
1842 fi
1843
1844 # write menu
1845 if [ "$no_menu" -eq 0 ] ; then
1846 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then
1847 echo "<pbc>" >> "$outdir/vmgm.xml"
1848 echo ' <selection id="menu">' >> "$outdir/vmgm.xml"
1849 echo ' <bsn>1</bsn>' >> "$outdir/vmgm.xml"
1850 echo ' <loop jump-timing="immediate">0</loop>' >> "$outdir/vmgm.xml"
1851 echo ' <play-item ref="seq-menu"/>' >> "$outdir/vmgm.xml"
1852 else # dvd
1853 echo ' <pgc entry="title" >' >> "$outdir/vmgm.xml"
1854 ## put fadein before each menu:
1855 if [ "$fadein" -eq 1 ] ; then
1856 echo ' <vob file="'$outdir/fadein.vob'"/>' >> "$outdir/vmgm.xml"
1857 fi
1858 echo ' <vob file="'$outdir/menu.vob'" pause="inf"/>' >> "$outdir/vmgm.xml"
1859 fi
1860
1861
1862 ## now loop over each title for select buttons:
1863 # myecho "[dvd-menu] xmlfiles=${xmlfile[@]}"
1864 let i=1 ## titles start from 1, not zero.
1865 let m=1 ## menus start at 1
1866 for it in "${xmlfile[@]}"; do
1867 # verify xml file exists:
1868 if [ ! -r "$it" ] ; then
1869 echo "[dvd-menu] ERROR: XML file $it does not exist."
1870 exit 1
1871 fi
1872 suffix=`echo "$it" | awk -F. '{print $NF}'`
1873 if [ "$suffix" == 'xml' ] ; then
1874 file_base=`basename "$it" .xml`
1875 elif [ "$suffix" == 'mpg' ] ; then
1876 file_base=`basename "$it" .mpg`
1877 elif [ "$suffix" == 'vob' ] ; then
1878 file_base=`basename "$it" .vob`
1879 else
1880 echo '[dvd-menu] error... filetype not supported!'
1881 exit 1
1882 fi
1883 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then
1884 echo ' <select ref="'video$i'"/>' >> "$outdir/vmgm.xml"
1885 select[$i]="$file_base"_$i
1886 else # dvd
1887 if [ -f "$file_base"_submenu.xml ] ; then
1888 echo ' <button> jump menu '$m'; </button>' >> "$outdir/vmgm.xml"
1889 let m=$m+1
1890 else
1891 echo ' <button> jump title '$i'; </button>' >> "$outdir/vmgm.xml"
1892 fi
1893 fi
1894 let i=$i+1
1895 let m=$m+1
1896 done
1897
1898
1899
1900 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then
1901 echo ' </selection>' >> "$outdir/vmgm.xml"
1902 else # dvd
1903 echo ' <post> jump vmgm menu 1; </post>' >> "$outdir/vmgm.xml"
1904 echo ' </pgc>' >> "$outdir/vmgm.xml"
1905 fi
1906 fi
1907
1908 ## close last section and open next one:
1909 if [ "$vcd" -eq 0 ] && [ "$svcd" -eq 0 ] ; then ## DVD
1910 echo ' </menus>' >> "$outdir/vmgm.xml"
1911 echo ' </vmgm>' >> "$outdir/vmgm.xml"
1912 echo ' <titleset>' >> "$outdir/vmgm.xml"
1913 ## add a menu to the vtsm that pops back to the main menu
1914 ## for DVD players that default to first vtsm menu when you
1915 ## press the DVD menu button. (thanks for fix from will guaraldi)
1916 echo ' <menus>' >> "$outdir/vmgm.xml"
1917 echo ' <video format="'$ntsc_or_pal'" />' >> "$outdir/vmgm.xml"
1918 echo ' <pgc>' >> "$outdir/vmgm.xml"
1919 echo ' <post> jump vmgm menu; </post>' >> "$outdir/vmgm.xml"
1920 echo ' </pgc>' >> "$outdir/vmgm.xml"
1921 echo ' </menus>' >> "$outdir/vmgm.xml"
1922 ## every dvd has at least one title!
1923 echo ' <titles>' > "$tmpdir/titles_vmgm.xml"
1924 echo ' <subpicture lang="'$subtitle_code'"/>' >> "$tmpdir/titles_vmgm.xml"
1925 fi
1926 ## now cat the other ones into this file...
1927 let i=0
1928 let title=1
1929 let m=1
1930
1931 ## get rid of existing files:
1932 #rm -f "$tmpdir/menus_vmgm.xml"
1933
1934 total_files="${#xmlfile[*]}"
1935 #for it in `seq 1 1 $total_files` ; do
1936 for (( it=1 ; it<=total_files ; it++ )) ; do
1937 if [ "$(( $i + 1 ))" -eq "$total_files" ] ; then continuous=0 ; fi
1938 let j=$i+2
1939 myecho "[dvd-menu] sequencefile=${xmlfile[$i]}"
1940 suffix=`echo "${xmlfile[$i]}" | awk -F. '{print $NF}'`
1941 if [ "$suffix" == 'xml' ] ; then
1942 file_base=`basename "${xmlfile[$i]}" .xml`
1943 elif [ "$suffix" == 'mpg' ] ; then
1944 file_base=`basename "${xmlfile[$i]}" .mpg`
1945 elif [ "$suffix" == 'vob' ] ; then
1946 file_base=`basename "${xmlfile[$i]}" .vob`
1947 else
1948 echo '[dvd-menu] error... filetype not supported!'
1949 exit
1950 fi
1951
1952 nextmenu=$(( $m + 1 ))
1953 lastmenu=$(( $m - 1 ))
1954 # myecho "[dvd-menu] file=${xmlfile[$i]} file_base=$file_base suffix=$suffix"
1955 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then # VCD
1956 echo ' <playlist id="video'$(($i+1))'">' >> "$tmpdir/titles_vmgm.xml"
1957 # echo ' <select ref="'"$file_base"_$i'"/>' >> "$outdir/vmgm.xml"
1958 if [ "$continuous" -eq 1 ] ; then
1959 echo ' <next ref="'video$(($i+2))'"/>' >> "$tmpdir/titles_vmgm.xml"
1960 elif [ "$no_menu" -eq 0 ] ; then
1961 echo ' <next ref="menu"/>' >> "$tmpdir/titles_vmgm.xml"
1962 fi
1963 echo ' <wait>0</wait>' >> "$tmpdir/titles_vmgm.xml"
1964 echo ' <play-item ref="'"$file_base"_$(($i+1))'"/>' >> "$tmpdir/titles_vmgm.xml"
1965 # echo ' <sequence-item src="'"$(full_path ${xmlfile[$i]})"'" id="'"$file_base"_$(($i+1))'"/>' >> "$tmpdir/titles_seq.xml"
1966 echo ' </playlist>' >> "$tmpdir/titles_vmgm.xml"
1967 else # dvd
1968 # make sure palette file exists:
1969 # if [ -e "$outdir"/palette.rgb ] ; then
1970 # echo ' <pgc palette="'$outdir/palette.rgb'">' >> "$tmpdir/titles_vmgm.xml"
1971 # else
1972 echo ' <pgc>' >> "$tmpdir/titles_vmgm.xml"
1973 # fi
1974 ## fadeout from vmgm
1975 if [ "$fadeout" -eq 1 ] && [ "$continuous_method" -ne 1 ] ; then
1976 # non-continuous play means we want to fadeout from every menu
1977 echo ' <vob file="'$outdir/fadeout.vob'"/>' >> "$tmpdir/titles_vmgm.xml"
1978 elif [ "$fadeout" -eq 1 ] && [ "$continuous_method" -eq 1 ] && [ "$i" -eq 0 ] ; then
1979 # continuous play means we only fadeout from the menu on the first .vob
1980 echo ' <vob file="'$outdir/fadeout.vob'"/>' >> "$tmpdir/titles_vmgm.xml"
1981 fi
1982 ## now, add in the .vob file:
1983 if [ "$suffix" == 'mpg' ] || [ "$suffix" == 'vob' ]; then
1984 echo ' <vob file="'${xmlfile[$i]}'" />' >> "$tmpdir/titles_vmgm.xml"
1985 else
1986 cat "${xmlfile[$i]}" >> "$tmpdir/titles_vmgm.xml"
1987 fi
1988 if [ "$continuous" -eq 1 ] ; then
1989 echo " <post> jump title $j; </post>" >> "$tmpdir/titles_vmgm.xml"
1990 elif [ "$no_menu" -eq 0 ] ; then
1991 echo ' <post> call vmgm menu 1; </post>' >> "$tmpdir/titles_vmgm.xml"
1992 fi
1993 echo ' </pgc>' >> "$tmpdir/titles_vmgm.xml"
1994 fi
1995 let i=$i+1
1996 let title=$title+1
1997 done
1998
1999 ## finish up menus tag:
2000 #if [ $m -gt 1 ] ; then # only if we had submenus:
2001 # echo ' </menus>' >> "$tmpdir/menus_vmgm.xml"
2002 #fi
2003
2004 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then # VCD
2005 echo '</pbc>' >> "$tmpdir/titles_vmgm.xml"
2006 # echo '</sequence-items>' >> "$tmpdir/titles_seq.xml"
2007 cat "$tmpdir/titles_vmgm.xml" >> "$outdir/vmgm.xml"
2008 # cat "$tmpdir/titles_seq.xml" >> "$outdir/vmgm.xml"
2009 echo '</videocd>' >> "$outdir/vmgm.xml"
2010 else
2011 ## finish up titles tag:
2012 echo ' </titles>' >> "$tmpdir/titles_vmgm.xml"
2013 ## join the menus and titles with the vmgm menu:
2014 #if [ -f "$tmpdir/menus_vmgm.xml" ] ; then # only if submenus exist!
2015 # cat "$tmpdir/menus_vmgm.xml" >> "$outdir/vmgm.xml"
2016 #fi
2017 cat "$tmpdir/titles_vmgm.xml" >> "$outdir/vmgm.xml"
2018 echo ' </titleset>' >> "$outdir/vmgm.xml"
2019 echo '</dvdauthor>' >> "$outdir/vmgm.xml"
2020 fi
2021
2022
2023 myecho "[dvd-menu] ##############################"
2024
2025 ## run dvdauthor?
2026 if [ "$no_dvdauthor" -eq 0 ] ; then
2027 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then # VCD
2028 myecho "[dvd-menu] Running vcdxbuild..."
2029 vcdxbuild -c "$outdir"/videocd.cue -b "$outdir"/videocd.bin -p "$outdir/vmgm.xml"
2030 if [ $? -ne 0 ] ; then
2031 ## vcdxbuild errored
2032 myecho "[dvd-menu] ERROR during vcdxbuild execution!"
2033 myecho "[dvd-menu] see $logfile for details"
2034 exit 1
2035 else
2036 myecho "[dvd-menu] vcdxbuild ran ok. See logfile for details."
2037 fi
2038 else
2039 myecho "[dvd-menu] Running dvdauthor..."
2040 # dvdauthor -o "$dvd_dir" -x "$outdir/vmgm.xml" >> "$logfile" 2>&1
2041 dvdauthor -o "$dvd_dir" -x "$outdir/vmgm.xml" 2>> "$logfile"
2042 if [ $? -ne 0 ] ; then
2043 ## dvdauthor errored
2044 myecho "[dvd-menu] ERROR during dvdauthor execution!"
2045 myecho "[dvd-menu] see $logfile for details"
2046 exit 1
2047 else
2048 myecho "[dvd-menu] dvdauthor ran ok. See logfile for details."
2049 fi
2050 fi
2051 # create iso image?
2052 if [ "$iso" -eq 1 ] ; then
2053 ## create iso image afterward:
2054 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then # VCD
2055 echo "supposed to create vcd image"
2056 else
2057 myecho "[dvd-menu] Creating iso image dvd.iso"
•2058 genisoimage -dvd-video -udf -o dvd.iso "$dvd_dir"
2059 if [ $? -ne 0 ] ; then
•2060 ## genisoimage errored
2061 myecho "[dvd-menu] ERROR during genisoimage execution!"
2062 myecho "[dvd-menu] see $logfile for details"
2063 exit 1
2064 fi
2065 fi
2066 fi
2067 else
2068 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then # VCD
2069 myecho "[dvd-menu] Not running vcdimager. Edit the vmgm.xml file"
2070 myecho "[dvd-menu] if you wish, and then run vcdimager: "
2071 myecho "[dvd-menu] vcdimager vmgm.xml"
2072 echo " "
2073 else
2074 myecho "[dvd-menu] Not running dvdauthor. Edit the vmgm.xml file"
2075 myecho "[dvd-menu] if you wish, and then run dvdauthor: "
2076 myecho "[dvd-menu] dvdauthor -x vmgm.xml"
2077 echo " "
2078 fi
2079 fi
2080
2081 if [ "$nocleanup" -eq 0 ] ; then
2082 cleanup
2083 fi
2084 # cleanup the logfile a little bit:
2085 sed -e '/ bytes of data written[[:cntrl:]]INFO/d' "$logfile" > "$outdir"/tmp.txt
2086 mv "$outdir"/tmp.txt "$logfile"
2087
2088 export VIDEO_FORMAT="$original_video_format"
2089
2090 echo "[dvd-menu] Output directory is $outdir"
2091 echo "[dvd-menu] Logfile output is at $logfile"
2092
2093 if [ "$vcd" -eq 1 ] || [ "$svcd" -eq 1 ] ; then
2094 echo "[dvd-menu] The vcd output is "
2095 echo "[dvd-menu] "
2096 echo "[dvd-menu] You can play this video using one of the following commands:"
2097 echo "[dvd-menu] xine -g vcd:\"$dvd_dir\""
2098 echo "[dvd-menu] "
2099 echo "[dvd-menu] or, if you just want to watch the videos without the menus:"
2100 echo "[dvd-menu] mplayer -sid 0 vcd:// -dvd-device $dvd_dir"
2101 echo "[dvd-menu] "
2102 echo "[dvd-menu] Burn the video cd using:"
2103 echo "[dvd-menu] cdrdao write --device ATA:1,0,0 videocd.cue"
2104 else
2105 echo "[dvd-menu] The dvd filesystem is $dvd_dir"
2106 echo "[dvd-menu] "
2107 echo "[dvd-menu] You can play this video using one of the following commands:"
2108 echo "[dvd-menu] totem $dvd_dir"
2109 echo "[dvd-menu] vlc dvd://$dvd_dir"
2110 echo "[dvd-menu] gxine -S dvd:\"$dvd_dir\""
2111 echo "[dvd-menu] xine -g -u 0 dvd:\"$dvd_dir\""
2112 echo "[dvd-menu] "
2113 fi
2114 myecho "[dvd-menu] Done!"
2115 echo