How to Use the DVD Writer to Write a DVD Image

Use the DVD Writer to write a 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 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); 
   } 
} 

  1. 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" 
   } 
}; 

  1. 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); 

  1. Set the target format to be a DVD.

C Source

IltmmConvert_put_TargetFormat(pConvert, ltmmConvert_TargetFormat_DVD); 

C++ Source

pConvert->put_TargetFormat(ltmmConvert_TargetFormat_DVD); 

  1. Set the DVD compatible video encoder 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(); 

  1. 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

if (AddResizeFilter(pConvert) != TRUE) 
{ 
   ::MessageBox(NULL, "Can't insert the resize filter", "Error", MB_OK); 
   pConvert->Release(); 
   return; 
} 

  1. 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); 

  1. Set the DVD temporary folder.

C Source

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

C++ Source

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

  1. Remove all of the menu titles.

C Source

ILTDvdWriter_RemoveAllMenuTitles(pIDvdWriter); 

C++ Source

pIDvdWriter->RemoveAllMenuTitles(); 

  1. Set the MenulessTitlePlay option to TRUE. This will concatenate all the titles for playback so each title will be played automatically, in sequential order.

C Source

ILTDvdWriter_put_MenulessTitlePlay(pIDvdWriter, VARIANT_TRUE); 

C++ Source

pIDvdWriter->put_MenulessTitlePlay(VARIANT_TRUE); 

  1. 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); 
} 

  1. 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); 

  1. 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); 

  1. Free the Convert and DVD writer objects.

C Source

ILTDvdWriter_Release(pIDvdWriter); 
IltmmConvert_Release(pConvert); 

C++ Source

pIDvdWriter->Release(); 
pConvert->Release(); 

Help Version 21.0.2021.7.19
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Multimedia C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.