Converting DivX/XviD AVI to DVD with FFMpeg

I recently bought a DVD burner, and I’ve been experimenting with the different software for video conversion, mastering, and burning in Linux.

Background

I’ve used Transcode and Ripmake in the past to do DVD-to-SVCD and AVI-to-SVCD reencodes. The problem I had with those tools is that they default to using MJPEG Toola, which I have never managed to get reasonable performance with. My 2.4ghz P4 only gets ~12fps when transcoding using tmarihis method. Recompiling with GCC 3.4 and all optimizations enabled brought me up to ~18-20fps, but this is still not acceptable.

Ripmake also seems to default to non-anamorphic DVD encodes. I don’t know if this can be changed, but it’s certainly not desirable.

Enter FFmpeg

Fortunately, I’ve had much better luck with FFmpeg’s performance. It also understands enough codecs to work directly on an AVI and spit out DVD-ready MPEG-2 video.

Software and Assumptions

I’m running Debian sarge (testing), with Christian Marillat’s excellent Debian video packages. I have the following packages installed:

  • ffmpeg 2:20050304-0sarge0.0
  • libxvidcore4 2:1.0.2-sarge0.0
  • dvdauthor 0.6.10-4
  • dvd+rw-tools 5.21.4.10.8-1

For this example, we’ll assume that you have a 1.85:1 ratio XviD AVI to convert, though it should be incredibly obvious how to convert a 1.33:1 video as well.

Reencoding

Reencoding the AVI is simple:

$ ffmpeg -i my_video.avi -target dvd -aspect 16:9 -sameq my_dvd_video.mpg

That’s all there is to it. The -target dvd option causes FFMpeg to handle all the niggly bits necessary to convert to DVD, including scaling the video frame, resampling audio, and so forth. According to the FFmpeg documentation, -sameq “uses in the encoder the same quality factor than in the decoder. It allows to be almost lossless in encoding.” Sounds good to me.

I get just over 25fps on my system using this method, with very acceptable output quality.

Mastering & Burning

Now, we have to master the DVD image. You’ll need a copy of dvdauthor for this.

Create the DVD structure:

$ mkdir DVD
$ dvdauthor --title -f my_dvd_video.mpg -o DVD
$ dvdauthor -T -o DVD

The DVD structure will now be in the “DVD” directory. Now we just have to burn this to our DVD. You will need to be root to do this.

# growisofs -dvd-compat -dvd-video -speed=4 -Z /dev/dvd ./DVD/*

You can change the speed argument to suit your burner and media speed. You can also drop the contents of the VIDEO_TS folder into a K3b DVD Video project, if you prefer a GUI.

And that’s it. You should be able to drop the burned disc into your DVD player and enjoy.

Edit: Fixed Christian’s address.

