How to Use the DVD Writer to Write a DVD Image

Use the DVD Writer to write 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.. to the hard disk. To write to a DVD, perform the following steps:

1.

Declare the following structure that will be filled with the 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." names, as follows:

typedef struct _tagDVDTITLES

{

   char pszChapters[2][256];

} DVDTITLES;

2.

Declare the following function to dispatch any incoming messages:

C Source

void WaitForCompletion(IltmmConvert *pConvert)
{
long lState = ltmmConvert_State_Running;
MSG msg;

// Get the conversion state

   IltmmConvert_get_State(pConvert, &lState);

// Dispatch messages during conversion
 

   while( lState != ltmmConvert_State_Stopped )
{
if( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

      IltmmConvert_get_State(pConvert, &lState);
}
}

 

C++ Source

void WaitForCompletion(IltmmConvert *pConvert)
{
long lState = ltmmConvert_State_Running;
MSG msg;
// Get the conversion state
pConvert->get_State(&lState);
// Dispatch messages during conversion
while( lState != ltmmConvert_State_Stopped )
{
if( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

      pConvert->get_State(&lState);
}
}

3.

Declare the following function to add the resize filter:

C Source

BOOL AddResizeFilter(IltmmConvert *pConvert)

{

   IltmmProcessors* pProcessors;

   IltmmProcessors* pSelProcessors;

   long lIndex = 0;

   BSTR bstr;

   IltmmProcessor* pProc;

   HRESULT hr;

   // Get the video processor's pointer

   hr = IltmmConvert_get_VideoProcessors(pConvert, &pProcessors);

   if(FAILED(hr))

   {

      MessageBox(NULL, "Error working with video processors", "Error", MB_OK);

      return FALSE;

   }

   // Get the selected video processor

   hr = IltmmConvert_get_SelectedVideoProcessors(pConvert, &pSelProcessors);

   if(FAILED(hr))

   {

      MessageBox(NULL, "Error working with video processors", "Error", MB_OK);

      IltmmProcessors_Release(pProcessors);

      return FALSE;

   }

   // Find the index for the resize filter

   bstr = SysAllocString(T2OLE("@device:sw:{E526D606-22E7-494C-B81E-AC0A94BFE603}\\{E2B7DCA5-38C5-11D5-91F6-00104BDB8FF9}"));

   hr = IltmmProcessors_Find(pProcessors, bstr, &lIndex);

   SysFreeString(bstr);

   if( lIndex != -1 )

   {

      // Add the resize filter

      IltmmProcessors_Item(pProcessors, lIndex, &pProc);

      hr = IltmmProcessors_RemoveAll(pSelProcessors);

      IltmmProcessors_Add(pSelProcessors, pProc, 0);

      IltmmProcessors_Release(pProc);

      IltmmProcessors_Release(pProcessors);

      IltmmProcessors_Release(pSelProcessors);

      return TRUE;

   }

   else

   {

      IltmmProcessors_Release(pProcessors);

      IltmmProcessors_Release(pSelProcessors);

      return FALSE;

   }

   return FALSE;

}

C++ Source

BOOL AddResizeFilter(IltmmConvert *pConvert)

{

   IltmmProcessors* pProcessors;

   IltmmProcessors* pSelProcessors;

   long lIndex = 0;

   BSTR bstr;

   IltmmProcessor* pProc;

   HRESULT hr;

   // Get the video processor's pointer

   hr = pConvert->get_VideoProcessors(&pProcessors);

   if(FAILED(hr))

   {

      MessageBox(NULL, "Error working with video processors", "Error", MB_OK);

      return FALSE;

   }

   // Get the selected video processor

   hr = pConvert->get_SelectedVideoProcessors(&pSelProcessors);

   if(FAILED(hr))

   {

      MessageBox(NULL, "Error working with video processors", "Error", MB_OK);

      pProcessors->Release();

      return FALSE;

   }

   // Find the index for the resize filter

   bstr = SysAllocString(T2OLE("@device:sw:{E526D606-22E7-494C-B81E-AC0A94BFE603}\\{E2B7DCA5-38C5-11D5-91F6-00104BDB8FF9}"));

   hr = pProcessors->Find(bstr, &lIndex);

   SysFreeString(bstr);

   if(lIndex != -1)

   {

      // Add the resize filter

      pProcessors->Item(lIndex, &pProc);

      hr = pSelProcessors->RemoveAll();

      pSelProcessors->Add(pProc, 0);

      pProc->Release();

      pProcessors->Release();

      pSelProcessors->Release();

      return TRUE;

   }

   else

   {

      pProcessors->Release();

      pSelProcessors->Release();

      return FALSE;

   }

   return FALSE;

}

 

4.

Configure the resize settings.

C Source

void ConfigureResizeFilter(IltmmConvert *pConvert, long lWidth, long lHeight)

{

   HRESULT    hr = S_OK;

   IUnknown   *pUnk;

   ILMVResize *pResize = NULL;

   // Get the resize filter

   hr = IltmmConvert_GetSubObject(pConvert, ltmmConvert_Object_SelVideoProcessor, &pUnk);

   if(SUCCEEDED(hr))

   {

      hr = IUnknown_QueryInterface(pUnk, &IID_ILMVResize, (void**) &pResize);

      if( pResize )

      {

         // Set the resize filter settings

         ILMVResize_put_Enabled(pResize, VARIANT_TRUE);

         ILMVResize_put_AutoSize(pResize, VARIANT_FALSE);

         ILMVResize_put_EnableQuickResize(pResize, VARIANT_FALSE);

         ILMVResize_put_AspectRatio(pResize, VARIANT_TRUE);

         ILMVResize_put_Width(pResize, lWidth);

         ILMVResize_put_Height(pResize, lHeight);

         ILMVResize_put_Flags(pResize, RESIZE_RESAMPLE);

         ILMVResize_Release(pResize);

      }

      IUnknown_Release(pUnk);

   }

}

C++ Source

void ConfigureResizeFilter(IltmmConvert *pConvert, long lWidth, long lHeight)

{

   HRESULT    hr = S_OK;

   IUnknown   *pUnk;

   ILMVResize *pResize = NULL;

   // Get the resize filter

   hr = pConvert->GetSubObject(ltmmConvert_Object_SelVideoProcessor, &pUnk);

   if(SUCCEEDED(hr))

   {

      hr = pUnk->QueryInterface(IID_ILMVResize, (void**) &pResize);

      if( pResize )

      {

         // Set the resize filter settings

         pResize->put_Enabled(VARIANT_TRUE);

         pResize->put_AutoSize(VARIANT_FALSE);

         pResize->put_EnableQuickResize(VARIANT_FALSE);

         pResize->put_AspectRatio(VARIANT_TRUE);

         pResize->put_Width(lWidth);

         pResize->put_Height(lHeight);

         pResize->put_Flags(RESIZE_RESAMPLE);

         pResize->Release();

      }

      pUnk->Release();

   }

}

 

5.

Declare the following variables:

IltmmConvert *pConvert = NULL;

IUnknown *pDvdWriter = NULL;

ILTDvdWriter *pIDvdWriter = NULL;

BSTR szFileName = NULL;

IltmmCompressors *pCompressors;

long lIndex = 0;

BOOL bRet = FALSE;

int nTitle, nChapter;

char szTitle[256];

BSTR strTitle, strChapter, strBackground;

DVDTITLES aTitles[2] = {{"C:\\Movie1.mpg", "C:\\Movie2.mpg"},

                     {"C:\\Movie3.mpg", "C:\\Movie4.mpg"}};

 

6.

Create the converter object.

C Source

CoCreateInstance(&CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmConvert, (void**) &pConvert);

 

C++ Source

CoCreateInstance(CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER, IID_IltmmConvert, (void**) &pConvert);

 

7.

Set the target format The format to be used for the converted file. This includes the file format, any special settings used by that format, and which audio and/or video codec A COmpressor combined with a DECompressor, or encoder and a decoder, which allows you to both compress and decompress that same data. is to be used for the conversion, and any special settings used by the codecs. to be a DVD.

C Source

IltmmConvert_put_TargetFormat(pConvert, ltmmConvert_TargetFormat_DVD);

C++ Source

pConvert->put_TargetFormat(ltmmConvert_TargetFormat_DVD);

 

8.

Set the DVD compatible video encoder Also known as 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.. to be the LEAD MPEG2 encoder (2.0).

C Source

IltmmConvert_get_VideoCompressors(pConvert, &pCompressors);

   IltmmCompressors_Find(pCompressors, L"@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\\LEAD MPEG2 Encoder (2.0)", &lIndex);

   IltmmCompressors_put_Selection(pCompressors, lIndex);

   IltmmCompressors_Release(pCompressors);

C++ Source

pConvert->get_VideoCompressors(&pCompressors);

   pCompressors->Find(L"@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\\LEAD MPEG2 Encoder (2.0)", &lIndex);

   pCompressors->put_Selection(lIndex);

   pCompressors->Release();

 

9.

Set the DVD compatible audio encoder to be the LEAD MPEG audio encoder (2.0).

C Source

IltmmConvert_get_AudioCompressors(pConvert, &pCompressors);

   IltmmCompressors_Find(pCompressors, L"@device:sw:{33D9A761-90C8-11D0-BD43-00A0C911CE86}\\LEAD MPEG Audio Encoder (2.0)", &lIndex);

   IltmmCompressors_put_Selection(pCompressors, lIndex);

   IltmmCompressors_Release(pCompressors);

C++ Source

pConvert->get_AudioCompressors(&pCompressors);

   pCompressors->Find(L"@device:sw:{33D9A761-90C8-11D0-BD43-00A0C911CE86}\\LEAD MPEG Audio Encoder (2.0)", &lIndex);

   pCompressors->put_Selection(lIndex);

   pCompressors->Release();

 

10.

Add the resize filter as a process. Use the resize filter to change the video size so the dimensions are standard DVD dimensions.

 

(In order for a DVD to be accepted by DVD players, the video size must be acceptable. It is recommended to use the DVD full resolution (720X480 for NTSC) because not all DVD navigators can handle the conversion from a DVD to a DVD image that is less than 720X480.)

C Source

if (AddResizeFilter(pConvert) != TRUE)

   {

      MessageBox(NULL, "Can't insert the resize filter", "Error", MB_OK);

      IltmmConvert_Release(pConvert);

      return;

   }

C++ Source

C++ Source

if (AddResizeFilter(pConvert) != TRUE)

   {

      ::MessageBox(NULL, "Can't insert the resize filter", "Error", MB_OK);

      pConvert->Release();

      return;

   }

 

11.

Configure the resize settings. Set the dimensions to be 720 x 480.

ConfigureResizeFilter(pConvert, 720, 480);

 

12.

Set the DVD target folder.

C Source

IltmmConvert_put_TargetFile(pConvert, T2OLE("C:\\DVDImage"));

C++ Source

pConvert->put_TargetFile(T2OLE("C:\\DVDImage"));

 

13.

Retrieve the DVD Writer interface.

C Source

IltmmConvert_GetSubObject(pConvert, ltmmConvert_Object_Sink, &pDvdWriter);

IUnknown_QueryInterface(pDvdWriter, &IID_ILTDvdWriter, (void**)&pIDvdWriter);

C++ Source

pConvert->GetSubObject(ltmmConvert_Object_Sink, &pDvdWriter);

pDvdWriter->QueryInterface(IID_ILTDvdWriter, (void**)&pIDvdWriter);

 

14.

Set the DVD temporary folder.

C Source

ILTDvdWriter_put_TempPath(pIDvdWriter, T2OLE("C:\\Temp"));

C++ Source

pIDvdWriter->put_TempPath(T2OLE("C:\\Temp"));

 

15.

Remove all of the menu titles.

C Source

ILTDvdWriter_RemoveAllMenuTitles(pIDvdWriter);

C++ Source

pIDvdWriter->RemoveAllMenuTitles();

 

16.

Set the MenulessTitlePlay option to TRUE. This will concatenate all the titles for playback so each 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. will be played automatically, in sequential order.

C Source

ILTDvdWriter_put_MenulessTitlePlay(pIDvdWriter, VARIANT_TRUE);

C++ Source

pIDvdWriter->put_MenulessTitlePlay(VARIANT_TRUE);

 

17.

Create multiple titles, each title containing multiple chapters.

 

Note: In order to add a new title to the DVD image being created, overwriting must be disabled before writing the image.

C Source

for (nTitle = 0; nTitle < 2; nTitle++)

   {

      // Open a title

      ILTDvdWriter_put_TitleBreak(pIDvdWriter, VARIANT_FALSE);

 

      // Add a menu for the current title

      wsprintf(szTitle, "Title %d", nTitle+1);

      strTitle = SysAllocString(T2OLE(szTitle));

      ILTDvdWriter_AddMenuTitle(pIDvdWriter, strTitle, -1);

      SysFreeString(strTitle);

      

      // Create two chapters in the title

      for (nChapter = 0; nChapter < 2; nChapter++)

      {

// Put the source movie file

         strChapter = SysAllocString(T2OLE(aTitles[nTitle].pszChapters[nChapter]));

         IltmmConvert_put_SourceFile(pConvert, strChapter);

         // Start writing the chapter

         IltmmConvert_StartConvert(pConvert);

         // Wait for the conversion to finish. You can use a window

         // to receive notifications

         WaitForCompletion(pConvert);         

         // Free the chapter's name

         SysFreeString(strChapter);

      }

      // Close the title

      ILTDvdWriter_put_TitleBreak(pIDvdWriter, VARIANT_TRUE);

      // Disable Overwrite so the title will be appended to the

      // existing DVD image

      ILTDvdWriter_put_Overwrite(pIDvdWriter, VARIANT_FALSE);

   }

C++ Source

for (nTitle = 0; nTitle < 2; nTitle++)

   {

      // Open a title

      pIDvdWriter->put_TitleBreak(VARIANT_FALSE);

      // Add a menu for the current title

      wsprintf(szTitle, "Title%d", nTitle+1);

      strTitle = SysAllocString(T2OLE(szTitle));

      pIDvdWriter->AddMenuTitle(strTitle, -1);

      SysFreeString(strTitle);

      

      // Create two chapters in the title

      for (nChapter = 0; nChapter < 2; nChapter++)

      {

         // Put the source movie file

         strChapter = SysAllocString(T2OLE(aTitles[nTitle].pszChapters[nChapter]));

         pConvert->put_SourceFile(strChapter);

         // Start writing the chapter

         pConvert->StartConvert();

         

         // Wait for the conversion to finish. You can use a window

         // to receive notifications

         WaitForCompletion(pConvert);         

         // Free the chapter's name

         SysFreeString(strChapter);

      }

      // Close the title

      pIDvdWriter->put_TitleBreak(VARIANT_TRUE);

      // Disable Overwrite so the title will be appended to the

      // existing DVD image

      pIDvdWriter->put_Overwrite(VARIANT_FALSE);

   }

 

18.

Write the menu title.

 

Menu writing should be the last step in a DVD image authoring process. Writing the menu first will cause an error and if a new title is written after the menu has been written, the menu will be destroyed.

C Source

// Change the writing state to indicate that the next conversion is

// a menu

ILTDvdWriter_put_TitleMenu(pIDvdWriter, VARIANT_TRUE);

// Set the loop behavior for the menu background.

ILTDvdWriter_put_MenuLoop(pIDvdWriter, TRUE);

// Set the source background movie (or you could use a still image // file as the background menu)

strBackground = SysAllocString(T2OLE("c:\\background.mpg"));

IltmmConvert_put_SourceFile(pConvert, strBackground);

SysFreeString(strBackground);

// Start writing the menu

IltmmConvert_StartConvert(pConvert);

// Wait for the conversion to finish

WaitForCompletion(pConvert);

C++ Source

// Change the writing state to indicate that the next conversion is

// a menu

pIDvdWriter->put_TitleMenu(VARIANT_TRUE);

// Set the loop behavior for the menu background.

pIDvdWriter->put_MenuLoop(TRUE);

// Set the source background movie (or you could use a still image // file as the background menu)

strBackground = SysAllocString(T2OLE("c:\\background.mpg"));

pConvert->put_SourceFile(strBackground);

SysFreeString(strBackground);

// Start writing the menu

pConvert->StartConvert();

// Wait for the conversion to finish

WaitForCompletion(pConvert);

 

19.

Finish the menu conversion by calling ILTDvdWriter::put_TitleMenu, passing VARIANT_FALSE for the newVal parameter to close the "menu write" mode. This merges the menu subtitle information with the background video and modifies the DVD image.

C Source

ILTDvdWriter_put_TitleMenu(pIDvdWriter, VARIANT_FALSE);

ILTDvdWriter_put_Overwrite(pIDvdWriter, VARIANT_TRUE);

 

C++ Source

pIDvdWriter->put_TitleMenu(VARIANT_FALSE);

pIDvdWriter->put_Overwrite(VARIANT_TRUE);

 

 

20.

Free the convert and DVD writer objects.

C Source

ILTDvdWriter_Release(pIDvdWriter);

IltmmConvert_Release(pConvert);

 

C++ Source

pIDvdWriter->Release();

pConvert->Release();