views:

231

answers:

4

My goal is to create a program that will take an AVI file as input and then do whatever is necessary to burn it to a DVD.

Currently, I use three separate programs to accomplish this. The first tool requires me to convert it from an AVI file to an MPEG. The second tool takes that MPEG and creates DVD files (a VIDEO_TS folder, with a few files inside of it). The third tool burns the folder to the DVD. I would like to combine these three tools into one, and if possible skip the AVI to MPEG conversion and just create the DVD files and burn them.

The target platform is Windows 7 and the language I'm going to use is C++.

What libraries or command line programs will help me on my quest for glory?

EDIT: To clarify, I want to create a video DVD to play movies on a DVD player. (Thanks Jerry)

EDIT 2: I ended up using Python on Linux to automate everything. Here is the script in case anyone needs it. (Note: this is my first python script so it probably isn't very good)

import sys
import os
import shutil
from subprocess import call

# step 1: call ffmpeg and convert the input avi to an mpeg-2
def avi_to_mpeg(input, output):
    return call(["ffmpeg", "-i", input, "-target", "ntsc-dvd", "-threads",  "4", output])

# step 2: create the xml file needed for dvdauthor
def create_xml_file(mpg_source, xml_file):
    with open(xml_file, "w") as file:
        file.write("<dvdauthor>\n")
        file.write("\t<vmgm />\n")
        file.write("\t<titleset>\n")
        file.write("\t\t<titles>\n")
        file.write("\t\t\t<pgc>\n")
        file.write("\t\t\t\t<vob file=\"" + mpg_source + "\" />\n")
        file.write("\t\t\t</pgc>\n")
        file.write("\t\t</titles>\n")
        file.write("\t</titleset>\n")
        file.write("</dvdauthor>\n")
    return os.path.isfile(xml_file)

# step 3: invoke dvdauthor
def author_dvd(mpg_source):
    return call(["dvdauthor", "-o", "mkdvd_temp", "-x", xml_file])

# step 4: finally, burn the files to the dvd
def burn_dvd(dvd_target):
    return call(["growisofs", "-Z", dvd_target, "-dvd-video", "mkdvd_temp"])

# step 5: clean up the mess
def clean_up(mpg_source, xml_file):
    shutil.rmtree("mkdvd_temp")
    os.remove(mpg_source)
    os.remove(xml_file)

def eject(dvd_target):
    return call(["eject", dvd_target])

def print_usage():
    print "mkdvd by kitchen"
    print "usage: mkdvd -s file.avi -t /dev/disc"
    print "  -s : Input .AVI file"
    print "  -t : Target disc, /dev/dvd for example"

def get_arg(sentinel):
    last_arg = ""
    for arg in sys.argv:
        if last_arg == sentinel:
            return arg
        last_arg = arg
    return None

# program start

avi_source = get_arg("-s") # input .avi file
dvd_target = get_arg("-t") # the disc to burn it to (/dev/dvd for example)

if avi_source == None or dvd_target == None:
    print_usage()
    sys.exit("Not enough parameters.")

if os.path.isfile(avi_source) == False:
    sys.exit("File does not exists (" + avi_source + ")")

mpg_source = avi_source + ".mpg"

if avi_to_mpeg(avi_source, mpg_source) != 0:
    sys.exit("Failed to convert the AVI to an MPG")

xml_file = mpg_source + ".xml"

if create_xml_file(mpg_source, xml_file) == False:
    sys.exit("Failed to create the XML file required by dvdauthor")

if author_dvd(mpg_source) != 0:
    sys.exit("Failed to create the DVD files")

if burn_dvd(dvd_target) != 0:
    sys.exit("Failed to burn the files to the disc")

print "mkdvd has finished burning " + avi_source + " to " + dvd_target
print "Cleaning up"

clean_up(mpg_source, xml_file)
eject(dvd_target)
+1  A: 

Try the Primo DVD components, they also have a mpeg-2 encoding library.

Alternatively, use ffmpeg library to cvonvert your avis.

gbjbaanb
+1  A: 

The question is whether you want to create a video DVD (i.e. something that will play in a normal DVD player) or just save a file that happens to contain video to a data DVD disc.

If you want something that will play in a DVD player, then you'll need to transcode it from AVI into the MPEG 2 encoding that a DVD player expects, and then turn the MPEG2 bit stream into VOB files, and create the VIDEO_TS (and such) directories that are required for any DVD.

If you just want to burn the file to a data DVD, you can use (for one example) Microsoft's Image Mastering API (IMAPI); I believe version 2 of the API is current, so the main things you'll need to use will be the COM interfaces IFileSystemImage (to create an image file) and IDiscFormat2Data to write the data to the disc.

Jerry Coffin
Thanks, I've clarified my post.
kitchen
+2  A: 

I know you are using Windows, but here are the steps I take to create a DVD from multiple AVIs on linux. The main three programs are ffmpeg to do the transcoding, dvdauthor to build the DVD filesystem, and growisofs to make a DVD image out of the DVD filesystem. I think you can find windows binaries for each of them through Google (I was just able to rather quickly, but I don't want to paste all of the links).

  • Transcode each avi:

    ffmpeg -i <infile.avi> -target ntsc-dvd -threads 2 <outfile.mpg>
    
  • Create xml file for DVD author:

    Example:

    <dvdauthor dest="dvd">
    <vmgm>
    </vmgm>
    <titleset>
        <titles>
            <pgc>
                <vob file="<file1.mpg>" chapters="0,5:00,10:00,15:00,20:00,25:00,30:00,35:00,40:00" />
            </pgc>
            <pgc>
                <vob file="<file2.mpg>" chapters="0,5:00,10:00,15:00,20:00,25:00,30:00,35:00,40:00" />
            </pgc>
        </titles>
    </titleset>
    </dvdauthor>
    
  • Create DVD file structure (will create it at the dest shown above):

    dvdauthor -x <xmlfile.xml>
    
  • Roll filesystem into an iso and burn it.

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

    where dvd/ is where the DVD filesystem was created.

This process could be automated fairly easily by just calling the correct command line programs and creating the dvdauthor xml file. You'll want to read the documentation for dvdauthor to find out all the details about the xml file that defines your DVD. You'll also probably have to replace /dev/dvd/ in the growisofs command to the windows DVD burner drive letter.

About your hope that you could skip the transcode from avi to mpeg-2: there is no way to do this and still make it compatible with the DVD standard which strictly requires MPEG-2 video in an MPEG-PS (Program Stream) container.

Jason
Well, I'll just burn movies on Linux from now on because it's much easier to do what I want. Anyways, I used all of your advice and wrote a python script to automate it. Thanks for your help.
kitchen
A: 

You may try this DVD burning software, I always use it to convert and burn video to DVD to play on my home DVD player, my friends recommend it to me, it's safe and works pretty well for me. And here is a step by step guide about how to download and use it

maccolar