Rainers Home

DVD-Authoring with Linux

How to get from a DV-AVI to a nice DVD including several audio tracks and subtitle tracks.

Things you might want to install:
- transcode
- ffmpeg
- mplayer
- xine
- dvdauthor
- dvd+-rw-tools

My list of websites to this topic:
- Foto & Video

I assume, that you have already edited your video (using e.g. cinelerra or Kino) and that you have exported your movie to an uncompressed DV-avi stream. If your favourite video editor allows exporting mpeg2 streams you can skip the first step.

Part1: Preparing the pieces:

First thing is to convert the DV-avi to an mpeg stream. There are different ways to do so, e.g. using transcode or mplayer, but I will using ffmpeg in the following.

ffmpeg -i input.avi -target dvd -aspect 4:3 -hq output.mpg
You can improve the video quality further using 2pass encoding:
ffmpeg -i input.avi -target dvd -aspect 4:3 -hq -passlogfile logfile.log -pass n output.mpg
where n equals 1 for the first pass and 2 for the second pass.

Next step is to extract the movie and audio stream out of the freshly created mpeg file:

tcextract -i output.mpg -x mpeg2 > output.m2v
Also you need the audio stream. If your video editor allows you to directly export a wav file, you can skip the next step. If you have several versions of your video with different audio tracks you’ll need to do the following two steps for each of the audio tracks.
tcextract -i input.avi -x pcm -a 0 > output.wav
Convert the wav file into mp2:
nice -n 20 toolame -p 2 -b 384 -s 48 output.wav output.mp2 > /dev/null 2>&1

I’m using mpeg2 audio as it has sufficient audio quality. The above noted ffmpeg command produces an ac3 audio stream which you can also use if you want. In this case, extract it using -x ac3 and skip the conversion to mp2. Using cinelerra you can also create ac3 sound with a multi-speaker setup, so you don’t need the steps above.

Part 2: Combining the pieces

Done that you’ll have to put the pieces together again to a mpeg-file for dvdauthor. Do this using

mplex -f8 -o output_dvd.mpg output.m2v output.mp2
If you have several audio tracks just list them all up in the mplex command. The order specified here is also the order on the DVD meaning the first listed audio track becomes the default audio etc.

If you want subtitles you need to create two files: One containing the actual subtitle text with start and end information, let’s call it subtitle.srt:

1
00:00:05,500 --> 00:00:07,000
Subtitle one

2
00:00:08,900 --> 00:00:10,000
You can write long sentences if you want, they will be wrapped automatically.
Next you’ll need an xml-file for spumux to define how and where the subtitles should appear, we’ll name it subtitle.xml:
 <subpictures>
  <stream>
    <textsub filename="subtitle.srt" characterset="ISO8859-1"
         fontsize="24.0" font="Verdana.ttf" horizontal-alignment="center"
         vertical-alignment="bottom" left-margin="60" right-margin="60"
         top-margin="20" bottom-margin="30" subtitle-fps="25"
         movie-fps="25" movie-width="720" movie-height="576"/>
  </stream>
</subpictures>
The specified font file has to be in ∼/.spumux/. Done that, it’s time to add the subtitles to the movie:
spumux -s0 subtitle.xml < output_dvd.mpg > output_sub.mpg

Part 3: Creating a menu

You need an image of 720x576 (for PAL that is). Gimp has templates for this. Here you simply paint the buttons on the background but be aware of overscan, so to be on the safe side leave a margin of about 120px on the left and right side and about 10px from above and below. So, if you’re using gimp, create your background image and then add a new transparent layer. Select the newly created layer and paint the button outlines around your button for the higlighting effect. Next, duplicate this layer and change the color of your button outlines for the selection effect. Finally, select only the background image and save it as background.jpg.

PNG - 458.3 kB
background

Now, select only the layer with the highlight buttons and save this as background_high.png and do the same step for the selection buttons and save it as background_select.png.

PNG - 360 Byte
background_highlight
PNG - 360 Byte
background_select

It is important that those png files don’t contain more than four colors where the transparency also counts as color! If you want to have some fancy shadow effects or something else this probably won’t work.

