Automated DVD menu authoring with pdfLATEX

Péter Szabó Budapest University of Technology and Economics, Dept. of Computer Science and Information Theory, H-1117 Hungary, Budapest, Magyar tudósok körútja 2. pts (at) cs dot bme dot hu http://www.inf.bme.hu/~pts/

Abstract dvdauthor is an excellent low-level free tool for video DVD authoring on Unix systems. However, it doesn’t provide a convenient way for drawing the menu background and buttons. We present dvdmenuauthor, a collection of scripts for automated DVD authoring with menus. dvdmenuauthor uses pdfLATEX macros for menu composition, Xpdf for menu rendering, and dvdauthor for DVD filesystem authoring.

1 Background Popular reasons for adding menus to a DVD: DVD-Video [8] is today’s most popular home enter- • DVD menus are a good quality addon for Holly- tainment video format. Video shops and video rental wood-style movies. Both the visual appearance services used to provide films on VHS cassettes in the and the sound of the menu is in theme with the 1990s, but now they offer DVD discs almost exclu- movie, and the first minute spent on navigating sively. DVD not only provides cheaper reproduction the menu (mostly in order to select the audio costs, better video and audio quality than VHS, and stream and subtitles) is now part of the fun the multiple camera angles, audio tracks and subtitles, spectator experiences. but it also has an advanced, programmable (but op- • If the DVD contains a lot of material (up to 8 tional) navigation facility called DVD menus (or DVD hours are feasible using double-layer discs and extras). lossy compression), spectators expect an order The remote control of a DVD player device has in which they can easily find the title they are several menu buttons (such as menu, top menu, au- looking for. Menus with thumbnail images and dio, subtitle and angle), which, when pressed, sus- title captions make navigation easier. It is also pend playback and jump to a menu. A menu is a possible to have multiple menus that point to single-page interactive part of the DVD, designed the same set of titles, but in different logical and programmed by the DVD creator. It can be order. Usually 2 × 2 or 3 × 2 thumbnails are animated (possibly in a loop), and it can have audio displayed in a single menu, and such menus as well. A menu has several on-screen buttons, one are linked together using buttons. Most DVD of them being highlighted. The arrow buttons (up, authoring software provide an automated wizard right, down and left) on the remote control can be for generating thumbnailed menus of this kind. used move the highlight, or, when the DVD is played • DVD menus make it possible to present an in- on a computer, the highlight is moved to the button teractive show to the spectators, in which they under the mouse. The enter button can be used can choose among 2 or 3 endings of the movie, to execute the action associated to the highlighted or they can even choose in the middle how the on-screen button. Possible actions: story should advance. Of course, movie creators • resume or start playback at a specific location; must record all possible storylines, which is a lot of extra work, and the capacity of the DVD disk • jump to another menu (possibly with a specific also limits the available choices. However, it can button pre-highlighted); be feasible to give the spectator 3 choice points • change a playback-related variable (such as au- and thus have 2 · 2 · 2 = 8 storylines altogether dio stream, subtitle language and angle); in a 1-hour long movie. • change an auxiliary variable (to be used later) — • It is also possible to offer a trivia game (playable integer arithmetic operators are available; by the spectator) in DVD format. For example, • execute a conditional block (if–then–else). the famous Who wants to be a millionaire TV

166 TUGboat, Volume 29, No. 1 — XVII European TEX Conference, 2007 Automated DVD menu authoring with pdfLATEX

