~ubuntu-branches/ubuntu/karmic/tovid/karmic

« back to all changes in this revision

Viewing changes to src/makexml

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2008-01-24 22:04:40 UTC
  • Revision ID: james.westby@ubuntu.com-20080124220440-x7cheljduf1rdgnq
Tags: upstream-0.31
ImportĀ upstreamĀ versionĀ 0.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
ME="[makexml]:"
 
3
. tovid-init
 
4
 
 
5
# makexml
 
6
# Part of the tovid suite
 
7
# =======================
 
8
# This bash script generates XML output describing the structure of
 
9
# a VCD, SVCD, or DVD disc. The resulting output can be given as input
 
10
# to vcdxbuild or dvdauthor. Format, and a list of menus and
 
11
# video files in MPEG format, are specified on the command-line, and
 
12
# the resulting XML is written to the specified file. Currently
 
13
# supports an optional top-level menu, any number of optional sub-menus,
 
14
# and any number of videos reachable through those menus.
 
15
#
 
16
# Project homepage: http://www.tovid.org
 
17
#
 
18
#
 
19
# Copyright (C) 2005 tovid.org <http://www.tovid.org>
 
20
#
 
21
# This program is free software; you can redistribute it and/or
 
22
# modify it under the terms of the GNU General Public License
 
23
# as published by the Free Software Foundation; either
 
24
# version 2 of the License, or (at your option) any later
 
25
# version.
 
26
#
 
27
# This program is distributed in the hope that it will be useful,
 
28
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
29
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
30
# GNU General Public License for more details.
 
31
#
 
32
# You should have received a copy of the GNU General Public License
 
33
# along with this program; if not, write to the Free Software
 
34
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Or see:
 
35
#
 
36
#           http://www.gnu.org/licenses/gpl.txt
 
37
 
 
38
SCRIPTNAME=`cat << EOF
 
39
--------------------------------
 
40
makexml
 
41
A script to generate XML for authoring a VCD, SVCD, or DVD.
 
42
Part of the tovid suite, version $TOVID_VERSION
 
43
$TOVID_HOME_PAGE
 
44
--------------------------------
 
45
EOF`
 
46
 
 
47
USAGE=`cat << EOF
 
48
Usage:  makexml [OPTIONS] {video1.mpg video2.mpg ...} -out OUT_PREFIX
 
49
 
 
50
Common OPTIONS:
 
51
 
 
52
    -dvd | -vcd | -svcd       Specify the target disc format
 
53
    -overwrite                Overwrite any existing output files
 
54
 
 
55
Provide a list of .mpg video files, and they will be played back in
 
56
sequence. You may organize several lists of videos into menus by
 
57
providing the name of a menu .mpg:
 
58
 
 
59
    makexml -menu menu1.mpg \\\\
 
60
        video1.mpg video2.mpg video3.mpg \\\\
 
61
        -out mydisc
 
62
    makexml -topmenu topmenu.mpg \\\\
 
63
        -menu submenu1.mpg vid1.mpg vid2.mpg vid3.mpg \\\\
 
64
        -menu submenu2.mpg vid4.mpg vid5.mpg vid6.mpg \\\\
 
65
        -out mydisc2
 
66
 
 
67
See the makexml manual page ('man makexml') for additional documentation.
 
68
 
 
69
EOF`
 
70
 
 
71
SEPARATOR="=========================================="
 
72
 
 
73
# Print script name, usage notes, and optional error message, then exit.
 
74
# Args: $1 == text string containing error message
 
75
usage_error ()
 
76
{
 
77
  echo "$USAGE"
 
78
  echo $SEPARATOR
 
79
  echo "$@"
 
80
  exit 1
 
81
}
 
82
 
 
83
QUIET=false
 
84
# Currently-numbered titleset (must have at least 1 titleset)
 
85
CUR_TS=1
 
86
# Currently-numbered video title under a titleset menu (0 for no titles)
 
87
CUR_TITLE=0
 
88
# Do we have a top menu yet?
 
89
HAVE_TOP_MENU=false
 
90
# Do we have any menus yet?
 
91
HAVE_MENU=false
 
92
# Do not overwrite by default
 
93
OVERWRITE=false
 
94
# Use dvdauthor XML for DVD authoring
 
95
XML_FORMAT="dvd"
 
96
# No un-found files yet
 
97
FILE_NOT_FOUND=false
 
98
# Not doing still titles
 
99
STILL_TITLES=false
 
100
FIRST_TITLE=:
 
