Creating DVD Images for C
// The following code demonstrates how to create DVD images
using LEAD Multimedia toolkit:
#include "ltmm.h"
#include "ILTDvdWriter2.h"
#include <TChar.h>
LPOLESTR T2OLE(LPCTSTR lpt)
{
static OLECHAR lpw[512];
if(!lpt)
return NULL;
lpw[0] = L'\0';
MultiByteToWideChar(CP_ACP, 0, lpt, -1, lpw, 512);
return lpw;
}
LPTSTR OLE2T(LPCOLESTR lpw)
{
static TCHAR lpt[512];
if(!lpw)
return NULL;
lpt[0] = _T('\0');
WideCharToMultiByte(CP_ACP, 0, lpw, -1, lpt, 512, NULL, NULL);
return lpt;
}
void WaitForCompletion(IltmmConvert *pConvert)
{
long lState = ltmmConvert_State_Running;
MSG msg;
IltmmConvert_get_State(pConvert,
&lState);
while( lState != ltmmConvert_State_Stopped )
{
if( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)
)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
IltmmConvert_get_State(pConvert,
&lState);
}
}
int main()
{
IltmmConvert *pConvert = NULL;
IUnknown *pDvdWriter = NULL;
ILTDvdWriter *pIDvdWriter = NULL;
BSTR szFileName = NULL;
IltmmCompressors *pCompressors;
long lIndex = 0;
BOOL bRet = FALSE;
HRESULT hr;
CoInitialize(NULL);
// create a converter object
hr = CoCreateInstance(&CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER,
&IID_IltmmConvert, (void**) &pConvert);
// set up the converter:
IltmmConvert_put_TargetFormat(pConvert,
ltmmConvert_TargetFormat_DVD);
IltmmConvert_get_VideoCompressors(pConvert,
&pCompressors);
hr = IltmmCompressors_Find(pCompressors,
L"@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\\LEAD MPEG2 Encoder Also known as compressor, this is a module or algorithm to compress
data. Playing that data back requires a decompressor, or decoder.compressor Also known as an encoder, this is a module or algorithm to compress
data. Playing that data back requires a decompressor, or decoder.,
this is a module or algorithm to compress data. Playing that data back
requires a decompressor, or decoder Also known as a decompressor, this is a module or algorithm to decompress
data..
(2.0)", &lIndex);
hr = IltmmCompressors_put_Selection(pCompressors,
lIndex);
IltmmCompressors_Release(pCompressors);
IltmmConvert_get_AudioCompressors(pConvert,
&pCompressors);
hr = IltmmCompressors_Find(pCompressors,
L"@device:sw:{33D9A761-90C8-11D0-BD43-00A0C911CE86}\\LEAD MPEG Audio
Encoder (2.0)", &lIndex);
hr = IltmmCompressors_put_Selection(pCompressors,
lIndex);
IltmmCompressors_Release(pCompressors);
// 1- Create a DVD
image A set of files that contain all of the video and audio content for a
DVD, organized with a table of contents (optional). See also: Title, Chapter,
ISO Image An ISO image (.iso) is a disk image of a file system. It includes data
files that are contained in the ISO image along with filesystem metadata.
ISO images are an alternative to physical media for distribution of a
"DVD" over the Internet. Most operating systems allow ISO images
images to be "played" as if they were physical discs. See also:
DVD Image..
with 1 title The name for a group of related video files (called "Chapters")
on your DVD. For example, for a DVD called "My Summer Vacation,"
you might have the titles "Water Skiing," "New Friends,"
and "Hiking." For each of those titles, you might have one or
more different video files.
that contains 1 chapter The name for each individual video file on a DVD. For example, under
the title "Water Skiing", you might have the chapters "My
first try," "My first wreck," and "My first jump.":
szFileName = SysAllocString(T2OLE("c:\\MyVideos\\DaDa_CMP.avi"));
// Source video
IltmmConvert_put_SourceFile(pConvert,
szFileName);
SysFreeString(szFileName);
szFileName = SysAllocString(T2OLE("c:\\MyVideos\\DVDImage1"));
// Destination image folder
IltmmConvert_put_TargetFile(pConvert,
szFileName);
SysFreeString(szFileName);
IltmmConvert_StartConvert(pConvert);
// Wait for the conversion to finish. You can use a window
to receive notifications
WaitForCompletion(pConvert);
// Done
IltmmConvert_ResetTarget(pConvert);
IltmmConvert_ResetSource(pConvert);
// 2- Create a DVD image with 1 title that contains 2 chapters:
szFileName = SysAllocString(T2OLE("c:\\MyVideos\\DaDa_CMP.avi"));
// Source video
IltmmConvert_put_SourceFile(pConvert,
szFileName);
SysFreeString(szFileName);
szFileName = SysAllocString(T2OLE("c:\\MyVideos\\DVDImage2"));
// Destination image folder
IltmmConvert_put_TargetFile(pConvert,
szFileName);
SysFreeString(szFileName);
// Retrieve the DVD Writer interface
IltmmConvert_getSubObject(pConvert,
ltmmConvert_Object_Sink, &pDvdWriter);
IUnknown_QueryInterface(pDvdWriter, &IID_ILTDvdWriter,
(void**)&pIDvdWriter);
// Call ILTDVDWriter's Reset to defaults method
ILTDVDWriter_ResetToDefaults(pIDvdWriter);
// Set the DVD temporary files folder
szFileName = SysAllocString(T2OLE("C:\\Temp"));
// Destination image folder
ILTDvdWriter_put_TempPath(pIDvdWriter,
szFileName);
SysFreeString(szFileName);
// Set the TitleBreak property to FALSE.
// This will prevent the title from being written immediately
after the conversion
ILTDvdWriter_put_TitleBreak(pIDvdWriter,
VARIANT_FALSE);
// write the first chapter
IltmmConvert_StartConvert(pConvert);
// Wait for the conversion to finish. You can use a window
to receive notifications
WaitForCompletion(pConvert);
// You can change the source file before this step.
// This demonstration code uses the same file for all chapters.
// Create chapter 2.
IltmmConvert_StartConvert(pConvert);
WaitForCompletion(pConvert);
// Close the title
ILTDvdWriter_put_TitleBreak(pIDvdWriter,
VARIANT_TRUE);
// Done
IUnknown_Release(pDvdWriter);
pDvdWriter = NULL;
ILTDvdWriter_Release(pIDvdWriter);
pIDvdWriter = NULL;
IltmmConvert_ResetTarget(pConvert);
IltmmConvert_ResetSource(pConvert);
// 3- Create a DVD image with 2 titles, each containing 2
chapters:
szFileName = SysAllocString(T2OLE("c:\\MyVideos\\DaDa_CMP.avi"));
// Source video
IltmmConvert_put_SourceFile(pConvert,
szFileName);
SysFreeString(szFileName);
szFileName = SysAllocString(T2OLE("c:\\MyVideos\\DVDImage3"));
// Destination image folder
IltmmConvert_put_TargetFile(pConvert,
szFileName);
SysFreeString(szFileName);
// Retrieve the DVD Writer interface
IltmmConvert_GetSubObject(pConvert,
ltmmConvert_Object_Sink, &pDvdWriter);
IUnknown_QueryInterface(pDvdWriter, &IID_ILTDvdWriter,
(void**)&pIDvdWriter);
// Set the TitleBreak property to FALSE.
// This will prevent the title from being written immediately
after the conversion
ILTDvdWriter_put_TitleBreak(pIDvdWriter,
VARIANT_FALSE);
// Write the first chapter in the first title
IltmmConvert_StartConvert(pConvert);
// Wait for the conversion to finish. You can use a window
to receive notifications
WaitForCompletion(pConvert);
// Write the second chapter in the first title
// You can change the source file before this step, this demonstration
code uses the same file for all chapters.
IltmmConvert_StartConvert(pConvert);
WaitForCompletion(pConvert);
// Prepare for the second title
// Set the TitleBreak property to TRUE, so the the current
title can be flushed
ILTDvdWriter_put_TitleBreak(pIDvdWriter,
VARIANT_TRUE);
// Set the TitleBreak property to FALSE.
// This will prevent the title from being written immediately
after the conversion
ILTDvdWriter_put_TitleBreak(pIDvdWriter,
VARIANT_FALSE);
// Disable Overwrite so the title will be appended to an existing
dvd image
ILTDvdWriter_put_Overwrite(pIDvdWriter,
VARIANT_FALSE);
// Write the first chapter in the second title
IltmmConvert_StartConvert(pConvert);
// Wait for the conversion to finish. You can use a window
to receive notifications
WaitForCompletion(pConvert);
// Write the second chapter in the second title
IltmmConvert_StartConvert(pConvert);
WaitForCompletion(pConvert);
// Close the second title
ILTDvdWriter_put_TitleBreak(pIDvdWriter,
VARIANT_TRUE);
// restore the overwrite property
ILTDvdWriter_put_Overwrite(pIDvdWriter,
VARIANT_TRUE);
// Done
IUnknown_Release(pDvdWriter);
pDvdWriter
= NULL;
ILTDvdWriter_Release(pIDvdWriter);
pIDvdWriter
= NULL;
IltmmConvert_ResetTarget(pConvert);
IltmmConvert_ResetSource(pConvert);
IltmmConvert_Release(pConvert);
CoUninitialize();
return
0;
}