game has a DVD version [16], in which the next so a multi-gigabyte temporary ISO image file question is chosen randomly from about 1000 doesn’t have to be created. pre-recorded questions. Even the three lifelines are present. All these are programmed as a set 2 Motivation of DVD menus. This article focuses on DVD menu authoring, i.e. The process of designing and creating a DVD-Video adding menus and integrating DVD-Video compo- disc is called DVD authoring. It consists of these nents. It presents a solution based on the combina- steps: tion of dvdauthor XML integration and LATEX type- 1. DVD stream authoring: The video, audio and setting. The reasons why such a solution can be subtitle streams are created, imported and mul- useful: tiplexed together to DVD-compatible MPEG-2 • Our solution uses only free software and runs program stream files. The DVD standard im- on Unix systems. We have tried several tools poses quite a lot of restrictions on the file format, [3, 14, 7, 11], but we haven’t found such a tool the video resolution, the frame rate, the video for Unix which is user-friendly, well-integrated codec, the audio codec and the audio sample (doesn’t need a specific version of several dozen rate. However, there are tools (such as the free other software packages to work), reliable (no DeVeDe [2]) which can convert any stream to random crashes) and ready for production use a DVD-compatible stream. Most video edit- (no major bugs and annoyances, no memory ing tools have DVD-compatible export filters. leaks). We decided to develop our own software, For simple MPEG video editing, we recommend which is practical and usable for menu-based MPEG Video Wizard [17], which is not only ef- DVD authoring. ficient to use, but it also runs quickly enough • Most popular video editing programs provide even in virtualised environments. only a wizard, which streamlines creating simple 2. DVD menu authoring: The menu background menus (such as thumbnail buttons for each title), images (or animations), buttons and captions and doesn’t let the user specify the exact menu are designed, menus and titles (i.e. streams au- structure. thored in the previous steps) are combined using programmed actions. This step is the integra- • A template-based, non-WYSIWYG solution is tion part of the DVD authoring process, because useful for repetitive, automated menu genera- the way individual background images, thumb- tion, such as generating a navigable DVD slide- nails, captions and stream files are combined show from a set of images, or generating several together is specified in this step. If dvdauthor DVDs (with different video content) using one [3] is used in the next step, the details of the in- menu theme. tegration are specified in its XML project input • LATEX provides a separation of text and design file. that is versatile enough for several designs to 3. DVD filesystem creation: The various stream be tried (and possibly customised) for the same files and declarations are combined to a DVD- menu structure. Most WYSIWYG DVD menu Video filesystem (with the VIDEO_TS folder). creation tools let the user manipulate the de- This is a completely automatic process (and sign of one object a time. Most of them don’t takes about 5 minutes on modern PCs for a support requests like “let’s see the same design single-layer full DVD). On , dvdauthor with 10% larger buttons”, and even those that [3] is the only well-known free tool that can do support it, won’t be able to adjust the spac- the job; other programs are usually easy-to-use ing properly around the resized buttons. With frontends to dvdauthor. LATEX, however, those kinds of changes can be 4. DVD image creation: An ISO image file is cre- easily done with glue nodes and a little macro ated automatically from the DVD filesystem. On programming. Linux systems, it is usually done with mkisofs • TEX can typeset textual labels of high quality. [13], with the -dvd-video option. Most DVD authoring programs have very lim- 5. DVD disc burning: The ISO image file is au- ited typographic capabilities, for example they tomatically burnt to a DVD disc. On Linux don’t support manual line breaking, line justi- systems, growisofs [10] is a convenient command- fication, automatic line breaking, pair kerning line tool to do the job. It can also combine this and accented characters are not available. Using step with the previous one (DVD image creation), LATEX we get all these features.

TUGboat, Volume 29, No. 1 — XVII European TEX Conference, 2007 167 Péter Szabó