25 Responses to “Converting DivX/XviD AVI to DVD with FFMpeg”

  1. thomas Says:

    Yes, but do you know (or know anyone who knows)
    how to get a true 1.85 aspect ratio? I’m trying to make
    one now, and don’t want to have to settle for 16:9.
    Thanks.

  2. Nibiru Says:

    Try the following!

    $ ffmpeg -i my_video.avi -target dvd -aspect 4:3 -sameq my_dvd_video.mpg

  3. Brendan Says:

    I have the same set up as above other than I am runnign Fedora Core 3. When I try to author the DVD I get the following error:

    WARN: Skipping sector, waiting for first VOBU

    and no vob is created.

    Do you have any thoughts on this?

  4. latcho Says:

    is there a way to loop or combine xvid files to make a new videofile with ffmpeg ?
    i want to loop clips x-times as a single smoothly playing track.
    any (other) suggestions ?
    thanks

  5. Ian Eure Says:

    “is there a way to loop or combine xvid files to make a new videofile with ffmpeg?
    i want to loop clips x-times as a single smoothly playing track.
    any (other) suggestions?”

    None that I’m aware of. Try using AVIDemux.

  6. video Says:

    I conver a avi to fle with ffmpeg.But audio missed.Why?

  7. Gergely Kontra Says:

    Hi!

    Just a quick question: how is the final size controlled?
    What if I’d like to write 2 avis to one DVD?
    What about 2 pass encoding?

    thx

  8. Ian Eure Says:

    Gergely,
    Final size is determined by FFmpeg. The -sameq argument tells it to try to keep the same level of quality. In my experience, the MPEG-2 files it outputs are around 1.5gb. You can therefore fit 3-4 files (~3.5 hrs) on a single DVD. Just pass the additional files to dvdauthor.

    Two-pass encoding is pointless. I noticed no degradation of quality from the original AVI, so you’re just burning CPU cycles at that point.

  9. Dave Says:

    Thanks for nice howto :) I was using MPlayer to create an MPEG-2, but it wasn’t very good - lot of errors, horrible sound and so.
    I just wanted to show you one nice option for DVDAuthor:
    dvdauthor -o ./dvd -c 0,05:00,10:00,15:00,20:00,25:00 film-dvd-sub.mpg
    That -c will split DVD to chapters long five minutes. Maybe you know it :)

  10. Dave Says:

    And one little question - will that works for some mpg > mpeg-2? Or I’ll have to do that with other options, or program?

  11. Max Says:

    Hi,
    First I want to thank all the people who participate for the construction of this web-site.
    It is very usefull…..thank you
    then I have a couple of questions:

    …please keep in mind I am not an expert in this…

    1) How do I know what type of aspect ratio I have in my original DivX or avi file? Knowing that what type of aspect ratio should I use during the conversion?

    2) Using the command that I found in this site
    I was able to convert a *.avi movie and the sound and the aspect ratio are good.
    I havn’t changed any command just used the initial command I found.
    But when the 2 folder VIDEO_TS and AUDIO_TS
    have been generated, I realize that in the AUDIO_TS
    there are no files …..but in what I get the sound i good
    Why?

    Than you very much for all

  12. waterox Says:

    Just to mention K3B now has a tool for authoring dvds. You can drop the files into the coreect directory. This would save time on dvdauthor and growisofs.

  13. Woonis Says:

    Thanks! I was trying to do this using mencoder and that is a vast insane wasteland of confusion compared to the ffmpeg command-line options. From what I understand they both use the same libav backend anyway. Great tutorial!

  14. Keef Says:

    Unfortunately that ffmpeg command generates errors with high quality video files as the files generated can have “bitrate spikes” where the bitrate goes higher than the dvd player can handle, which stops lot of DVD players from playing the DVD Disc.

    Also I recommend using mencoder I’m getting 60fps encoding instead of 35fps.

    he’s a batch file you can use to encode dvd compliant PAL mpeg2 files

    set /p inputfile=Input File:

    set outputfile=c:\outpufile.mpg

    rem Change fps to 29.97 if NTSC, 25 for PAL
    set fps=25
    set aspect=16/9

    mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:acodec=ac3:abitrate=192:aspect=%aspect%:vqmin=2:vqmax=8 -ofps %fps% -o “%outputfile%” “%inputfile%”

  15. Siddharth Menon Says:

    Here is a great advance tutorial for converting DVD to Xvid.

    Its not for 1st timmers but for those who really want that extra quality from there video.

    Here is the link this tutorial is by Sujit Mohan
    http://vtalk2.com/forum/index.php?showtopic=309

  16. David Says:

    Just been using thesse instructions and was tripped up my the wild card expantion on the ‘growisofs’.

    Issuing the command in the mannor described on this page caused growisfs to complain about an invalid VIDEO_TS directory.

    Therefore I had to change the commmand from:
    growisofs -dvd-compat -dvd-video -speed=4 -Z /dev/dvd ./DVD/*
    to:
    growisofs -dvd-compat -dvd-video -speed=4 -Z /dev/dvd ./DVD

    maybe growisofs has changed since the document was written. I am using version 7.0 (mkisofs 2.01.01a05-unofficial-iconv)

    Otherwise thanks for the consise DVD authoring instructions.

  17. Art Says:

    Great site!

    What is the method when you wish to have 2 (different) video titles on the same dvd?

  18. Ian Eure Says:

    Art,

    Just add more “-f” options to dvdauthor, one per title on the DVD.

  19. FFmpeg mpeg2 DVD movie « hardyweb:perjalanan hidupkuā„¢ Says:

    [...] 1. atomizedĀ  [...]

  20. Wombats next five kilometers » Blog Archive » My top 10 Ubuntu programs Says:

    [...] do, it does it WELL. I couldn’t begin to tell you all the ins and outs of this program…Here is a good place to start if you’re looking to make DVD complaint MPEG [...]

  21. Gary Says:

    The questions about output file size and vbr are actually good ones. I have an AVI file that is over 3 hours long. If I don’t specify the output size, it comes in at 6.2G after a single pass. The quality is as good as the original, but I’d like it to fit on a single layer DVD. This implies going to vbr, which means two passes.

    When I tried two passes (setting -pass 1 and -pass 2 as appropriate), it created an output MPEG each time and both were the same 6.2G. I tried limiting the file size (-fs 43000000) and it just truncated the file. There is something else required that I’m missing and the man page is not exactly a model of clarity on this issue.

    Any hints would be appreciated.

  22. stephen Says:

    Gary, you are looking for the -b option, which will set the video bitrate. When I used this command it defaulted to a bit rate of 6000000 b/s, whereas a bitrate as low as 3000000 b/s is acceptable for most material (especially using lower resolutions)

  23. Mohammad Says:

    Thanks for the tutorial. I downloaded an avi movie and wanted to convert it to DVD to watch it on TV. I didn’t have a DVD burner on my Linux laptop, so tried to do it at work on a windows machine using Nero. I failed two times to burn the DVD using Nero and wasted 4 hours of my time. Then I gave a try to Mac and iDVD. It comes with beautiful themes and menus for DVD, but I found that, it doesn’t do what it is supposed to do (Converting Movies). So I decided to do it using Linux and came across your tutorial. I converted my movie in less than half an hour (In nero takes 2 hours). I made my DVD schema and then transfered the whole thing to Mac computer with DVD burner. I simply burned everything as data, and got my DVD working.

    If you don’t have anything on your AUDIO_TS directory, it s fine. I’m not sure, but I think that file should contains files for special sound effects.

  24. Chris Davies Says:

    Many thanks for this quick guide. I found also that the growisofs command didn’t work for me, as cited. Instead, I found I needed to use this:

    growisofs -dvd-compat -speed=4 -Z /dev/dvd -dvd-video DVD

    (Note the change in order of the arguments and the DVD folder path)

  25. Steve Marks Says:

    Greetings - I have been using Slackware since 93 or 94. I was using transcode to convert my videos to DVD format, getting painfully slow results. Using ffmpeg, I was able to convert a 2:55 avi to DVD at 33fps on my 2.2ghz AMD laptop, much quicker than previously converted 1:27 long video, using optimized transcode. I compile most all add on software, so that it is tailored for this cpu. That is, anything within reason. I don’t have time to build Mozilla from source…heh. Seriously, I wanted to thank you for making this information available. I love anything that can be done from the command line as I have been a quadriplegic since 1988 and mice give me a fit. As Chris noted above, growisofs works like a champ as long as you provide the right path.

Leave a Reply