The next step is to create a mpg movie out of the images:

convert background.jpg ppm:- | ppmtoy4m -n50 -F25:1 -A59:54 -I p -r -S 420mpeg2 | mpeg2enc -n p -f8 -b5000 -a2 -o background.m2v
If you want to create 16:9 format replace -a2 with -a3 in the mpeg2enc command.

Also we need some silence audio.

ffmpeg -ab 224 -ar 48000 -ac 2 -t 5 menu_audio.ac3
(Depending on the configuration of your sound card this might record the currently playbacked audio on your system, so be careful)

If you want you can also use some real music. In this case make sure you have enough movie material (read enough frames) matching your audio. You can tune this with the -n100 parameter above in the ppmtoy4m command by increasing the number of frames.

Now, we need again to combine audio and video:

mplex -f8 -o menu_video.mpg menu_background.m2v menu_audio.ac3

To embed the buttons to the video, we again use spumux. Save the following as menu.xml

 <subpictures>
  <stream>
    <spu start="00:00:00.0" end="00:00:00.0"
         highlight="background_high.png"
         select="background_select.png"
         autooutline="infer"
         autoorder="rows"/>
  </stream>
</subpictures>

Then run spumux:

spumux menu.xml < menu_video.mpg > menu.mpg

Part 4: Build the DVD

Finally all the pieces need to be combined in a DVD structure which is done using dvdauthor. Again we need a xml file to describe the content of the DVD, we call it dvd.xml. There are several menu hierarchies: You have one menu at the root of the DVD (the vmgm one, the title-menu of the DVD) from where you can jump to the menus of the different titlesets. A DVD may contain one or more titlesets and you can have several menu pages per menu simply by defining several menu files. For a detailed explanation of the possible menu hierarchies visit http://www.tappin.me.uk/Linux/dvd.html

<dvdauthor dest="/output/directory/DVD">
 <vmgm>
   <menus lang="de">
     <video format="pal" aspect="4:3" resolution="720x576" />
     <pgc entry="title">
       <pre>jump titleset 1 menu;</pre>
     </pgc>
   </menus>
 </vmgm>
 
 <titleset>
   <menus>
     <pgc entry="root">
       <button>jump title 1;</button>
       <button>jump title 2;</button>
       <button>jump title 3;</button>
       <button>jump title 4;</button>
       <button>jump menu 2;</button>
       <vob file="menu.mpg"/>
     </pgc>
   </menus>

   <titles>
     <audio lang="de" />
     <audio lang="de" />
     <subpicture lang="de" />
     <pgc>
       <vob file="title1.mpg" chapters="0,12:51,17:16,23:20"/>
       <post>jump title 2;</post>
     </pgc>  
     <pgc>
       <vob file="title2.mpg"/>
       <post>jump title 3;</post>
     </pgc>  
     <pgc>
       <vob file="title3.mpg"/>
       <post>jump title 4;</post>
     </pgc>  
     <pgc>
       <vob file="title4.mpg" chapters="0,8:01,11:29"/>
       <post>call menu;</post>
     </pgc>
   </titles>  
 </titleset>  
</dvdauthor>

The DVD structure can now be created using

dvdauthor -x dvd.xml
Once this has finished you can write everything on a DVD using
growisofs -Z /dev/dvdram -dvd-video /output/directory/DVD/
It might be necessary to use -dvd-compat as additional parameter and/or limit the write speed with -speed=N DVD-RWs can be blanked again using dvd+rw-format -blank /dev/dvdram. Using a DVD-RW is recommended for experimentation ;)

Some general notes:

If you want to use DVD+R DL etc. have a look what your DVD writer is setting as booktype for the DVD. Many standalone DVD players require this to be set to "DVD-ROM". You can toggle this on some writers using dvd+rw-booktype prior to burning the DVD. If this is not possible with your writer you’ll have to look for another way to burn your DVD. Also be aware of the layer change which can cause some trouble with certain DVD players. I’ve finally split my data to two ordinary DVD-R...

SPIP | | Aktivitäten verfolgen RSS 2.0