101
# Avoid some unbound variables
 
102
TOP_MENU_XML=""
 
103
TOP_MENU_BUTTONS=""
 
104
MENU_BUTTONS=""
 
105
TS_TITLES=""
 
106
ALL_MENU_XML=""
 
107
SEGMENT_ITEMS_XML=""
 
108
SEQUENCE_ITEMS_XML=""
 
109
PBC_XML=""
 
110
PLAYLIST_XML=""
 
111
 
 
112
MAKE_GROUP=false
 
113
MAKE_CHAPTERS=:
 
114
FORCE_TITLESETS=false
 
115
CUR_VIDEO=0
 
116
CHAPTER_INTERVAL=5
 
117
 
 
118
STANDARD=133
 
119
WIDESCREEN=177
 
120
NOPANSCAN=''
 
121
 
 
122
# ==========================================================
 
123
# Backslash-escape the given special character (and any EOLs)
 
124
# Usage:
 
125
#    sedprep "$TEXT" /
 
126
#    echo $TEXT | sed "s/PATTERN/$(sedprep "$REPLACEMENT" /)/"
 
127
function sedprep ()
 
128
{
 
129
    delim=${2:-/}
 
130
    echo "$1" |sed -e 's/[\&'"$delim"']/\\&/g' -e '$!s,$,\\,';
 
131
}
 
132
 
 
133
# ==========================================================
 
134
# Check for the existence of a file and print an error if it
 
135
# does not exist in the current directory
 
136
# Args: $1 = file to look for
 
137
function checkExistence ()
 
138
{
 
139
    if test -e "$1"; then :
 
140
    else
 
141
        echo "The file "$1" was not found.  Exiting."
 
142
        FILE_NOT_FOUND=:
 
143
        exit 1
 
144
    fi
 
145
}
 
146
 
 
147
# ==========================================================
 
148
# Find a video's aspect ratio and set dvd behavior accordingly
 
149
# Args: $1 = video file to find aspect for
 
150
# Usage: noPanScan foo.avi
 
151
# Sets NOPANSCAN to either: widescreen="nopanscan"
 
152
#                       or: <null>
 
153
function noPanScan ()
 
154
{
 
155
    ASPECT=$(idvid -fast -terse "$1" | grep "ASPECT" | awk -F '=' '{print $2}')
 
156
    $QUIET || echo -n "    $1 has aspect $ASPECT "
 
157
    if test $ASPECT -eq $WIDESCREEN; then
 
158
        NOPANSCAN='widescreen="nopanscan"'
 
159
        $QUIET || echo "(widescreen)."
 
160
    else
 
161
        NOPANSCAN=''
 
162
        $QUIET || echo "(standard)."
 
163
    fi
 
164
 
 
165
}
 
166
 
 
167
# ==========================================================
 
168
# Add a top-level VMGM menu to the DVD
 
169
# Args: $1 = video file to use for top menu
 
170
function addTopMenu ()
 
171
{
 
172
  HAVE_TOP_MENU=:
 
173
  echo "Adding top-level menu using file: $1"
 
174
 
 
175
  # --------------------------
 
176
  # For DVD
 
177
  if test $XML_FORMAT = "dvd"; then
 
178
    # Set NOPANSCAN
 
179
    noPanScan "$1"
 
180
    
 
181
    # Generate XML for the top menu, with a placeholder for
 
182
    # the titleset menu buttons (to be replaced later by sed)
 
183
    TOP_MENU_XML=`cat << EOF
 
184
  <menus>
 
185
  <video $NOPANSCAN />
 
186
  <pgc entry="title">
 
187
  <vob file="$1" />
 
188
__TOP_MENU_BUTTONS__
 
189
  </pgc>
 
190
  </menus>
 
191
EOF`
 
192
 
 
193
  # --------------------------
 
194
  # For (S)VCD
 
195
  else
 
196
 
 
197
    # Generate XML for the segment-item
 
198
    SEGMENT_ITEMS_XML=`cat << EOF
 
199
$SEGMENT_ITEMS_XML
 
200
  <segment-item src="$1" id="seg-top-menu"/>
 
201
EOF`
 
202
 
 
203
    # Generate XML for the selection to go in pbc
 
204
    TOP_MENU_XML=`cat << EOF
 
205
  <selection id="select-top-menu">
 
206
    <bsn>1</bsn>
 
207
    <loop jump-timing="immediate">0</loop>
 
208
    <play-item ref="seg-top-menu"/>
 
209
__TOP_MENU_BUTTONS__
 
210
  </selection>
 
211
EOF`
 
212
 
 
213
  fi
 
214
}
 
