Tuxicity's source

December 1, 2006

Avi to DVD with ffmpeg and dvdauthor

Filed under: Open Source, Tuxicity, Ubuntu — tuxicity @ 1:35 pm

sudo apt-get install ffmpeg dvdauthor

Normal screen:

ffmpeg -i film.avi -aspect 4:3 -target pal-dvd dvd.mpg (or ntsc-dvd)

Wide screen:

ffmpeg -i film.avi -aspect 16:9 -target pal-dvd dvd.mpg (or ntsc-dvd)

Make dvd files without menu in a dvd/ folder:

dvdauthor -o dvd/ -t dvd.mpg

Just add several movies this way
File the movies before burning in /dvd :

dvdauthor -o dvd/ -T

Burn:

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

A rewritable will be erased automatically.
Here is a script to somewhat automate this process, read it and make sure the settings are the way you want them, to make it executable save it as whatever.sh and do

chmod +x whatever.sh

to make it executable.
Run it as:

./whatever.sh /path/to/file_to_run.

I tried it and it seems to work fine with single files.

#!/bin/bash

#packages used: ffmpeg, dvdauthor, dvd+rw-tools

#TODO
#somehow do length/size detection and split onto multiple dvd’s
#port to VCD, SVCD

#FIXME
#cannot fast-forward through tracks

#Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#run
#runs the command and prints it to stderr
#only prints if $dryrun=true
run(){
echo -n “>> ” > /dev/stderr
if ! $dryrun; then
echo “$@” | tee /dev/stderr | sh –
return $?
else
echo “$@”
return 0;
fi
}

cleanup(){
if $cleanup && [ “$cleanuplist” ]; then
echo “# cleaning up…”
run rm -R $cleanuplist
fi
}

#Aspect-Ratio detection~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
getaspect(){
#2.350000 =Panavision (235:100)
#2.063888
#1.777777 =Widescreen (16:9)
#1.555555
#1.333333 =Normal (4:3)

#parses out `height x 10000 / width` from “ffmpeg -i”
#(no decimal numbers in bash)
aspect=`ffmpeg -i “$1” 2>&1 | grep “Stream\ #0.0″`
aspect=`echo “$aspect” | sed “s/.* \([1-9][0-9]*\)x\([0-9]*\).*/\10000 \/ \2/”`
echo “>> $aspect”
aspect=$(( $aspect ))
if [ $aspect -gt 20639 ]; then
#dvdauthor does not understand panavision aspect ratio (2.35)
#we must pad the video into widescreen (16:9)
aspect=”16:9″;
pana=”-s 720×380 -padtop 50 -padbottom 50″;
echo “# $1 is Panavision”
elif [ $aspect -lt 15555 ]; then
aspect=”4:3″
echo “# $1 is Normal.”
else
aspect=”16:9″
echo “# $1 is Widescreen”
fi
}

#Encoding~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
encode(){
#TODO do a better checking for DVD format
for avi in “$@”; do
case $avi in
*.DVD.mpg )
echo “# $avi is in DVD format, skipping…”
mpglist=”$mpglist \”$avi\””;;
* )
mpg=`echo “$avi” | sed “s/\.[^.]*$//g”`
mpg=”$mpg.DVD.mpg”
mpglist=”$mpglist \”$mpg\””

if ! [ -f “$mpg” ]; then
echo “# Encoding $mpg…”
if run “ffmpeg -i \”$avi\” -target $standard-dvd -y \
-aspect $aspect $pana $name.temp.DVD.mpg”; then
run “mv $name.temp.DVD.mpg \”$mpg\””
cleanuplist=”$cleanuplist \”$mpg\””
else
echo “# ffmpeg ERROR WHILE ENCODING \”$avi\””
exit 1
fi
else
echo “# $avi already encoded! Skipping…”
fi;;
esac
done
echo “# Encoding complete!”
}

#Authoring~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
author(){
if run dvdauthor -o $dvddir -v $standard+$aspect $mpglist; then
cleanup;
cleanuplist=”\”$dvddir\””
else
echo “# dvdauthor error”
exit 1;
fi
run dvdauthor -o “$dvddir” -T
}

#ISO creation~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
image(){
if run mkisofs -dvd-video -o $iso $dvddir; then
cleanup
cleanuplist=”\”$iso\””
else
echo “# ERROR: mkisofs”;
exit 1;
fi
#at this point you can view the iso with:
# mplayer dvd:// -dvd-device name.iso
}