3 Design decisions 4 The manual way of authoring DVDs It was our intention to use existing software if possi- This section gives an introduction to DVD-Video ble, and add or change things where existing software concepts, and it also presents the pure, manual way is not powerful enough. We have found that dvd- of DVD menu authoring using dvdauthor. The way author’s XML project file provides an efficient and presented here is similar to typesetting documents precise way for DVD menu authoring — except for with TEX: there are a bunch of input files, most drawing the menus (and converting them to a for- of them being plain text files written by humans, mat that dvdauthor understands). Thus we decided and there are some non-WYSIWYG tools, which can to supplement the XML project file with drawing be applied to the input files in the correct order to operations, and write some scripts that extract the produce the desired output. drawing operations, typeset the menus, render them 4.1 DVD without menus to images, convert the images, and run dvdauthor to create the DVD file system. We chose LATEX for DVD stream authoring is beyond the scope of this pa- the markup language of drawing operations, mostly per, so we assume that the movie is already prepared because it has powerful typesetting capabilities, and in a set of DVD-compatible MPEG-2 stream files. Un- its macro language is powerful enough to implement fortunately, there is no validator for this file format. the necessary housekeeping (e.g. which button was If there is a problem with the file (for example, the emitted to which page). wrong audio codec is used, or the multiplexing packet We wanted to keep LATEX programming at a size is incorrect), dvdauthor will usually complain, minimum, because LATEX is not convenient for gen- but the error message doesn’t always indicate clearly eral data processing. Thus we use LATEX mostly for the reason for the problem. The free video conversion typesetting. Perl scripts generate the document to tools MEncoder [12] and FFmpeg [9] can generate a typeset from the project XML file, and Perl scripts conforming MPEG-2 stream if called with the proper drive the further conversion of pdfLATEX’s PDF out- parameters. See the source code of DeVeDe [2] for put to images (using the pdftoppm tool of Xpdf parameters to MEncoder. [19]). LATEX macros emit some metainformation to A DVD-Video disc consists of titles and menus. the .aux file (e.g. the correspondence of PDF page A title is a stream that contains video and audio numbers and DVD menu button names), which is (multiple video and audio channels possible). The also read by the Perl scripts. playback of a title can start at the beginning or at any specific position (given by a time offset from the We wanted to reuse as many LATEX typesetting constructs as possible, thus the style file just sets beginning). A chapter is a logical unit within a title. the page size, the margins and the default font size, DVD players usually let the user choose a title (by its number) to start playback at (not all players expose and lets the user draw the menu with LATEX. We don’t enforce any specific layout, any layout can chapter boundaries within the title to the user). The simplest, completely automatic way to cre- be designed using TEX boxes, glues and macro pro- gramming. However, we don’t use automatic page ate a DVD without menus is to use dvdauthor [3]. breaks: the user has to decide in advance how many For example, menus to have. (Automatic page breaks wouldn’t dvdauthor -o dir -t a.mpg b.mpg c.mpg fit with dvdauthor’s project file easily anyway.) The dvdauthor -o dir -t d.mpg e.mpg style file also provides some drawing primitives useful dvdauthor -o dir -T for DVD menus: colourful frames, framed buttons, creates a DVD with two titles. Title 1 contains single-colour buttons (of any shape) and absolute 3 chapters (from the contents of video files a.mpg, positioning. b.mpg and c.mpg, respectively). Title 2 contains 2 We designed the project file syntax so that users chapters (from the contents of video fies d.mpg and don’t have to type the same information twice, and e.mpg, respectively). For each title, files dir/VIDEO data relationships are often expressed by putting _TS/VTS_NN_* are created, where NN is the number related pieces close to each other. For example, it of the title. The last command (with the -T) creates is possible to specify the thumbnail image file name the table of contents (to files dir/VIDEO_TS/VIDEO_ as an attribute to the DVD

Figure 2: A menu definition in the dvdauthor project file

\thispagebgimage{}{pal_bg_light} \thispagetemplate{palthumbsix} \menucaption{Fazekas szalagavató 1998.\ december} jump vmgm menu 1;

Figure 3: A menu definition in the dvdmenuauthor project file

TUGboat, Volume 29, No. 1 — XVII European TEX Conference, 2007 171 Péter Szabó

\begin{dvdmenupage}{e1,e2,e3,e4,e5,prev,back,next} \thispagebgimage{}{pal_bg_light} \thispagetemplate{palthumbsix} \menucaption{Fazekas szalagavató 1998.\ december} \begingroup\def\dvdbuttonattrXname{e1} \def\dvdbuttonattrXcaption{a szalagtűzés \emph{előtt}} \def\dvdbuttonattrXimage{1.png} \dvdprocessbutton\endgroup \begingroup\def\dvdbuttonattrXname{e2} \def\dvdbuttonattrXcaption{szalagtűzés} \def\dvdbuttonattrXimage{2.png} \dvdprocessbutton\endgroup ... \begingroup\def\dvdbuttonattrXname{next} \def\dvdbuttonattrXdummy{} \dvdprocessbutton\endgroup \end{dvdmenupage}

Figure 4: The LATEX code snippet generated from the dvdmenuauthor definition the dvdauthor definition on Figure 3. We can see \putat{x}{y}boxspec that for each attribute with a tex: prefix, a macro Typesets the specified material with its reference \dvdbuttonattrX... is defined, and the command point at (x, y). Creates a properly shifted box of size \dvdprocessbutton is called after the macro defini- zero. Can be used for absolute positioning if called tions for each button. The tex:dummy attribute is at the top of the page. Can be used with \vbox for just an indicator that the button must be processed last line alignment or \vtop for first line alignment. A by LTEX. This command can be used in templates. The macros \menucaption and \dvdprocess button are defined in template palthumbsix. They \begin{dvdmenupage}{buttonlist} take care of the visual formatting of the menu data. Renders a DVD menu page with the specified buttons \dvdprocessbutton has the available button names (in the specified order). For technical reasons (see hardwired, and it formats and positions a button Subsection 6.2) each button is rendered on its own based on its name. onto a separate PDF page.

5.2 New LATEX commands provided \framehbox{sep-dimen}{hbox-contents} Although dvdmenuauthor encourages the use of ex- Similar to the built-in command \framebox, but isting LATEX commands, it also defines some new allows catcode changes and verbatims in the box. commands, most of them related to positioning and Unfortunately, catcode changes don’t work in gen- button typesetting. eral in dvdmenuauthor, because the dvdmenupage environment reads its contents to a macro for multi- \thispagecolor{colorname} ple rendering. Changes the background of the current page to the specified color. Like most graphics operations in \aliascolor{oldname}{newname} dvdmenuauthor, it works only with pdfLATEX. Copies a colour definition to be usable as a different name. \thispagebgimage{optionlist}{filename} Sets the background image for the current page. The \dvdtextbutton{name}{text} image will be loaded by the \includegraphics com- Typesets a button. Doesn’t wrap its contents in mand using the pdftex driver. a box, so a button can be in a middle of a para- graph, even line breaks are allowed. Each button has \thispagetemplate{templatename} three forms: background, highlighted and selected. Selects the specified template for the current page. In background mode, text is typeset normally, in This means defining some macros, for example the highighted mode, it is typeset in dvdhighlightedcolor sample template palthumbsix defines \menucaption (without color changes and images), and in selected and \dvdprocessbutton. mode it typesets in dvdselectedcolor.

172 TUGboat, Volume 29, No. 1 — XVII European TEX Conference, 2007 Automated DVD menu authoring with pdfLATEX

\dvdframebutton{name}{text} 5. Authoring the DVD filesystem. This is just a Typesets a button inside a \hbox. In background simple dvdauthor run (with the -x option using mode, emits the \hbox. In highlighted mode, it emits the XML project file generated in the first step). an empty box surrounded by a frame (using the pa- This step might take quite a lot of time (up to rameters \dvdbuttonframesep, \dvdbuttonframe 5 minutes on modern systems for a full, 4.7 GB width and dvdhighlightedcolor). This command can DVD), and it needs free disk space about the be used to typeset thumbnail buttons. same size as the sum of the input video sizes. The recommended DVD preview application is Xine \begin{narrowcentering} [18]. It can be installed from source in any mod- Like \begin{centering}, but doesn’t reset the nat- ern Linux distribution. Although the user interface ural width of \leftskip and \rightskip to zero. (toolbars and menus) of Xine is quite ugly, and not convenient to operate, Xine has very good keybind- 5.3 Working with dvdmenuauthor ings, especially suitable for DVD menu navigation TEX users are familiar with the edit–compile–pre- (a remote control panel is also available — press Alt– view cycle of TEX document preparation, possibly hEi to make it visible). See the manual page of xine extended with a final conversion and printing or pub- for the list of available keys. MPlayer is not rec- lishing. The same cycle exists with dvdmenuauthor. ommended for DVD menu testing, because MPlayer In the edit cycle, the user edits an XML project file doesn’t support DVD menus yet. Although VLC has with LATEX markup for the menus, in the compile DVD menu support, sometimes it crashes or behaves cycle the user compiles the project files (and the unexpectedly. Kaffeine and Totem should also be media files it refers to) to a DVD image, and finally given a try. the user previews the DVD on screen, including the Since dvdauthor runs slowly when the videos to menus and titles. The publishing step is burning the be put on the DVD are large, the compile step might DVD filesystem to disc. be too slow for the user. To solve this, dvdmenu- In the edit step any text editor can be used, author has the dvdmenutest.sh shell script, which preferably one with XML syntax highlighting facili- warps a dvdauthor project XML files so that all titles ties. Unfortunately, LATEX snippets won’t be high- (but not menus!) are replaced with dummy short lighted as LATEX markup. The dvdmenuauthor con- videos, so that the total video size would be small, tains an example project file ex.dmp.xml . and thus dvdauthor runs quickly. The compile step consists of feeding the project The publishing step means creating an ISO im- file to a few scripts. The Makefile in the dvdmenu- age (with mkisofs) and/or burning it to disc (with author distribution automates this. (There is no growisofs). The -dvd-video flag of mkisofs must be incremental compilation support yet: the whole DVD specified in both command lines. filesystem is regenerated from scratch in each make run.) The following steps constitute compilation: 6 Implementation tricks Some details of the implementation are worth men- 1. Generating the menu LATEX source file and the dvdauthor XML project file. This is done by the tioning, because the tricks employed can be useful gendap.pl Perl script. in other TEX or DVD-related projects. 2. Compiling the LATEX source file to PDF. This is 6.1 Bounding box calculation just a regular pdfLAT X run. The Makefile runs E dvdmenuauthor calculates button bounding boxes pdfLAT X twice, in case there are s. E \ref automatically. This operation is impossible within 3. Rendering the PDF to PPM raster image files. TEX, because there is no way to inquire about the This is done by the excellent pdftoppm utility absolute (x, y) coordinates of an item within a box. from Xpdf. Solution: dvdmenuauthor uses a bluescreen tech- 4. Combining the PPM images to short MPEG-2 nique [1]. The LATEX component emits each button streams for the menus. This is done by the on its own to a PDF page with a blue background, genspuxml.pl Perl script, which calls another and a Perl script analyses the rendered page. The Perl script genmpeg.pl (to generate an MPEG- bounding box is the smallest rectangle on the page 2 stream from still images), and the spumux whose complement contains only blue pixels. A little tool from dvdauthor (to multiplex the button extra housekeeping is done for identifying the button layers to the background). Since some image pages belonging to the same menu, because later processing is done in Perl, this step can take they have to be merged again to a button highlight about three seconds for each menu. layer.

TUGboat, Volume 29, No. 1 — XVII European TEX Conference, 2007 173 Péter Szabó

Limitations: It is not possible to force a bound- Solution: The character set of the XML docu- ing box larger than it appears. It is not possible to ment must be specified in the encoding= attribute use that specific shade of blue in buttons. Fortu- of the

174 TUGboat, Volume 29, No. 1 — XVII European TEX Conference, 2007 Automated DVD menu authoring with pdfLATEX

To solve this, one could render at viewing size (thus [4] The manual page of dvdauthor. degrading rendering quality a little) or one could http://dvdauthor.sourceforge.net/doc/ condense the fonts horizontally (not easy to do in [5] Anders Dahnielson. DVD Author Primer. TEX, but the pdfTEX font expansion feature might December 31, 2003. http://en.dahnielson. be useful). com/2003/12/dvd-author-primer.html 8 Conclusion [6] dvdmenuauthor, automated DVD menu authoring with pdfLATEX. http://freshmeat. TEX can be used productively for typesetting many net/projects/dvdmenuauthor different kinds of work: high quality (possibly inter- [7] DVDStyler, a cross-platform GUI DVD national) documents, maths, presentation slides and authoring system. http://www.dvdstyler. music, to name a few. Other uses of T X include E de/ developing software and its documentation together, preparing web-ready books, and rearranging PDF [8] Wikipedia article on DVD-Video. http: pages. DVD menu authoring is also a new, non- //en.wikipedia.org/wiki/DVD-Video standard use. [9] FFmpeg, a very fast command-line video and We have designed dvdmenuauthor, a program audio converter. for project-file-driven (non-WYSIWYG) automated http://ffmpeg.mplayerhq.hu/ DVD menu authoring with powerful menu drawing [10] DVD+RW-tools, a set of tools for burning and facilities. It is now a free proof-of-concept imple- examining DVD discs. http://fy.chalmers. mentation. DVD menus can be drawn using LATEX se/~appro/linux/DVD+RW/tools/ markup to have high typographic quality output. [11] KMediaFactory, template-based GUI DVD Layout and menu data can be separated using tem- authoring software. http://freshmeat.net/ plates. Since dvdauthor is used for integration, users projects/kmediafactory/ have full freedom to create complex and/or smart [12] MEncoder, the command-line movie encoder of menus they want. The system design (compilation the MPlayer suite. and templates) makes it possible to experiment with http://www.mplayerhq.hu/ layout changes any time in the authoring process. [13] mkisofs, a tool for creating CD and DVD dvdmenuauthor is not easy to start using for an filesystems. http://cdrecord.berlios.de/ average user who expects WYSIWYG and wizards. [14] ’Q’ DVD-Author, a GUI frontend for dvdauthor However, we hope that LATEX users would find it convenient, and the software can evolve from its and other related tools. present proof-of-concept version to a stable, general http://qdvdauthor.sourceforge.net/ and powerful tool like the mainstream TEX-based [15] Samantha Lane. Switched menus with programs. dvdauthor. http://www.geocities.com/ samanthalane/dvd/index.html References [16] Who Wants to Be a Millionaire — DVD game [1] Wikipedia article on the Bluescreen technique. review. http://www.ciao.co.uk/Who_Wants_ http://en.wikipedia.org/wiki/Bluescreen To_Be_A_Millionaire_DVD_Game__Review_ [2] DeVeDe, a GUI program to create video 5480599 DVDs suitable for home players, from any [17] Womble MPEG Video Wizard, a commercial number of video formats supported by MPlayer. nonlinear MPEG video editor. http://www.rastersoft.com/programas/ http://www.womble.com/products/ devede.html [18] Xine, a free multimedia player. [3] dvdauthor, a tool that assembles multiple http://xinehq.de/index.php/home mpeg program streams into a suitable DVD [19] Xpdf, an open source viewer for PDF files. filesystem. http://dvdauthor.sourceforge. http://www.foolabs.com/xpdf/ net/

TUGboat, Volume 29, No. 1 — XVII European TEX Conference, 2007 175