215
 
 
216
# ==========================================================
 
217
# Add a menu to the disc.
 
218
# Args: $1 = video file to use for the menu
 
219
function addMenu ()
 
220
{
 
221
  # --------------------------
 
222
  # For DVD
 
223
  if test $XML_FORMAT = "dvd"; then
 
224
    echo "Adding a titleset-level menu using file: $1"
 
225
 
 
226
    # Generate XML for the button linking to this titleset menu from the top menu
 
227
    TOP_MENU_BUTTONS=`cat << EOF
 
228
  $TOP_MENU_BUTTONS
 
229
    <button>jump titleset $CUR_TS menu;</button>
 
230
EOF`
 
231
 
 
232
    # Set NOPANSCAN
 
233
    noPanScan "$1"
 
234
 
 
235
    # Generate XML for the menu header, with a placeholder for
 
236
    # the video segment buttons (to be replaced later by sed)
 
237
    MENU_XML=`cat << EOF
 
238
  <menus>
 
239
    <video $NOPANSCAN />
 
240
    <pgc entry="root">
 
241
      <vob file="$1" />
 
242
__MENU_BUTTONS__
 
243
    </pgc>
 
244
  </menus>
 
245
EOF`
 
246
 
 
247
  # --------------------------
 
248
  # For (S)VCD
 
249
  else
 
250
    echo "Adding a menu using file: $1"
 
251
 
 
252
    # Generate XML for the button linking to this menu from the top menu
 
253
    TOP_MENU_BUTTONS=`cat << EOF
 
254
$TOP_MENU_BUTTONS
 
255
    <select ref="select-menu-$CUR_TS"/>
 
256
EOF`
 
257
 
 
258
    # Generate XML for the segment item
 
259
    SEGMENT_ITEMS_XML=`cat << EOF
 
260
$SEGMENT_ITEMS_XML
 
261
  <segment-item src="$1" id="seg-menu-$CUR_TS"/>
 
262
EOF`
 
263
 
 
264
    # Generate XML for the selection to go in pbc
 
265
    # If there's a top menu, "return" goes back to it.
 
266
    # Otherwise, don't use a "return" command.
 
267
    if $HAVE_TOP_MENU; then
 
268
      RETURN_CMD="<return ref=\"select-top-menu\"/>"
 
269
    else
 
270
      RETURN_CMD=""
 
271
    fi
 
272
    SELECTION_XML=`cat << EOF
 
273
  <selection id="select-menu-$CUR_TS">
 
274
    <bsn>1</bsn>
 
275
    $RETURN_CMD
 
276
    <loop jump-timing="immediate">0</loop>
 
277
    <play-item ref="seg-menu-$CUR_TS"/>
 
278
__MENU_BUTTONS__
 
279
  </selection>
 
280
EOF`
 
281
 
 
282
  fi
 
283
}
 
284
 
 
285
# ==========================================================
 
286
# Add a video title to a titleset menu, or a still image to
 
287
# a slideshow
 
288
# Args: $1 = video file to use for the title
 
289
function addTitle ()
 
