Use the DVD Writer to write a DVD image to the hard disk. To write to a DVD, perform the following steps:
Declare the following structure that will be filled with the chapter names, as follows:
typedef struct _tagDVDTITLES{char pszChapters[2][256];} DVDTITLES;
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 stateIltmmConvert_get_State(pConvert, &lState);// Dispatch messages during conversionwhile( 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 statepConvert->get_State(&lState);// Dispatch messages during conversionwhile( lState != ltmmConvert_State_Stopped ){if( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ){TranslateMessage(&msg);DispatchMessage(&msg);}pConvert->get_State(&lState);}}
C Source
BOOL AddResizeFilter(IltmmConvert *pConvert){IltmmProcessors* pProcessors;IltmmProcessors* pSelProcessors;long lIndex = 0;BSTR bstr;IltmmProcessor* pProc;HRESULT hr;// Get the video processor's pointerhr = IltmmConvert_get_VideoProcessors(pConvert, &pProcessors);if (FAILED(hr)){MessageBox(NULL, "Error working with video processors", "Error", MB_OK);return FALSE;}// Get the selected video processorhr = 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 filterbstr = 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 filterIltmmProcessors_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 pointerhr = pConvert->get_VideoProcessors(&pProcessors);if (FAILED(hr)){MessageBox(NULL, "Error working with video processors", "Error", MB_OK);return FALSE;}// Get the selected video processorhr = 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 filterbstr = 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 filterpProcessors->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 filterhr = IltmmConvert_GetSubObject(pConvert, ltmmConvert_Object_SelVideoProcessor, &pUnk);if (SUCCEEDED(hr)){hr = IUnknown_QueryInterface(pUnk, &IID_ILMVResize, (void**)&pResize);if (pResize){// Set the resize filter settingsILMVResize_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 filterhr = pConvert->GetSubObject(ltmmConvert_Object_SelVideoProcessor, &pUnk);if (SUCCEEDED(hr)){hr = pUnk->QueryInterface(IID_ILMVResize, (void**)&pResize);if (pResize){// Set the resize filter settingspResize->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"}};
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); C Source
IltmmConvert_put_TargetFormat(pConvert, ltmmConvert_TargetFormat_DVD); C++ Source
pConvert->put_TargetFormat(ltmmConvert_TargetFormat_DVD); 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();
(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;}
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);
C Source
ILTDvdWriter_put_TempPath(pIDvdWriter, T2OLE("C:\\Temp")); C++ Source
pIDvdWriter->put_TempPath(T2OLE("C:\\Temp")); C Source
ILTDvdWriter_RemoveAllMenuTitles(pIDvdWriter); C++ Source
pIDvdWriter->RemoveAllMenuTitles(); C Source
ILTDvdWriter_put_MenulessTitlePlay(pIDvdWriter, VARIANT_TRUE); C++ Source
pIDvdWriter->put_MenulessTitlePlay(VARIANT_TRUE); 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 titleILTDvdWriter_put_TitleBreak(pIDvdWriter, VARIANT_FALSE);// Add a menu for the current titlewsprintf(szTitle, "Title %d", nTitle + 1);strTitle = SysAllocString(T2OLE(szTitle));ILTDvdWriter_AddMenuTitle(pIDvdWriter, strTitle, -1);SysFreeString(strTitle);// Create two chapters in the titlefor (nChapter = 0; nChapter < 2; nChapter++){// Put the source movie filestrChapter = SysAllocString(T2OLE(aTitles[nTitle].pszChapters[nChapter]));IltmmConvert_put_SourceFile(pConvert, strChapter);// Start writing the chapterIltmmConvert_StartConvert(pConvert);// Wait for the conversion to finish. You can use a window// to receive notificationsWaitForCompletion(pConvert);// Free the chapter's nameSysFreeString(strChapter);}// Close the titleILTDvdWriter_put_TitleBreak(pIDvdWriter, VARIANT_TRUE);// Disable Overwrite so the title will be appended to the// existing DVD imageILTDvdWriter_put_Overwrite(pIDvdWriter, VARIANT_FALSE);}
C++ Source
for (nTitle = 0; nTitle < 2; nTitle++){// Open a titlepIDvdWriter->put_TitleBreak(VARIANT_FALSE);// Add a menu for the current titlewsprintf(szTitle, "Title%d", nTitle + 1);strTitle = SysAllocString(T2OLE(szTitle));pIDvdWriter->AddMenuTitle(strTitle, -1);SysFreeString(strTitle);// Create two chapters in the titlefor (nChapter = 0; nChapter < 2; nChapter++){// Put the source movie filestrChapter = SysAllocString(T2OLE(aTitles[nTitle].pszChapters[nChapter]));pConvert->put_SourceFile(strChapter);// Start writing the chapterpConvert->StartConvert();// Wait for the conversion to finish. You can use a window// to receive notificationsWaitForCompletion(pConvert);// Free the chapter's nameSysFreeString(strChapter);}// Close the titlepIDvdWriter->put_TitleBreak(VARIANT_TRUE);// Disable Overwrite so the title will be appended to the// existing DVD imagepIDvdWriter->put_Overwrite(VARIANT_FALSE);}
C Source
// Change the writing state to indicate that the next conversion is// a menuILTDvdWriter_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 menuIltmmConvert_StartConvert(pConvert);// Wait for the conversion to finishWaitForCompletion(pConvert);
C++ Source
// Change the writing state to indicate that the next conversion is// a menupIDvdWriter->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 menupConvert->StartConvert();// Wait for the conversion to finishWaitForCompletion(pConvert);
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);
C Source
ILTDvdWriter_Release(pIDvdWriter);IltmmConvert_Release(pConvert);
C++ Source
pIDvdWriter->Release();pConvert->Release();