#Burn~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
burn(){
if run growisofs -Z /dev/hdb=$iso -speed=8; then
cleanup
cleanuplist=””
else
echo “# ERROR: growisofs”
exit 1
fi
}

#displays help and exits
showhelp(){
helptext
exit 1
}

helptext(){
echo “Usage: `basename $0` [OPTIONS]… clip1.avi clip2.avi…” ;
echo “Convert each clip to .mpg, author to a folder, convert to .iso image,”;
echo “then finally burn to DVD.” ;
echo ” -n, –name base name for created files (recommended)” ;
echo ” -c, –cleanup will cleanup intermediate files” ;
echo ” -d, –dryrun will display but not execute commands”;
echo ” -h, –help show more options” ;
echo “”;
echo “Target options:”;
echo ” -e, –encode only encode the clips.”;
echo ” -a, –author stop after encoding and authoring the clips”;
echo ” -i, –image only create a .iso image of a DVD, no burning.”;
echo ” -b, –burn only burn the specified image, no processing”;
}

morehelptext(){
echo “”;
echo “MORE OPTIONS:”;
echo ” -p, –pal the PAL tv standard will be used (default NTSC)”;
echo “”
echo “Aspect options: (automatic aspect detection by default)”;
echo ” –norm clips will be encoded to normal 4:3″;
echo ” –wide clips will be encoded to widescreen 16:9″;
echo ” –pana clips will be encoded to panavision 2.35″;
echo “”;
echo “Process control options:”;
echo ” –no-encode – do not create DVD-compatible clips”;
echo ” –no-author – do not create a DVD-format directory tree”
echo ” –no-image – do notcreate ISO image for burning”;
echo ” –no-burn – disable burning”;
}

#Main~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Set defaults
encode=”true”
author=”true”
image=”true”
burn=”true”
dryrun=”false”
cleanup=”false”
standard=”ntsc” #TV standard to use

#Option processing
if ! [ “$1” ]; then
showhelp
fi

while [ “$#” -gt 0 ]; do
case $1 in
-h|–help) helptext; morehelptext; exit 0;;
-d|–dryrun ) echo “Doing a dry-run.”; dryrun=”true”; shift;;
-c|–cleanup ) echo “Will cleanup files.”; cleanup=”true”; shift;;
-p|–pal ) standard=”pal”; shift;;
–norm ) echo “Aspect set to Normal.”; aspect=”4:3″; shift;;
–wide ) echo “Aspect set to Widescreen.”; aspect=”16:9″; shift;;
–pana ) echo “Aspect set to Panavision.”; aspect=”16:9″;
pana=”-s 720×380 -padtop 50 -padbottom 50″; shift;;
–no-encode ) echo “Encoding disabled.”; encode=”false”; shift;;
–no-author ) echo “Authoring disabled.”; author=”false”; shift;;
–no-image ) echo “Imaging disabled.”; image=”false”; shift;;
–no-burn ) echo “Burning disabled.”; burn=”false”; shift;;
-e|–encode)
echo “Will only do encoding.”
burn=”false”; author=”false”; image=”false”; shift;;
-a|–author)
echo “Will only author DVD to ‘$name.dvd/’.”
burn=”false”; image=”false”; shift;;
-i|–image)
echo “Will create but not burn ‘$name.iso’.”
burn=”false”; shift;;
-b|–burn)
echo “Will only burn $2.”
iso=”$2″; burn; exit 0 ;;
-n|–name )
echo “Setting base name to ‘$2’.”
name=”$2″; dvddir=”$name.dvd”; iso=”$name.iso”; shift 2;;
-* ) echo “ERROR: option = $1”;showhelp;;
* ) break;;
esac
done

shift $(($OPTIND – 1)) #takes the processed options out of $@

#More defaults…
if ! [ “$name” ]; then
#basename for files to be created
#strips non-alphanumeric characters and the extension
name=`echo “$1” | sed -e “s/\.[^.]*$//” -e “s/[^[:alnum:]]/./g”`
dvddir=”$name.dvd” #folder to put DVD in
iso=”$name.iso” #iso file to be created & burned
fi

#main processing
if $encode; then
if ! [ “$aspect” ]; then
getaspect “$1”;
fi
encode “$@”
else
for mpg in “$@”; do
mpglist=”$mpglist \”$mpg\””
done
fi

if $author; then
author;
else
cleanuplist=””
fi

if $image; then
image ;
else
cleanuplist=””
fi