290
{
 
291
  if $FORCE_TITLESETS && test $CUR_VIDEO -eq 0; then
 
292
    closeTitleset
 
293
  fi
 
294
  # Increment the current title number
 
295
  if ! $MAKE_GROUP; then
 
296
    (( CUR_TITLE++ ))
 
297
  else
 
298
    # Grouping several videos within one title
 
299
    if test $CUR_VIDEO -eq 0; then
 
300
       (( CUR_TITLE++ ))
 
301
    fi
 
302
    (( CUR_VIDEO++ ))
 
303
  fi
 
304
  # --------------------------
 
305
  # For DVD
 
306
  if test $XML_FORMAT = "dvd"; then
 
307
    if ! $MAKE_GROUP; then
 
308
      echo "Adding title: $1 as title number $CUR_TITLE of titleset $CUR_TS"
 
309
    else
 
310
      if test $CUR_VIDEO -eq 1; then
 
311
        echo "Adding title number $CUR_TITLE of titleset $CUR_TS"
 
312
      fi
 
313
      echo "Adding $1 as video $CUR_VIDEO of title $CUR_TITLE"
 
314
    fi
 
315
 
 
316
    # Set NOPANSCAN
 
317
    noPanScan "$1"
 
318
 
 
319
    # Generate XML for the button linking to this title from the titleset menu
 
320
    if ! $FORCE_TITLESETS; then
 
321
      if test $CUR_VIDEO -lt 2; then
 
322
        MENU_BUTTONS=`cat << EOF
 
323
$MENU_BUTTONS
 
324
        <button>jump title $CUR_TITLE;</button>
 
325
EOF`
 
326
      fi
 
327
    else
 
328
      # Add a button for the current titleset to the top menu
 
329
      if test $CUR_VIDEO -le 1; then
 
330
        TOP_MENU_BUTTONS=`cat << EOF
 
331
$TOP_MENU_BUTTONS
 
332
        <button>jump titleset $CUR_TS menu;</button>
 
333
EOF`
 
334
      fi
 
335
    fi
 
336
 
 
337
    # Generate the chapters tag
 
338
    # If file exists, get duration and add appropriate chapter breaks
 
339
    if test -e "$1" && $MAKE_CHAPTERS; then
 
340
        CMD="idvid -terse \"$1\""
 
341
        echo "    Calculating the duration of the video with:"
 
342
        echo "        $CMD"
 
343
        echo "    This may take a few minutes, so please be patient..."
 
344
        DURATION=$(eval $CMD | grep DURATION | awk -F '=' '{print $2}')
 
345
        echo $DURATION | awk '{hh=int($1/3600);mm=int(($1-hh*3600)/60);ss=$1-hh*3600-mm*60;\
 
346
            printf "    The duration of the video is %02d:%02d:%02d\n",hh,mm,ss}'
 
347
 
 
348
        CHAPTERS=`echo $DURATION $CHAPTER_INTERVAL | \
 
349
           awk '{dur=$1;\
 
350
                    iv=$2*60;\
 
351
                    if (iv==0){\
 
352
                       printf "0";\
 
353
                       exit\
 
354
                    }\
 
355
                    cur=0;\
 
356
                    i=0;\
 
357
                    while(cur<dur){\
 
358
                       if(i>0){\
 
359
                          printf ","\
 
360
                       }\
 
361
                       i++;\
 
362
                       hh=int(cur/3600);\
 
363
                       mm=int((cur-hh*3600)/60);\
 
364
                       ss=cur-hh*3600-mm*60;\
 
365
                       printf "%02d:%02d:%02d",hh,mm,ss;
 
366
                       cur+=iv\
 
367
                    }\
 
368
                }'`
 
369
    # If file doesn't exist, or -nochapters was passed, use 0 chapters
 
370
    else
 
371
        CHAPTERS="0"
 
372
    fi
 
373
 
 
374
    # Generate the XML for the title itself, appending to existing titles
 
375
    if $MAKE_GROUP; then
 
376
      if test $CUR_VIDEO -eq 1; then
 
377
        TS_TITLES=`cat << EOF
 
378
$TS_TITLES
 
379
    <pgc>
 
380
EOF`
 
381
      fi
 
382
      TS_TITLES=`cat << EOF
 
383
                 $TS_TITLES
 
384
      <vob file="$1" chapters="$CHAPTERS" />
 
385
EOF`
 
386
    else
 
387
      TS_TITLES=`cat << EOF
 
388
$TS_TITLES
 
389
    <pgc>
 
390
      <vob file="$1" chapters="$CHAPTERS" />
 
391
      __POST_CMD__
 
392
    </pgc>
 
393
EOF`
 
394
    fi
 
395
 
 
396
  # --------------------------
 
397
  # For (S)VCD
 
398
  else
 
399
 
 
400
    # If there's a menu, "return" goes back to it; if not,
 
401
    # do not generate a "return" command
 
402
    if $HAVE_MENU; then
 
403
      RETURN_CMD="<return ref=\"select-menu-$CUR_TS\"/>"
 
404
    else
 
405
      RETURN_CMD=""
 
406
    fi
 
407
    # If this is the first title or slide in a series
 
408
    if $FIRST_TITLE; then
 
409
      # For the first titles, PREV stays on the current title
 
410
      let "PREV_TITLE=$CUR_TITLE"
 
411
    # For all other titles
 
412
    else
 
413
      # PREV goes to the previous slide
 
414
      let "PREV_TITLE=$CUR_TITLE - 1"
 
415
    fi
 
416
 
 
417
    # Fill in the NEXT command for the previous slide, if there was one
 
418
    NEXT_TITLE="<next ref=\"play-title-$CUR_TITLE\"\/>"
 
419
    SELECTION_XML=$( echo "$SELECTION_XML" | sed -e "s/__NEXT_TITLE__/$NEXT_TITLE/g" )
 
