Creating DVD Images for C++

The following code demonstrates how to create DVD images using LEAD Multimedia toolkit.

// include the LEAD Multimedia TOOLKIT header 
#include "ltmm.h" 
#include "ILTDVDWriter2.h"  
 
void WaitForCompletion(IltmmConvert *pConvert); 
 
int main() 
{ 
   IltmmConvert *pConvert = NULL; 
   IUnknown *pDvdWriter = NULL; 
   ILTDvdWriter *pIDvdWriter = NULL; 
   BSTR szFileName = NULL; 
   IltmmCompressors *pCompressors; 
   long lIndex = 0; 
 
   CoInitialize(NULL); 
 
   // create a converter object 
   HRESULT hr = CoCreateInstance(CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER, IID_IltmmConvert, (void**) &pConvert); 
 
   // setup the converter:  
   hr = pConvert->put_TargetFormat(ltmmConvert_TargetFormat_DVD); 
   hr = pConvert->get_VideoCompressors(&pCompressors); 
   hr = pCompressors->Find(L"@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\\LEAD MPEG2 Encoder (2.0)", &lIndex); 
   hr = pCompressors->put_Selection(lIndex); 
   pCompressors->Release(); 
   hr = pConvert->get_AudioCompressors(&pCompressors); 
   hr = pCompressors->Find(L"@device:sw:{33D9A761-90C8-11D0-BD43-00A0C911CE86}\\LEAD MPEG Audio Encoder (2.0)", &lIndex); 
   hr = pCompressors->put_Selection(lIndex); 
   pCompressors->Release(); 
 
   // 1- Create a DVD image with 1 title that contains 1 chapter:  
  
   szFileName = ::SysAllocString(MAKE_MEDIA_PATH("DaDa_CMP.avi"));  
   // Source video 
   hr = pConvert->put_SourceFile(szFileName); 
   SysFreeString(szFileName); 
 
   szFileName = ::SysAllocString(MAKE_MEDIA_PATH(""));  
   // Destination image folder 
   hr = pConvert->put_TargetFile(szFileName); 
   SysFreeString(szFileName); 
 
   hr = pConvert->StartConvert(); 
 
   // Wait for the conversion to finish. You can use a window to receive notifications 
   WaitForCompletion(pConvert); 
 
   // Done 
   pConvert->ResetTarget(); 
   pConvert->ResetSource(); 
 
 
   // 2- Create a DVD image with 1 title that contains 2 chapters:  
  
   szFileName = ::SysAllocString(MAKE_MEDIA_PATH("DaDa_CMP.avi"));  
   // Source video 
   hr = pConvert->put_SourceFile(szFileName); 
   SysFreeString(szFileName); 
 
   szFileName = ::SysAllocString(MAKE_MEDIA_PATH(""));  
   // Destination image folder 
   hr = pConvert->put_TargetFile(szFileName); 
   SysFreeString(szFileName); 
 
   // Retrieve the DVD Writer interface  
   hr = pConvert->GetSubObject(ltmmConvert_Object_Sink, &pDvdWriter); 
   pDvdWriter->QueryInterface(IID_ILTDvdWriter, (void**)&pIDvdWriter); 
 
   // Set the DVD temporary files folder  
   szFileName = ::SysAllocString(MAKE_MEDIA_PATH(""));  
   // Destination image folder 
   pIDvdWriter->put_TempPath(szFileName); 
   SysFreeString(szFileName); 
 
   // Set the TitleBreak property to FALSE.  
   // This will prevent the title from being written immediately after the conversion 
   pIDvdWriter->put_TitleBreak(VARIANT_FALSE);  
  
   // write the first chapter 
   hr = pConvert->StartConvert(); 
   // 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. 
   hr = pConvert->StartConvert(); 
   WaitForCompletion(pConvert); 
 
   // Close the title 
   pIDvdWriter->put_TitleBreak(VARIANT_TRUE); 
 
   // Done 
   pDvdWriter->Release(); 
   pDvdWriter = NULL; 
   pIDvdWriter->Release(); 
   pIDvdWriter = NULL; 
   pConvert->ResetTarget(); 
   pConvert->ResetSource(); 
 
   // 3- Create a DVD image with 2 titles, each contains 2 chapters:  
  
   szFileName = ::SysAllocString(MAKE_MEDIA_PATH("DaDa_CMP.avi"));  
   // Source video 
   hr = pConvert->put_SourceFile(szFileName); 
   SysFreeString(szFileName); 
 
   szFileName = ::SysAllocString(MAKE_MEDIA_PATH(""));  
   // Destination image folder 
   hr = pConvert->put_TargetFile(szFileName); 
   SysFreeString(szFileName); 
 
   // Retrieve the DVD Writer interface  
   hr = pConvert->GetSubObject(ltmmConvert_Object_Sink, &pDvdWriter); 
   pDvdWriter->QueryInterface(IID_ILTDvdWriter, (void**)&pIDvdWriter); 
 
   // Set the TitleBreak property to FALSE.  
   // This will prevent the title from being written immediately after the conversion 
   pIDvdWriter->put_TitleBreak(VARIANT_FALSE);  
  
   // Write the first chapter in the first title 
   hr = pConvert->StartConvert(); 
   // 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. 
   hr = pConvert->StartConvert(); 
   WaitForCompletion(pConvert); 
 
   // Prepare for the second title 
   // Set the TitleBreak property to TRUE, so the current title can be flushed 
   pIDvdWriter->put_TitleBreak(VARIANT_TRUE); 
 
   // Set the TitleBreak property to FALSE.  
   // This will prevent the title from being written immediately after the conversion 
   pIDvdWriter->put_TitleBreak(VARIANT_FALSE); 
 
   // Disable Overwrite so the title will be appended to an existing dvd image 
   pIDvdWriter->put_Overwrite(VARIANT_FALSE); 
 
   // Write the first chapter in the second title 
   hr = pConvert->StartConvert(); 
 
   // Wait for the conversion to finish. You can use a window to receive notifications 
   WaitForCompletion(pConvert); 
 
   // Write the second chapter in the second title 
   hr = pConvert->StartConvert(); 
   WaitForCompletion(pConvert); 
 
   // Close the second title 
   pIDvdWriter->put_TitleBreak(VARIANT_TRUE); 
 
   // restore the overwrite property 
   pIDvdWriter->put_Overwrite(VARIANT_TRUE); 
 
   // Done  
   pDvdWriter->Release(); 
   pDvdWriter = NULL; 
   pIDvdWriter->Release(); 
   pIDvdWriter = NULL; 
   pConvert->ResetTarget(); 
   pConvert->ResetSource(); 
   pConvert->Release(); 
 
   CoUninitialize(); 
 
   return 0; 
} 
 
void WaitForCompletion(IltmmConvert *pConvert) 
{ 
   long lState = ltmmConvert_State_Running; 
   MSG msg; 
 
   pConvert->get_State(&lState); 
 
   while(lState != ltmmConvert_State_Stopped) 
   {  
      if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
      { 
         TranslateMessage(&msg); 
         DispatchMessage(&msg); 
      } 
       
      pConvert->get_State(&lState); 
   } 
} 

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

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