5
# version $Id: makemenu 2220 2007-07-27 02:21:46Z wapcaplet88 $
7
# Part of the tovid suite
8
# =======================
9
# A bash script for generating menus for use with DVD, VCD, or SVCD.
10
# Given a background image and a list of titles, and an optional audio
11
# file to use as background music, this script produces an MPEG video
12
# displaying the specified text, with subtitle-multiplexed menu
13
# highlights (for DVD) or enumerated titles (for (S)VCD).
15
# Project homepage: http://www.tovid.org
18
# Copyright (C) 2005 tovid.org <http://www.tovid.org>
20
# This program is free software; you can redistribute it and/or
21
# modify it under the terms of the GNU General Public License
22
# as published by the Free Software Foundation; either
23
# version 2 of the License, or (at your option) any later
26
# This program is distributed in the hope that it will be useful,
27
# but WITHOUT ANY WARRANTY; without even the implied warranty of
28
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
# GNU General Public License for more details.
31
# You should have received a copy of the GNU General Public License
32
# along with this program; if not, write to the Free Software
33
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Or see:
35
# http://www.gnu.org/licenses/gpl.txt
39
# font color, highlight color, selection color
41
# icons, graphic overlays
42
# Support for full-motion video menus
44
SCRIPT_NAME=`cat << EOF
45
--------------------------------
47
A script to generate DVD/(S)VCD menus
48
Part of the tovid suite, version $TOVID_VERSION
50
--------------------------------
54
Usage: makemenu [OPTIONS] "Title1" "Title2" ... -out {output prefix}
58
-pal | -ntsc | -ntscfilm Set TV standard
59
-dvd | -vcd | -svcd Encode to standard format
60
-background IMAGE ex: -background star_field.png
61
-audio AUDIOFILE ex: -audio foo_fighters.mp3
62
-font "FONTNAME" ex: -font Courier
66
makemenu -background ocean.jpg "First" "Second" "Third" -out mymenu
67
Create 'mymenu.mpg' with three titles and a custom background image.
69
See the makemenu manual page ('man makemenu') for additional documentation.
73
# Defaults and function definitions
75
# Print script name, usage notes, and optional error message, then exit.
76
# Args: $@ == text string containing error message
79
printf "%s\n" "$USAGE"
80
printf "%s\n" "$SEPARATOR"
81
printf "*** %s\n" "$@"
85
# Clean up the temporary files
89
echo "Leaving temporary files in $TMP_DIR"
90
echo "Debugging log saved to $LOG_FILE"
92
echo "Cleaning up... "
100
# No background image or audio
113
OVER_MAX_TITLES=false
114
# Scale up and crop non-4:3 images by default
116
# Colors for menu items (RGB)
118
HIGHLIGHT_COLOR="yellow"
120
# Default title font and point size
121
TITLE_FONT="Helvetica"
123
FONT_DECO="-stroke black -strokewidth 1"
124
TEXT_ALIGN="northwest"
125
# Default menu title settings
138
MPEG2ENC_SYS="-F 4 -n n"
139
# Figure out what version of ppmtoy4m is in use;
140
# mjpegtools 1.6.2 seems to require 420_mpeg2
141
if mplex 2>&1 | grep -q "version 1.6.2"; then
142
CHROMA_MODE="420_mpeg2"
144
CHROMA_MODE="420mpeg2"
146
PPM_OPTS="-S $CHROMA_MODE -A 10:11 -F 30000:1001"
147
# Direct stuff to /dev/null
149
# Not doing debugging
152
# Don't overwrite output files
155
LOG_FILE="makemenu.log"
157
# How far to space titles and buttons
158
TITLE_BOTTOM_SPACE=12
162
# =========================================================================\
163
# E X E C U T I O N B E G I N S H E R E
169
assert_dep "$magick" "You are missing dependencies required for making menus!"
171
# Process all options
172
while test $# -gt 0; do
174
"-ntsc" | "-ntscfilm" )
176
MPEG2ENC_SYS="-F 4 -n n"
177
PPM_OPTS="-S $CHROMA_MODE -A 10:11 -F 30000:1001"
182
MPEG2ENC_SYS="-F 3 -n p"
183
PPM_OPTS="-S $CHROMA_MODE -A 59:54 -F 25:1"
209
# Make sure file exists
210
if test -f "$1"; then
213
usage_error "Can't find background audio file: $1"
218
# Make sure file exists
219
if test -f "$1"; then
222
usage_error "Can't find background image file: $1"
225
"-overwrite" ) OVERWRITE=: ;;
226
"-crop" ) SCALECROP="crop" ;;
227
"-scale" ) SCALECROP="scale" ;;
228
"-nosafearea" ) SAFE_AREA=false ;;
256
"left" ) TEXT_ALIGN="northwest" ;;
257
"right" ) TEXT_ALIGN="northeast" ;;
258
"center" ) TEXT_ALIGN="north" ;;
259
"middle" ) TEXT_ALIGN="center" ;;
260
* ) TEXT_ALIGN=$(echo "$1" | tr A-Z a-z)
267
BUTTON_FONT="Webdings"
271
BUTTON_FONT="Webdings"
272
OFFICIAL_PRINTF=$(which printf)
273
BUTTON_CHAR=$($OFFICIAL_PRINTF '\u00b8')
277
OFFICIAL_PRINTF=$(which printf)
278
BUTTON_CHAR=$($OFFICIAL_PRINTF "\u$1")
282
if test $(echo -n "$BUTTON_CHAR" | wc -c ) -ne 1; then
283
usage_error "Buttons must have only _one_ characater."
299
"-noask" ) NOASK=: ;;
313
"-menu-title-fontsize" )
321
# Assume anything in quotes is a video title
323
TITLES=("${TITLES[@]}" "$1")
326
test -n "$1" && usage_error "Unrecognized command-line option: $1"
330
# Get the next argument
334
NUM_TITLES=${#TITLES[@]}
335
# If no titles were provided, exit with error
336
if test $NUM_TITLES -eq 0; then
337
usage_error "Please provide at least one title string, enclosed in double-quotes."
340
# If output prefix was not provided, exit with error
341
if test -z "$OUT_PREFIX"; then
342
usage_error "Please provide an output prefix with the -out option."
345
# Make sure we're not overwriting an existing menu
346
if test -f "$OUT_PREFIX.mpg"; then
348
rm -f "$OUT_PREFIX.mpg"
350
echo "There is already a file named \"$OUT_PREFIX.mpg\" in this directory!"
351
echo "Use '-overwrite' to replace this file. (makemenu -overwrite ...)"
358
OUT_FILENAME="$OUT_PREFIX.mpg"
359
# Temporary directory named after the given -out prefix
360
OUTNAME=$(basename "$OUT_PREFIX")
361
TMP_DIR=$(tempdir "$WORKING_DIR/$OUTNAME")
362
$DEBUG && echo "Storing temporary files in $TMP_DIR"
363
BG_CANVAS="$TMP_DIR/bg_canvas.png"
364
MENU_PPM="$TMP_DIR/menu.ppm"
365
MENU_MPEG="$TMP_DIR/menu.mpg"
366
SPUMUX_XML="$TMP_DIR/menu_buttons.xml"
368
SELECT_PNG="$TMP_DIR/select.png"
369
HIGHLIGHT_PNG="$TMP_DIR/highlight.png"
370
TILE_CANVAS="$TMP_DIR/00_tile_canvas.png"
371
BUTTON_PAD="$TMP_DIR/00_button_pad.png"
372
BUTTON_PLACEHOLDER="$TMP_DIR/00_button-placeholder.png"
373
HIGHLIGHT_BUTTON="$TMP_DIR/00_highlight-button.png"
374
SELECT_BUTTON="$TMP_DIR/00_select-button.png"
375
HIGHLIGHT_TEXT="$TMP_DIR/02_highlight-text.png"
376
MENU_TEXT="$TMP_DIR/02_menu-text.png"
377
SAFETY_CANVAS="$TMP_DIR/02_safety-canvas.png"
378
SELECT_TEXT="$TMP_DIR/02_select-text.png"
379
ACTIVE_TEXT="$TMP_DIR/03_active-text.png"
380
ACTIVE_HIGHLIGHT="$TMP_DIR/03_active-highlight.png"
381
ACTIVE_SELECT="$TMP_DIR/03_active-select.png"
382
MENU_TITLE_TEXT="$TMP_DIR/02_menu-title.png"
383
MENU_TITLE_PLACEHOLDER="$TMP_DIR/02_menu-title-placeholder.png"
385
# Use appropriate settings for DVD
386
if test $RES = "dvd"; then
387
assert_dep "$dvd" "You are missing dependencies required for making DVD menus!"
390
test $TVSYS = "ntsc" && HEIGHT="480"
391
test $TVSYS = "pal" && HEIGHT="576"
396
test $TVSYS = "ntsc" && HEIGHT="240"
397
test $TVSYS = "pal" && HEIGHT="288"
398
# Reduce font size and spacing
399
TITLE_SIZE=$(expr $TITLE_SIZE \/ 2)
402
# Set audio stream format
403
if test "$RES" = "dvd"; then
408
VIDEO_STREAM="$TMP_DIR/video.$VSUF"
409
AUDIO_STREAM="$TMP_DIR/audio.$ASUF"
411
# Make sure there are 9 or fewer titles for VCD and 36 or fewere for DVD
412
if test "$RES" = "vcd" && test "$NUM_TITLES" -gt $MAX_VCD_TITLES; then
415
MAX_TITLES=$MAX_VCD_TITLES
416
elif test "$RES" = "dvd" && test "$NUM_TITLES" -gt $MAX_DVD_TITLES; then
419
MAX_TITLES=$MAX_DVD_TITLES
421
if $OVER_MAX_TITLES; then
423
echo "I read $NUM_TITLES titles for your $DISC_TYPE menu, which is more than the maximum number"
424
echo "of titles allowed on one menu for ${DISC_TYPE}s ($MAX_TITLES is the limit)."
425
echo "Please try using fewer titles on this menu."
430
# Use a foreground canvas the size of the background minus safe area
432
FG_WIDTH=$(expr $WIDTH \* 4 \/ 5)
433
FG_HEIGHT=$(expr $HEIGHT \* 4 \/ 5)
435
FG_WIDTH=$(expr $WIDTH \- 10)
436
FG_HEIGHT=$(expr $HEIGHT \- 10)
439
# If no button font was given with -button-font, default to the title font
440
if test -z "$BUTTON_FONT"; then
441
BUTTON_FONT=$TITLE_FONT
444
# Confirm the title font, or use a similar one
445
if test -s "$TITLE_FONT"; then
446
# Using ttf font file for ImageMagick
447
USE_TITLE_FONT="$TITLE_FONT"
449
# Check to see if the given font name is available in ImageMagick
450
# (only return the first exact match)
451
USE_TITLE_FONT=$( convert -list type | \
452
grep -m 1 "$TITLE_FONT" | awk '{print $1}' )
454
# If not available, try to use something similar
455
if test -z $USE_TITLE_FONT ; then
457
echo "Font: \"$TITLE_FONT\" does not appear to be either a font file or registered with ImageMagick."
458
USE_TITLE_FONT=$( convert -list type | \
459
grep -i -m 1 "${TITLE_FONT:0:20}" | awk '{print $1}' )
461
# If a similarly-named one does't exist, default to Helvetica
462
if test -z "$USE_TITLE_FONT"; then
463
echo "A similarly-named font was not found. Sorry!"
464
USE_TITLE_FONT="Helvetica"
466
echo "The font \"$USE_TITLE_FONT\" will be used instead."
471
# Set the title font with the one that was found/compatible
472
TITLE_FONT="$USE_TITLE_FONT"
474
# Confirm the button font and button's existance in the font
475
if test $RES = 'dvd'; then
476
# Confirm the button font, or use a similar one
477
if test -s "$BUTTON_FONT"; then
478
# Using ttf font file for ImageMagick
479
USE_BUTTON_FONT="$BUTTON_FONT"
481
# Check to see if the given button font is available in ImageMagick
482
# (only return the first exact match)
483
USE_BUTTON_FONT=$( convert -list type | \
484
grep -m 1 "$BUTTON_FONT" | awk '{print $1}' )
486
# If not available, try to use something similar
487
if test -z $USE_BUTTON_FONT ; then
489
echo "Button: \"$BUTTON_FONT\" does not appear to be either a font file or registered with ImageMagick."
490
USE_BUTTON_FONT=$( convert -list type | \
491
grep -i -m 1 "${BUTTON_FONT:0:20}" | awk '{print $1}' )
493
# If a similarly-named one does't exist, default to Helvetica
494
if test -z "$USE_BUTTON_FONT"; then
495
echo "A similarly-named font was not found. Sorry!"
496
USE_BUTTON_FONT="$TITLE_FONT"
498
echo "The font \"$USE_BUTTON_FONT\" will be used instead."
503
# Confirm that the button character exists in the font
504
if convert -size 720x200 xc:none -fill white \
505
-font $USE_BUTTON_FONT -pointsize $TITLE_SIZE -weight bold \
506
+antialias -annotate +20+80 "$BUTTON_CHAR" -trim +repage \
507
-bordercolor none -border 10 info: >> /dev/null 2>&1; then :
510
echo "The button \"$BUTTON_CHAR\" doesn't exist in \"$USE_BUTTON_FONT\""
511
USE_BUTTON_FONT="$TITLE_FONT"
512
echo "The font \"$USE_BUTTON_FONT\" will be used instead."
517
# Set the button font with the one that was found/compatible
518
BUTTON_FONT="$USE_BUTTON_FONT"
520
# ==========================================================================\
521
# M E N U D R A W I N G
525
# Measure the font's vertical height
526
TILE_HEIGHT=$(convert -size 720x200 xc:none -fill white -pointsize $TITLE_SIZE -font $TITLE_FONT -antialias $FONT_DECO -annotate +20+80 "Al" -trim +repage info: | awk '{print $3}' | awk -F 'x' '{print $2}')
528
let "TILE_HEIGHT=TILE_HEIGHT+TITLE_BOTTOM_SPACE"
530
# Make text 'tiles' for each title. These will be pieced together later on.
531
echo "Adding $NUM_TITLES titles to the menu:"
532
for ((i=0; i<$NUM_TITLES; i++)); do
533
SEQNUM=$(printf "%02d" ${i})
535
echo " $j: ${TITLES[i]}"
536
# Enumerate (S)VCD titles
537
if test $RES = "vcd" ; then
538
ENTRY="${j}. ${TITLES[i]}"
540
# Get the width of text and pad it
541
TILE_WIDTH=$(convert -size 720x200 xc:none -fill $TEXT_COLOR -pointsize $TITLE_SIZE -font $TITLE_FONT -antialias $FONT_DECO -annotate +20+80 "$ENTRY" -trim +repage info: | awk '{print $3}' | awk -F 'x' '{print $1}')
542
let "TILE_WIDTH=TILE_WIDTH+TITLE_LEFT_SPACE"
544
# Draw the text, and put it on a blank tile
545
convert -size 720x100 xc:none -font $TITLE_FONT -antialias $FONT_DECO -fill $TEXT_COLOR -pointsize $TITLE_SIZE -annotate +20+80 "$ENTRY" -trim +repage "$TMP_DIR/01_entry-$SEQNUM.png"
546
convert -size ${TILE_WIDTH}x${TILE_HEIGHT} xc:none "$TILE_CANVAS"
547
composite -compose Over -gravity north "$TMP_DIR/01_entry-$SEQNUM.png" \
548
"$TILE_CANVAS" "$TMP_DIR/01_entry-$SEQNUM.png"
550
# Use a highlight cursor for DVD titles (drawn later, for now just text)
554
# Get the width of the text and pad it
555
TILE_WIDTH=$(convert -size 720x200 xc:none -fill $TEXT_COLOR -pointsize $TITLE_SIZE -font $TITLE_FONT -antialias $FONT_DECO -annotate +20+80 "$ENTRY" -trim +repage info: | awk '{print $3}' | awk -F 'x' '{print $1}')
556
let "TILE_WIDTH=TILE_WIDTH+TITLE_LEFT_SPACE"
558
# Draw the text, and put it on a blank tile
559
convert -size 720x100 xc:none -font $TITLE_FONT -antialias $FONT_DECO -fill $TEXT_COLOR -pointsize $TITLE_SIZE -annotate +20+80 "$ENTRY" -trim +repage "$TMP_DIR/00_title-$SEQNUM.png"
560
convert -size ${TILE_WIDTH}x${TILE_HEIGHT} xc:none "$TILE_CANVAS"
561
composite -compose Over -gravity northeast \
562
"$TMP_DIR/00_title-$SEQNUM.png" "$TILE_CANVAS" \
563
"$TMP_DIR/00_title-$SEQNUM.png"
565
# Blank placeholder: no font decorations or color
566
DIMS=$(identify "$TMP_DIR/00_title-$SEQNUM.png" | grep -o -e " [0-9]\{1,\}x[0-9]\{1,\} " | tr -d ' ')
568
-size $DIMS xc:none "$TMP_DIR/00_title-${SEQNUM}_placeholder.png"
572
# Finish DVD menu entries (all we have so far is text, no buttons!)
573
if test $RES = "dvd"; then
574
echo "Making the DVD buttons... "
576
# Get the dimensions of the button
577
TILE_WIDTH=$(convert -size 720x200 xc:none -fill white -stroke $BTN_STROKE -strokewidth 1 -pointsize $TITLE_SIZE -font $BUTTON_FONT +antialias -weight bold -annotate +20+80 "$BUTTON_CHAR" -trim +repage info: | awk '{print $3}' | awk -F 'x' '{print $1}')
578
BUTTON_HEIGHT=$(convert -size 720x200 xc:none -fill white -stroke $BTN_STROKE -strokewidth 1 -pointsize $TITLE_SIZE -font $BUTTON_FONT +antialias -weight bold -annotate +20+80 "$BUTTON_CHAR" -trim +repage info: | awk '{print $3}' | awk -F 'x' '{print $2}')
580
# Find how much to pad the top of the button and make the pad
581
let "BUTTON_PADDING=(TILE_HEIGHT-BUTTON_HEIGHT-TITLE_BOTTOM_SPACE)/2"
582
convert -size ${TILE_WIDTH}x${BUTTON_PADDING} xc:none "$BUTTON_PAD"
585
convert -size 720x100 xc:none -font $BUTTON_FONT -stroke $BTN_STROKE -strokewidth 1 +antialias -weight bold -fill $HIGHLIGHT_COLOR -pointsize $TITLE_SIZE -annotate +20+80 "$BUTTON_CHAR" -trim +repage "$HIGHLIGHT_BUTTON"
586
convert -size 720x100 xc:none -font $BUTTON_FONT -stroke $BTN_STROKE -strokewidth 1 +antialias -weight bold -fill $SELECT_COLOR -pointsize $TITLE_SIZE -annotate +20+80 "$BUTTON_CHAR" -trim +repage "$SELECT_BUTTON"
588
# Pad the buttons so that they line up with the font's baseline
589
convert -background none "$BUTTON_PAD" "$HIGHLIGHT_BUTTON" -append \
591
convert -background none "$BUTTON_PAD" "$SELECT_BUTTON" -append \
594
# Make a blank button tile according to measured dimensions
595
convert -size ${TILE_WIDTH}x${TILE_HEIGHT} xc:none "$TILE_CANVAS"
597
# Put padded buttons on the blank tile
598
composite -compose Over -gravity north "$HIGHLIGHT_BUTTON" \
599
"$TILE_CANVAS" "$HIGHLIGHT_BUTTON"
600
composite -compose Over -gravity north "$SELECT_BUTTON" \
601
"$TILE_CANVAS" "$SELECT_BUTTON"
603
# A placeholder to space the title text correctly
604
DIMS=$(identify "$HIGHLIGHT_BUTTON" | grep -o -e " [0-9]\{1,\}x[0-9]\{1,\} " | tr -d ' ')
605
convert -size $DIMS xc:none "$BUTTON_PLACEHOLDER"
607
# Next, join the button tiles with the title tiles:
609
while test $i -lt $NUM_TITLES; do
610
SEQNUM=$(printf "%02d" $i)
612
convert -background none "$BUTTON_PLACEHOLDER" \
613
"$TMP_DIR/00_title-$SEQNUM.png" +append \
614
"$TMP_DIR/01_entry-$SEQNUM.png"
616
convert -background none "$HIGHLIGHT_BUTTON" \
617
"$TMP_DIR/00_title-${SEQNUM}_placeholder.png" \
618
+append "$TMP_DIR/01_highlight_entry-$SEQNUM.png"
620
convert -background none "$SELECT_BUTTON" \
621
"$TMP_DIR/00_title-${SEQNUM}_placeholder.png" \
622
+append "$TMP_DIR/01_select_entry-$SEQNUM.png"
627
# Stack all 01_entry-N.png lines
628
echo "Creating the text menu... "
629
convert -background none "$TMP_DIR/01_entry-*.png" -append "$MENU_TEXT"
631
# Stack all DVD button lines
632
if test $RES = "dvd"; then
633
echo "Creating the DVD button overlays... "
634
convert -background none "$TMP_DIR/01_highlight_entry-*.png" -append \
636
convert -background none "$TMP_DIR/01_select_entry-*.png" -append \
640
# If specified, add a menu title
642
echo "Adding the menu title..."
644
# Default title font size = current text size + 4
645
if test -z "$MENU_TITLE_SIZE"; then
646
let "MENU_TITLE_SIZE=TITLE_SIZE+8"
649
# Draw the menu title and pad the bottom with TILE_HEIGHT pixels
650
convert -size 720x100 xc:none -font $TITLE_FONT -antialias $FONT_DECO -fill $TEXT_COLOR -pointsize $MENU_TITLE_SIZE -annotate +20+80 "$MENU_TITLE" -trim +repage "$MENU_TITLE_TEXT"
651
convert "$MENU_TITLE_TEXT" -gravity south -background none -splice 0x$TILE_HEIGHT "$MENU_TITLE_TEXT"
653
# Put the menu title above the menu text (and buttons for DVDs)
654
convert -background none "$MENU_TITLE_TEXT" "$MENU_TEXT" -append \
656
if test $RES = "dvd"; then
657
# DVD menus need an empty placeholder for the buttons
658
DIMS=$(identify "$MENU_TITLE_TEXT" | grep -o -e " [0-9]\{1,\}x[0-9]\{1,\} " | tr -d ' ')
659
convert -size $DIMS xc:none "$MENU_TITLE_PLACEHOLDER"
660
convert -background none "$MENU_TITLE_PLACEHOLDER" "$HIGHLIGHT_TEXT" \
661
-append "$HIGHLIGHT_TEXT"
662
convert -background none "$MENU_TITLE_PLACEHOLDER" "$SELECT_TEXT" \
663
-append "$SELECT_TEXT"
668
# Put the text menus inside the safety area
669
if $SAFE_AREA; then FRAME_TYPE="safe area"; else FRAME_TYPE="frame"; fi
670
echo "Placing text menu in the $FRAME_TYPE... "
671
convert -size ${FG_WIDTH}x${FG_HEIGHT} xc:none "$SAFETY_CANVAS"
672
composite -compose Over -gravity $TEXT_ALIGN \
673
"$MENU_TEXT" "$SAFETY_CANVAS" "$ACTIVE_TEXT"
675
# Same for DVD buttons: into the safety area
676
if test $RES = 'dvd'; then
677
echo "Placing DVD buttons in the $FRAME_TYPE... "
678
composite -compose Over -gravity $TEXT_ALIGN \
679
"$HIGHLIGHT_TEXT" "$SAFETY_CANVAS" "$ACTIVE_HIGHLIGHT"
680
composite -compose Over -gravity $TEXT_ALIGN \
681
"$SELECT_TEXT" "$SAFETY_CANVAS" "$ACTIVE_SELECT"
685
# If none was provided, create a default one (blue-black gradient)
686
if test -z "$BG_IMAGE"; then
687
BG_CMD="convert -size ${WIDTH}x${HEIGHT} gradient:blue-black \
688
-gravity center -matte \"$BG_CANVAS\""
689
# Otherwise, scale/crop the provided image
691
if test "$SCALECROP" = "crop"; then
692
SCALECROP="-resize ${WIDTH}x -resize \"x${HEIGHT}<\" -gravity center \
693
-crop ${WIDTH}x${HEIGHT}+0+0"
695
SCALECROP="-resize ${WIDTH}x${HEIGHT}!"
697
BG_CMD="convert \"$BG_IMAGE\" $SCALECROP -matte \"$BG_CANVAS\""
699
echo "Working on the background... "
700
$DEBUG && echo -e "\n\nBackground:\n$BG_CMD" >> $REDIR
703
# Put menu text over the background image
704
MAGICK_CMD="composite -compose Over -gravity center \
705
\"$ACTIVE_TEXT\" \"$BG_CANVAS\" -depth 8 \"$MENU_PPM\""
706
echo "Centering the $FRAME_TYPE over the background... "
707
$DEBUG && echo -e "\n\nMenu Text:\n$MAGICK_CMD" >> $REDIR
711
if test $RES = 'dvd'; then
712
echo "Positioning the DVD button overlays on the background... "
713
composite -compose Src -gravity center \
714
"$ACTIVE_HIGHLIGHT" "$BG_CANVAS" "$HIGHLIGHT_PNG"
715
composite -compose Src -gravity center \
716
"$ACTIVE_SELECT" "$BG_CANVAS" "$SELECT_PNG"
720
# ======================================================================\
721
# P R E V I E W & F I N I S H
726
echo "Generating preview..."
727
echo "Type 'q' to close the preview window."
728
if test "$RES" = vcd; then
731
composite -compose Over -gravity center "$HIGHLIGHT_PNG" \
732
"$MENU_PPM" miff: | display
735
echo -n "Was the preview ok [y/N]? "
738
if ! ( test "$ANSWER" = "y" || test "$ANSWER" = "Y" ); then
739
echo "Preview was not OK, exiting..."
742
echo "Try: -font FONT -fontsize NUM -textcolor '#RGB'"
743
echo " -fontdeco 'ImageMagick instr' -align left|center|right"
744
echo " -background IMAGE -audio AUDIOFILE"
745
echo "to change the appearance. More in 'man makemenu'"
748
echo "Preview was OK. Continuing..."
753
# If no background audio was provided, generate 4 seconds of silence
754
if test -z "$BG_AUDIO"; then
755
if test -z "$MENU_LENGTH"; then
758
echo "Creating $(echo "$MENU_LENGTH" | cut -c 4-)-second silent $ASUF audio... "
759
AUDIO_CMD="ffmpeg -f s16le -i /dev/zero -ac 2 -ar $SAMPRATE -ab 224k \
760
$MENU_LENGTH -acodec $ASUF -y \"$AUDIO_STREAM\""
761
$DEBUG && echo -e "\n\nBG audio:\n$AUDIO_CMD" >> $REDIR
762
eval $AUDIO_CMD >> $REDIR 2>&1
763
# Otherwise, convert provided audio to the target format
765
echo "Converting \"$BG_AUDIO\" to $ASUF... "
766
AUDIO_CMD="ffmpeg -i \"$BG_AUDIO\" -ac 2 -ar $SAMPRATE -ab 224k \
767
$MENU_LENGTH -acodec $ASUF -y \"$AUDIO_STREAM\""
768
$DEBUG && echo -e "\n\nBG audio:\n$AUDIO_CMD" >> $REDIR
769
eval $AUDIO_CMD >> $REDIR 2>&1
772
# Calculate video length from length of audio
773
VID_LENGTH=$(mplayer -quiet -identify -frames 0 -vo null -ao null \
774
"$AUDIO_STREAM" 2>&1 | grep '^ID_LENGTH' | awk -F '=' '{print $2}' | \
775
sed -e "s/\.[0-9]*//g")
776
VID_LENGTH=$(expr $VID_LENGTH \* $FPS \/ 100)
778
# Make sure VID_LENGTH is nonzero
779
if test $VID_LENGTH -eq 0 ; then
780
# Use 30 seconds as a sensible default
781
VID_LENGTH=$(expr 30 \* $FPS \/ 100)
784
# Make video of specified length from PPM background image
785
echo "Converting menu image to video. This may take a while... "
786
VIDEO_CMD="ppmtoy4m $PPM_OPTS -n $VID_LENGTH -r \"$MENU_PPM\" 2>>$REDIR | \
787
mpeg2enc -a 2 $MPEG2ENC_FMT $MPEG2ENC_SYS -o \"$VIDEO_STREAM\" >> $REDIR 2>&1"
788
$DEBUG && echo -e "\n\nTo mpeg:\n$VIDEO_CMD" >> $REDIR
791
# Multiplex audio and video
792
echo "Multiplexing video and audio streams... "
793
MPLEX_CMD="mplex $MPLEX_OPTS $MPEG2ENC_FMT -o \"$MENU_MPEG\" \
794
\"$VIDEO_STREAM\" \"$AUDIO_STREAM\" >> $REDIR 2>&1"
795
$DEBUG && echo -e "\n\nMux:\n$MPLEX_CMD" >> $REDIR
798
# For DVD, create spumux XML
799
if test "$RES" = "dvd"; then
804
<spu force="yes" start="00:00:00.00"
805
highlight="$HIGHLIGHT_PNG"
814
SPUMUX_CMD="spumux \"$SPUMUX_XML\" < \"$MENU_MPEG\" > \"$OUT_FILENAME\" 2>>$REDIR"
815
echo "Adding the DVD buttons to menu... "
816
$DEBUG && echo -e "\n\nSpumux buttons:\n$SPUMUX_CMD" >> $REDIR
819
# Rename the output menu for VCD and SVCD
821
mv "$MENU_MPEG" "$OUT_FILENAME"
827
if test -s "$OUT_FILENAME"; then
829
echo "Finished! Your menu should be in the file \"$OUT_FILENAME\"."
830
if test "$RES" = "vcd"; then
831
echo "You can use this menu on an SVCD or VCD disc with:"
833
echo " makexml -vcd -menu \"$OUT_FILENAME\" <title 1> <title 2> ... \\"
834
echo " <output name>"
836
echo "You can use this menu on a DVD disc with:"
838
echo " makexml -dvd -menu \"$OUT_FILENAME\" <title 1> <title 2> ... \\"
839
echo " -out <output name>"
843
echo "where <title N> is an MPEG video file corresponding to title N as listed"
844
echo "on your menu. Run 'makexml' without any options for more usage information."
849
echo "It looks like something went wrong, because there is no output file."
850
echo "Please submit a bug report on the tovid homepage: add -debug to your"
851
echo "command (makemenu -debug ...) and post the log file and terminal"
852
echo "output. Sorry for the inconvenience. http://www.tovid.org"
856
$QUIET || echo $SEPARATOR
857
$QUIET || echo "Thanks for using makemenu!"