420
    PLAYLIST_XML=$( echo "$PLAYLIST_XML" | sed -e "s/__NEXT_TITLE__/$NEXT_TITLE/g" )
 
421
 
 
422
    # --------------------------
 
423
    # If doing a still-image slideshow, use segment/selection
 
424
    if $STILL_TITLES; then
 
425
      echo "Adding title: $1 as number $CUR_TITLE in a slideshow"
 
426
 
 
427
      # Generate XML for the selection (menu) "buttons" that will
 
428
      # jump to this slideshow. Only the first slide gets a button.
 
429
      if $FIRST_TITLE; then
 
430
        MENU_BUTTONS=`cat << EOF
 
431
$MENU_BUTTONS
 
432
    <select ref="play-title-$CUR_TITLE"/>
 
433
EOF`
 
434
      fi
 
435
 
 
436
      # Generate XML for the segment item
 
437
      SEGMENT_ITEMS_XML=`cat << EOF
 
438
$SEGMENT_ITEMS_XML
 
439
  <segment-item src="$1" id="seg-slide-$CUR_TITLE"/>
 
440
EOF`
 
441
 
 
442
      # Generate XML for the selection to go in pbc
 
443
      # The slide will play indefinitely until NEXT, PREV,
 
444
      # or RETURN is pressed. __NEXT_TITLE__ is a placeholder
 
445
      # until we're sure there is a next slide; it will be
 
446
      # filled in on the next addition if there is.
 
447
      SELECTION_XML=`cat << EOF
 
448
$SELECTION_XML
 
449
  <playlist id="play-title-$CUR_TITLE">
 
450
    <prev ref="play-title-$PREV_TITLE"/>
 
451
    __NEXT_TITLE__
 
452
    $RETURN_CMD
 
453
    <wait>-1</wait>
 
454
    <play-item ref="seg-slide-$CUR_TITLE"/>
 
455
  </playlist>
 
456
EOF`
 
457
 
 
458
    # --------------------------
 
459
    # If doing normal video titles, use select/playlist
 
460
    else
 
461
 
 
462
      echo "Adding title: $1 as title number $CUR_TITLE"
 
463
 
 
464
      # Generate XML for the selection (menu) "buttons" that will
 
465
      # jump to this playlist (title)
 
466
      MENU_BUTTONS=`cat << EOF
 
467
$MENU_BUTTONS
 
468
    <select ref="play-title-$CUR_TITLE"/>
 
469
EOF`
 
470
 
 
471
      # Generate XML for the sequence item
 
472
      SEQUENCE_ITEMS_XML=`cat << EOF
 
473
$SEQUENCE_ITEMS_XML
 
474
  <sequence-item src="$1" id="seq-title-$CUR_TITLE"/>
 
475
EOF`
 
476
 
 
477
      # Generate XML for the playlist for this title
 
478
      PLAYLIST_XML=`cat << EOF
 
479
$PLAYLIST_XML
 
480
  <playlist id="play-title-$CUR_TITLE">
 
481
    <prev ref="play-title-$PREV_TITLE"/>
 
482
    __NEXT_TITLE__
 
483
    $RETURN_CMD
 
484
    <wait>0</wait>
 
485
    <play-item ref="seq-title-$CUR_TITLE"/>
 
486
  </playlist>
 
487
EOF`
 
488
 
 
489
    fi # (S)VCD slides or normal titles
 
490
 
 
491
  fi # DVD or (S)VCD
 
492
 
 
493
  FIRST_TITLE=false
 
494
}
 
495
 
 
496
# ==========================================================
 
497
# Finalize the XML for a titleset, containing a menu and titles
 
498
function closeTitleset ()
 