if $burn; then
burn;
fi
exit 0

22 Comments »

  1. When you say :
    “Make dvd files without menu in a dvd/ folder:

    dvdauthor -o dvd/ dvd.mpg”

    It kept giving me an error saying I needed to include “-t, -m, or -x” so I tried doing

    “dvdauthor -o SAW4/ -t SAW4 saw4.mpg”

    but it kept giving me a segmentation fault error. I then looked up another how-to using a similar method and they used

    “dvdauthor -o DVD/ -t final.mpg” and then “dvdauthor -o DVD/ -T”

    that didn’t return any segmentation errors and then I finished using your growisofs command

    Thanks for the how-to! I feel so accomplished now!

    Comment by Max — February 20, 2008 @ 7:01 pm

    • ” dvdauthor -o DVD/ -T

      was missing in the initials description. Thanks for sharing.

      To be somewhat more specific: Without the “dvdauthor -o DVD/ -T” command in my case

      ” growisofs -Z /dev/hdd -dvd-video dvd/

      returns:

      ” Executing ‘genisoimage -dvd-video dvd/ | builtin_dd
      of=/dev/hdd obs=32k seek=0’
      I: -input-charset not specified, using utf-8 (detected
      in locale settings)
      genisoimage: No such file or directory. Failed to open
      VIDEO_TS.IFO
      genisoimage: Can’t open VMG info for ‘dvd/’.
      genisoimage: Unable to parse DVD-Video structures.
      genisoimage: Could not find correct ‘VIDEO_TS’
      directory.
      genisoimage: Unable to make a DVD-Video image.
      Possible reasons:
      – VIDEO_TS subdirectory was not found on specified
      location
      – VIDEO_TS has invalid contents
      😦 write failed: Input/output error

      Comment by Hans — August 4, 2009 @ 8:17 am

  2. uh, thanks for the code, but could you post it with tags or something around? It’s full of unicode..

    Comment by k — August 8, 2008 @ 6:07 pm

  3. root@socrates:/home/chris/makedvd$ growisofs -Z /dev/hdb -dvd-video dvd/
    Executing ‘mkisofs -dvd-video dvd/ | builtin_dd of=/dev/hdb obs=32k seek=0’
    Setting input-charset to ‘ISO-8859-1’ from locale.
    mkisofs: No such file or directory. Failed to open ‘dvd//VIDEO_TS/VIDEO_TS.IFO’.
    mkisofs: Can’t open VMG info for ‘dvd/’.
    mkisofs: Unable to parse DVD-Video structures.
    mkisofs: Could not find correct ‘VIDEO_TS’ directory.
    mkisofs: Unable to make a DVD-Video image.
    😦 write failed: Input/output error
    root@socrates:/home/chris/makedvd$ ls dvd/VIDEO_TS/
    VTS_01_0.BUP VTS_01_0.IFO VTS_01_1.VOB VTS_01_2.VOB

    Comment by chris — August 9, 2008 @ 11:22 am

  4. Hi, thank you very much for your code.

    But, when I try it I could this error message:

    marcelo@laia:~/bin$ ./gravar_dvd.sh ~/português.avi
    ./gravar_dvd.sh: line 253: unexpected EOF while looking for matching `”‘
    ./gravar_dvd.sh: line 260: syntax error: unexpected end of file
    marcelo@laia:~/bin$

    Could you help me? If is possible, could you send de answer to my mail account?

    Bests.

    Comment by Marcelo — November 21, 2008 @ 2:06 pm

  5. The topic is quite hot in the net right now. What do you pay the most attention to when choosing what to write ?
    p.s. Year One is already on the Internet and you can watch it for free.

    Comment by Watch Year One Online Free — June 20, 2009 @ 9:00 pm

  6. Great tutorial, works perfectly today is 19 Ot 2009

    Comment by Barry de Graaff — October 19, 2009 @ 5:00 pm

  7. For real. Thanks for publishing this.

    Comment by cbarnardo — January 8, 2010 @ 7:57 am

  8. ALQUEM POTE ME AJUDAR QUERO FAZER UM SLIDESHOW COM FOTOS E MUSICAS E SO VEM ESSE ERRO. JÁ REMOVI TODOS OS PACOTES FFMPEG E CONSEGUI FAZER MAS SEM MUSICA O QUE A CONTECE COM OS PACOTES FFMPEG DO MANDRIVA 2010

    [dvd-slideshow] fade_in_time=0:0:3.000 fade_out_time=0:0:3.000
    [dvd-slideshow] total_audio_length=0:4:8.000
    [dvd-slideshow] ###############
    [dvd-slideshow] Creating ac3 audio for /home/usuario/My eBooks/beyonce .mp3…
    [dvd-slideshow] ERROR during ffmpeg execution!
    [dvd-slideshow] see /home/usuario/tmp//Unnamed/dvd-slideshow.log for details
    [dvd-slideshow] cleanup…

    Comment by JONAS — January 22, 2010 @ 1:09 am

  9. […] Fonti: ffmpeg dvdauthor growisofs blog Tuxicity […]

    Pingback by aqquadro » Blog Archive » AVI to MPG per creare un DVD-video con ffmpeg, dvdauthor e growisofs – Debian GNU/Linux — May 9, 2010 @ 10:08 am

  10. growisofs now uses -dvd-compat instead of -dvd-video.

    Comment by Ricky — July 22, 2010 @ 8:31 pm

  11. Debian Notes…

    dvdauthor dvdauthor Fresh Install Run the following commands in the terminal as root: apt-get purge xsane xsane-common aumix exfalso quodlibet hplip libsane sane-utils aumix-common quodlibet-ext quodlibet-plugins orage xfce4 xfce4-goodies xfce…

    Trackback by Matt's Linux Stuff — April 29, 2011 @ 8:10 am

  12. I appreciate your post. I also wrote that SMS advertising provides a cost effective method of targeting promotions to specific customer profiles. You might want to remind customers of specific events or promotions, but for whatever reasons, SMS allows you to pass information directly to the right customer at very affordable prices and fast delivery.
    iso 9000

    Comment by ISO 9000 — October 4, 2011 @ 9:28 am

  13. here is a script I Put together for windows 7.
    You just put your media files in the media folder and it trans-codes, sets up the DVD folder, creates the ISO, and finally burns to DVD.
    two things to note: some media files trans-code to larger than 4.3 GB and will not fit a normal DVD even with over burn enabled (out of 100 i have only had this happen with 3), and only one DVD per media file with no menu. If you want menus and more than 1 media file per DVD then you will have to edit the XML.
    I have an 8 core processor in one computer and 2 cores in the other. the script works well in both with any editing. it is a 2 pass script to get the best quality.
    2 cores = 50+ fps per pass, 8 cores = 150+ fps per pass. on computer and standard TV, not much difference between one pass and two pass. high def is a different story.
    in your project folder you will also want to include the following files:

    dvdauthor.exe
    ffmpeg.exe
    growisofs.exe
    iconv.dll
    libgcc_s_dw2-1.dll
    mencoder.exe
    mkisofs.exe
    nircmd.exe
    nircmdc.exe
    zlib1.dll

    :: ******************************** CreateDVD.cmd
    @echo off
    cls

    for /r %%a in (.\Media\*.*) do (
    rem ****** Transcode to mpg ******
    title transcode to mpg2 %%~na
    ffmpeg -threads 8 -i “%%a” -sameq -vcodec mpeg2video -acodec copy -copyts -qscale 1 -me_method epzs -b 1200k -minrate 1200k -maxrate 1200k -bufsize 500k -pass 1 -passlogfile foo -target ntsc-dvd -pass 1 -passlogfile foo -y nul.mpg

    ffmpeg -threads 8 -i “%%a” -sameq -vcodec mpeg2video -acodec copy -copyts -qscale 1 -me_method epzs -b 1200k -minrate 1200k -maxrate 1200k -bufsize 500k -pass 1 -passlogfile foo -target ntsc-dvd -pass 2 -passlogfile foo -y newmovie1.mpg

    rem ****** Createing DVD structure ******
    title Createing DVD structure %%~na
    if exist newmovie1.mpg (if not exist dvd md dvd)
    if exist newmovie1.mpg (if not exist “.\dvd\%%~na” md “.\dvd\%%~na”)
    if exist newmovie1.mpg dvdauthor -o “.\dvd\%%~na” -x dvd-project.xml

    rem ****** create DVD image ******
    title Createing ISO %%~nxa
    if exist newmovie1.mpg mkisofs -dvd-video -p “RSS” -publisher “RSS” -V “%%~na” -v -o “%%~na.iso” “DVD\%%~na”
    if exist *.iso md iso &move “%%~na.iso” iso

    rem ****** write to DVD ******
    title ****** write to DVD %%~na ******
    growisofs -dvd-compat -Z d:=”iso\%%~na.iso”
    start “” /min nircmd.exe cdrom open

    rem ****** clean Up ******
    if exist newmovie1.mpg ren newmovie1.mpg “%%~na.mpg”
    if exist *.mpg md mpg&move “%%~na.mpg” mpg
    if exist foo-0.log del foo-0.log
    )

    pause
    exit
    :: ******************************** end of CreateDVD.cmd

    :: ******************************* dvd-project.xml

    :: ******************************* end dvd-project.xml

    Comment by Rob Moore — February 4, 2012 @ 5:10 am

  14. the blog did not like my xml, so just rem to enclose each line with a greater/lesthan sign
    :: ******************************* dvd-project.xml
    dvdauthor
    vmgm
    menus
    video format=”ntsc” aspect=”16:9″ widescreen=”nopanscan”/
    /menus
    /vmgm
    titleset
    titles
    video format=”ntsc” aspect=”16:9″ widescreen=”nopanscan”/
    pgc
    vob file=”newmovie1.mpg” chapters=”0,5:00,10:00,15:00,20:00,25:00,30:00,35:00,40:00,45:00,50:00,55:00,60:00,70:00,80:00,90:00,100:00,120:00,140:00,160:00,180:00,200:00,220:00,260:00″ /
    /pgc
    /titles
    /titleset
    /dvdauthor
    :: ******************************* end dvd-project.xml

    Comment by Rob Moore — February 4, 2012 @ 5:19 am

  15. it really bothered me that I could not get a 2:30 hour movie on to a DVD using ffmpeg like I was doing in the windows script above.
    I have put 5 hours on a DVD using a GUI that is built around ffmpeg and dvdauthor.
    So I spent most of the night trying to figure where I went wrong.
    it is so simple once I figured it out. I was trying too hard,
    -target ntsc-dvd automatically fills in all the needed parameters to make a playable DVD.
    I was trying to input parameters that were already set by the -target parameter.
    I was able to cut the file size in half by using -s qvga (320×240) parameter
    here is my revised ffmpeg command lines for the script above.

    rem ****** Transcode to mpg ******
    rem ****** -s qvga is set to make frame size half, making bandwidth half = longer play time on dvd
    rem ****** dvd player will resize to screen output. remove -s qvga for better quaility
    rem ****** -target ntsc-dvd sets all options to make a ntsc dvd. There are other -target options such as pal-dvd,vcd,svcd and others

    ffmpeg -i “%%a” -target ntsc-dvd -aspect 16:9 -s qvga -pass 1 -passlogfile foo -y nul.mpg
    ffmpeg -i “%%a” -target ntsc-dvd -aspect 16:9 -s qvga -pass 2 -passlogfile foo -y newmovie1.mpg

    I tested it, and the file size is about half what it was with the old ffmpeg command line.
    My DVD player re sized the movie to the proportion of mt TV without much of a quality loss

    Comment by Rob Moore — February 4, 2012 @ 5:45 pm

  16. won a libel case against British newspaper, the Sun, for
    accusing Diaz of having an affair with her friend, TV producer, Shane Nickerson.
    Now Kudrow is back on top thanks to some out-of-the-box thinking.
    Have you been watching the new season of Dancing with the Stars since
    the show premiered.

    Comment by Marcella — May 25, 2013 @ 7:12 pm

  17. I like the valuable info you provide in your articles. I’ll bookmark your blog and check again here frequently. I’m quite sure I will learn
    a lot of new stuff right here! Good luck for the next!

    Comment by chiropractors spokane — June 24, 2013 @ 11:47 pm

  18. Ahaa, its fastidious dialogue regarding this paragraph at this place
    at this blog, I have read all that, so at this time me also commenting at this place.

    Comment by Star — June 30, 2013 @ 12:41 pm

  19. Hello, i think that i saw you visited my site thus i came to
    “return the favor”.I’m attempting to find things to enhance my web site!I suppose its ok to use some of your ideas!!

    Comment by Turbo Force onde comprar — June 30, 2013 @ 5:36 pm

  20. This excellent website really has all of the info I wanted about this subject and didn’t know who to ask.

    Comment by click here — July 3, 2013 @ 10:13 am

  21. Fckin awesome things here. I am very glad to see your article. Thanks a lot and i’m looking forward to contact you. Will you please drop me a mail? bkfbecfeckkd

    Comment by Johne706 — September 13, 2014 @ 5:38 am


RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.