Creating DVD Images for C

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

#define MAKE_MEDIA_PATH(pFileName) (TEXT("C:\\Program Files (x86)\\LEAD Technologies\\LEADTOOLS 19\\Media\\")TEXT(pFileName)) 
#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); 
   } 
} 
void CreateDVDImageExample ( ) 
{ 
   IltmmConvert *pConvert = NULL; 
   IUnknown *pDvdWriter = NULL; 
   ILTDvdWriter *pIDvdWriter = NULL; 
   BSTR szFileName = NULL; 
   IltmmCompressors *pCompressors; 
   long lIndex = 0; 
   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 (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 with 1 title that contains 1 chapter: 
   szFileName = SysAllocString(T2OLE(MAKE_MEDIA_PATH("DaDa_CMP.avi"))); // Source video 
   IltmmConvert_put_SourceFile(pConvert, szFileName); 
   SysFreeString(szFileName); 
   szFileName = SysAllocString(T2OLE(MAKE_MEDIA_PATH(""))); // 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(MAKE_MEDIA_PATH("DaDa_CMP.avi"))); // Source video 
   IltmmConvert_put_SourceFile(pConvert, szFileName); 
   SysFreeString(szFileName); 
   szFileName = SysAllocString(T2OLE(MAKE_MEDIA_PATH(""))); // 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 DVD temporary files folder 
   szFileName = SysAllocString(T2OLE(MAKE_MEDIA_PATH(""))); // 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(MAKE_MEDIA_PATH("DaDa_CMP.avi"))); // Source video 
   IltmmConvert_put_SourceFile(pConvert, szFileName); 
   SysFreeString(szFileName); 
   szFileName = SysAllocString(T2OLE(MAKE_MEDIA_PATH(""))); // 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(); 
} 
int main() 
{ 
   CreateDVDImageExample ( ) ; 
   return 0; 
} 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Multimedia C API Help