499
{
 
500
  # Proceed only if there are titles in this titleset
 
501
  if (( $CUR_TITLE > 0 )); then
 
502
 
 
503
  # --------------------------
 
504
  # For DVD
 
505
  if test $XML_FORMAT = "dvd"; then
 
506
    echo "Closing titleset $CUR_TS with $CUR_TITLE title(s)."
 
507
 
 
508
    # Give each menu a button linking back to the top menu, if there is one
 
509
    if $HAVE_TOP_MENU; then
 
510
      MENU_BUTTONS=`cat << EOF
 
511
$MENU_BUTTONS
 
512
        <button>jump vmgm menu;</button>
 
513
 
 
514
EOF`
 
515
    fi
 
516
 
 
517
    # Fill in titleset menu buttons
 
518
    MENU_XML=$(echo "$MENU_XML" | \
 
519
        sed -e "s/__MENU_BUTTONS__/$(sedprep "$MENU_BUTTONS" /)/g")
 
520
 
 
521
    # Fill in the POST command. If there is a menu to jump back to, use that;
 
522
    # otherwise, do not insert a POST command.
 
523
    if $HAVE_MENU; then
 
524
      POST_CMD="<post>call menu;<\/post>"
 
525
    elif $FORCE_TITLESETS && $HAVE_TOP_MENU; then
 
526
      POST_CMD="<post>call vmgm menu;<\/post>"
 
527
    else
 
528
      POST_CMD=""
 
529
    fi
 
530
    TS_TITLES=$( echo "$TS_TITLES" | sed -e "s/__POST_CMD__/$POST_CMD/g" )
 
531
 
 
532
    # Append titleset info to ALL_MENU_XML
 
533
    if ! $FORCE_TITLESETS || ! $HAVE_TOP_MENU; then
 
534
      ALL_MENU_XML=`cat << EOF
 
535
$ALL_MENU_XML
 
536
<titleset>
 
537
$MENU_XML
 
538
  <titles>
 
539
    <video $NOPANSCAN />
 
540
$TS_TITLES
 
541
  </titles>
 
542
</titleset>
 
543
EOF`
 
544
    else
 
545
      # One titleset for each title -> add a dummy menu to the titleset
 
546
      ALL_MENU_XML=`cat << EOF
 
547
$ALL_MENU_XML
 
548
<titleset>
 
549
  <menus>
 
550
    <pgc>
 
551
      <post>
 
552
        jump title 1;
 
553
      </post>
 
554
    </pgc>
 
555
  </menus>
 
556
  <titles>
 
557
    <video $NOPANSCAN />
 
558
$TS_TITLES
 
559
  </titles>
 
560
</titleset>
 
561
EOF`
 
562
    fi
 
563
    # Clear existing XML to prepare for next titleset
 
564
    MENU_XML=""
 
565
    TS_TITLES=""
 
566
    CUR_TITLE=0
 
567
    MENU_BUTTONS=""
 
568
 
 
569
  # --------------------------
 
570
  # For (S)VCD
 
571
  else
 
572
 
 
573
    # Fill in menu title selections ("buttons")
 
574
    # and remove any remaining __NEXT_TITLE__s
 
575
    SELECTION_XML=$(echo "$SELECTION_XML" | \
 
576
        sed -e "s/__MENU_BUTTONS__/$(sedprep "$MENU_BUTTONS" /)/g" -e "s/__NEXT_TITLE__//g")
 
577
    PLAYLIST_XML=$(echo "$PLAYLIST_XML" | sed -e "s/__NEXT_TITLE__//g")
 
578
 
 
579
    # Append new PBC menus/playlists to PBC_XML
 
580
    PBC_XML=`cat << EOF
 
581
$PBC_XML
 
582
$SELECTION_XML
 
583
$PLAYLIST_XML
 
584
 
 
585
EOF`
 
586
 
 
587
    # Clear existing XML to prepare for next menu/titles
 
588
    SELECTION_XML=""
 
589
    PLAYLIST_XML=""
 
590
    MENU_BUTTONS=""
 
591
    # Go back to doing normal video titles
 
592
    STILL_TITLES=false
 
593
  fi
 
594
 
 
595
  # Increment the current titleset number
 
596
  (( CUR_TS++ ))
 
597
 
 
598
  fi # End if there are titles
 
599
}
 
600
 
 
601
# ==========================================================
 
602
# EXECUTION BEGINS HERE
 
603
echo "$SCRIPTNAME"
 
604
 
 
605
if test $# -lt 1; then
 
606
    usage_error "Please provide at least one video to author, and the name of an output file to use."
 
607
fi
 
608
 
 
609
while test $# -gt 0; do
 
610
    case "$1" in
 
611
        "-quiet" )
 
612
            QUIET=:
 
613
            ;;
 
614
        "-out" )
 
615
            shift
 
616
            OUT_PREFIX="$1"
 
617
            ;;
 
618
        # Format and overwriting options
 
619
        "-dvd" ) XML_FORMAT="dvd" ;;
 
620
        "-vcd" ) XML_FORMAT="vcd" ;;
 
621
        "-svcd" ) XML_FORMAT="svcd" ;;
 
622
        "-overwrite" ) OVERWRITE=: ;;
 
623
        # Menus and video titles
 
624
        "-topmenu" )
 
