Posts Tagged ‘mencoder’

Convert avi to dvd with command line tools

February 24, 2009

Assume you have a divx movie (e.g. sneakers.avi) and two subtitle files (sneakersHUN.srt, sneakersENG.srt) that you want to convert into dvd format. In this blog entry I’ll only use command line tools. This is because there’s no need to write another “How to convert avi to dvd with Devede” article, and because most GUI tools available in Ubuntu are simple graphical frontends of ffmpeg, mencoder and dvdauthor (the command line tools described bellow).

Let’s get down to business:

1. Convert your .avi file with ffmpeg or mencoder to a suitable .mpg format

Using ffmpeg is less complicated because it needs much less command line options. As an example (converting an avi file into a pal dvd format):

ffmpeg -i film.avi -aspect 4:3 -target pal-dvd dvd.mpg

If using mencoder, a lot of command line options have to be added. To make my life easier, I use a bash script in that I can simply change the file name, aspect ratio and what else is needed. Here’s the script:

#! /bin/bash
# bash script for creating a pal dvd
# movie is sneakers!

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
-vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 \
-lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
keyint=15:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 25 \
-o sneakers.mpg sneakers.avi

Notes: the DVD format is heavily constrained, i.e. bitrates and screen sizes are pre-defined. Take a look at this table.

2. Add the subtitles with spumux

  • Create two xml files with the contents below, and save them as “spumuxHUN.xml” and “spumuxENG.xml” (one for each language) .
    <subpictures>
        <stream>
           <textsub filename="sneakersHUN.srt" characterset="ISO8859-2"
                        fontsize="28.0" font="devedesans.ttf" horizontal-alignment="left"
                        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="574"
                        force="yes"
            />
         </stream>
    </subpictures>
    

    Notes: the xml files contain the necessary information for spumux. Option names speak for themselves. One remark to “font=”: you can use whatever fonts you like, only copy the .ttf file into the ~/.spumux directory (devedesans.ttf is the only font in Ubuntu that’s available by default).

  • Create an mpg file with the subtitles embedded:

    spumux -s0 spumuxHUN.xml sneakersHUN.mpg
    rm sneakers.mpg
    spumux -s1 spumuxENG.xml sneakersHUNENG.mpg
    rm sneakersHUN.mpg

3. Create the dvd file system with dvdauthor in two steps:

  • Create a simple text file with the following content and save it as auth.xml
    <dvdauthor>
        <vmgm />
        <titleset>
            <titles>
                <subpicture lang="hu"/>
                <subpicture lang="en" />
                <pgc>
                    <vob file="sneakersHUNENG.mpg" />
                </pgc>
            </titles>
        </titleset>
    </dvdauthor>
    
  • type the following into a terminal:

    dvdauthor -o mydvd -x auth.xml

    Note: this will create the dvd filesystem in the mydvd folder.

      4. Burn the dvd! A simple command line tool to do this:

      growisofs -Z /dev/dvd -dvd-video mydvd/

      Be aware that the -Z option will erase the disk if it’s not empty!