625
            shift
 
626
            if ! $HAVE_TOP_MENU; then
 
627
                checkExistence "$1"
 
628
                addTopMenu "$1"
 
629
            else
 
630
              usage_error "Please specify only one -topmenu option. If you would like to have multiple menus, please use the -menu option."
 
631
            fi
 
632
            ;;
 
633
        "-menu" )
 
634
            if $FORCE_TITLESETS; then
 
635
              usage_error "You can not use -titlesets with -menu. Please use -topmenu instead."
 
636
            fi
 
637
            shift
 
638
            HAVE_MENU=:
 
639
            FIRST_TITLE=:
 
640
            checkExistence "$1"
 
641
            closeTitleset
 
642
            addMenu "$1"
 
643
            ;;
 
644
        "-slides" )
 
645
            STILL_TITLES=:
 
646
            FIRST_TITLE=:
 
647
            ;;
 
648
        "-group" )
 
649
            MAKE_GROUP=:
 
650
            CUR_VIDEO=0
 
651
            ;;
 
652
        "-endgroup" )
 
653
            if $MAKE_GROUP; then
 
654
                TS_TITLES=`cat << EOF
 
655
                $TS_TITLES
 
656
                __POST_CMD__
 
657
                </pgc>
 
658
EOF`
 
659
            fi
 
660
            MAKE_GROUP=false
 
661
            CUR_VIDEO=0
 
662
            ;;
 
663
        "-chapter-points" )
 
664
            # Space-separated list of comma-separated chapter points
 
665
            MAKE_CHAPTERS=:
 
666
            shift
 
667
            IFS=""; while test $# -gt 0 && test ${1:0:1} != "-"; do
 
668
                CHAPTER_POINTS=("${CHAPTER_POINTS[@]}" "$1")
 
669
                shift
 
670
            done
 
671
            if test $# -gt 0 && test ${1:0:1} = "-"; then
 
672
                DO_SHIFT=false;
 
673
            fi
 
674
            unset IFS
 
675
            ;;
 
676
        "-chapters" )
 
677
            # Fixed chapter intervals
 
678
            MAKE_CHAPTERS=:
 
679
            shift
 
680
            CHAPTER_INTERVAL=$1
 
681
            if test "$CHAPTER_INTERVAL" -lt "0" || \
 
682
               test "$CHAPTER_INTERVAL" -gt "9999";
 
683
            then
 
684
               usage_error "Please use a -chapters interval between 0 and 9999."
 
685
            fi
 
686
            ;;
 
687
        "-nochapters" )
 
688
            MAKE_CHAPTERS=false
 
689
            ;;
 
690
        "-titlesets" )
 
691
            if $HAVE_MENU; then
 
692
              usage_error "You can not use -titlesets with -menu. Please use -topmenu instead."
 
693
            fi
 
694
            FORCE_TITLESETS=:
 
695
            echo "Creation of titlesets forced ..."
 
696
            ;;
 
697
        * )
 
698
            checkExistence "$1"
 
699
            addTitle "$1"
 
700
            ;;
 
701
    esac
 
702
    # Get the next argument
 
703
    shift
 
704
done
 
705
 
 
706
# Last argument should be the name of the output file
 
707
if test -z "$OUT_PREFIX"; then
 
708
    usage_error "Please provide an output filename with -out."
 
709
fi
 
710
 
 
711
# See if selected output file exists. If so, confirm for overwrite.
 
712
if test -e "$OUT_PREFIX.xml"; then
 
713
    echo $SEPARATOR
 
714
    echo "*** The output file you specified: $OUT_PREFIX.xml already exists."
 
715
    if $OVERWRITE; then
 
716
        echo "Overwriting existing file."
 
717
    else
 
718
        echo "Please re-run the script with the -overwrite option to overwrite."
 
719
        exit 1
 
720
    fi
 
721
    echo $SEPARATOR
 
722
fi
 
723
 
 
724
 
 
725
# Close current titleset
 
726
closeTitleset
 
727
 
 
728
# Fill in top menu buttons
 
729
TOP_MENU_XML=$(echo "$TOP_MENU_XML" | \
 
730
    sed -e "s/__TOP_MENU_BUTTONS__/$(sedprep "$TOP_MENU_BUTTONS" /)/g")
 
731
 
 
732
# If there is a top menu with no other menus, print an error and
 
733
# a suggestion that user specify -menu instead of -topmenu
 
734
if $HAVE_TOP_MENU && ! $HAVE_MENU && ! $FORCE_TITLESETS; then
 
735
  echo "You have specified a top menu without any other menus. If you only want to have one menu, please use the -menu option instead of -topmenu."
 
736
  echo "Exiting without writing XML file."
 
737
  exit 1
 
738
fi
 
739
 
 
740
# Assemble the final XML file
 
741
 
 
742
# dvdauthor format for a DVD
 
743
if test $XML_FORMAT = "dvd" ; then
 
744
FINAL_DISC_XML=`cat << EOF
 
745
<dvdauthor dest="$OUT_PREFIX">
 
746
<!-- makexml $TOVID_VERSION -->
 
747
<vmgm>
 
748
$TOP_MENU_XML
 
749
</vmgm>
 
750
$ALL_MENU_XML
 
751
</dvdauthor>
 
752
EOF`
 
753
 
 
754
# vcdxbuild (vcdimager) format for a VCD or SVCD
 
755
else
 
756
  # Determine what version number to use
 
757
  if test $XML_FORMAT = "vcd" ; then
 
758
    VCD_VERSION="2.0"
 
759
    OPTION_LINE=''
 
760
  # Use 1.0 for SVCD
 
761
  else
 
762
    VCD_VERSION="1.0"
 
763
    OPTION_LINE='<option name="update scan offsets" value="true" />'
 
764
  fi
 
765
 
 
766
  # Make sure there are segment-items and sequence-items
 
767
  if test -n "$SEGMENT_ITEMS_XML" ; then
 
768
    SEGMENT_ITEMS_XML=`cat << EOF
 
769
<segment-items>
 
770
$SEGMENT_ITEMS_XML
 
771
</segment-items>
 
772
EOF`
 
773
  fi
 
774
  if test -n "$SEQUENCE_ITEMS_XML" ; then
 
775
    SEQUENCE_ITEMS_XML=`cat << EOF
 
776
<sequence-items>
 
777
$SEQUENCE_ITEMS_XML
 
778
</sequence-items>
 
779
EOF`
 
780
  fi
 
781
 
 
782
FINAL_DISC_XML=`cat << EOF
 
783
<?xml version="1.0"?>
 
784
<!DOCTYPE videocd PUBLIC "-//GNU/DTD VideoCD//EN"
 
785
  "http://www.gnu.org/software/vcdimager/videocd.dtd">
 
786
<videocd xmlns="http://www.gnu.org/software/vcdimager/1.0/"
 
787
  class="$XML_FORMAT" version="$VCD_VERSION">
 
788
$OPTION_LINE
 
789
<info>
 
790
  <album-id>VIDEO_DISC</album-id>
 
791
  <volume-count>1</volume-count>
 
792
  <volume-number>1</volume-number>
 
793
  <restriction>0</restriction>
 
794
</info>
 
795
 
 
796
<pvd>
 
797
  <volume-id>VIDEO_DISC</volume-id>
 
798
  <system-id>CD-RTOS CD-BRIDGE</system-id>
 
799
</pvd>
 
800
 
 
801
$SEGMENT_ITEMS_XML
 
802
 
 
803
$SEQUENCE_ITEMS_XML
 
804
 
 
805
<pbc>
 
806
$TOP_MENU_XML
 
807
 
 
808
$PBC_XML
 
809
</pbc>
 
810
</videocd>
 
811
EOF`
 
812
fi
 
813
 
 
814
# Remove blank lines and write final result to output file
 
815
echo "$FINAL_DISC_XML" | sed -e '/^ *$/d' > "$OUT_PREFIX.xml"
 
816
 
 
817
if $FILE_NOT_FOUND; then
 
818
  echo $SEPARATOR
 
819
  echo "Some of the video files you specified were not found."
 
820
  echo "The XML file was written anyway, but you might want to"
 
821
  echo "double-check to make sure you didn't make a typing mistake."
 
822
fi
 
823
 
 
824
echo "Done. The resulting XML was written to $OUT_PREFIX.xml."
 
825
 
 
826
if ! $QUIET; then
 
827
    if test $XML_FORMAT = "dvd" ; then
 
828
        echo "You can now author, image and/or burn the disc by running:"
 
829
        echo "    makedvd \"$OUT_PREFIX.xml\""
 
830
    else
 
831
        echo "You can create the (S)VCD .bin and .cue files by running the command:"
 
832
        echo "    makevcd \"$OUT_PREFIX.xml\""
 
833
    fi
 
834
    echo "Thanks for using makexml!"
 
835
fi
 
836
 
 
837
exit 0
 
838