The ltmmConvert object allows the user to recompress multimedia files or convert from one multimedia format to another.
To begin simple conversion, first create an instance of the ltmmConvert class. Do so using the Win32 CoCreateInstance function as follows:
IltmmConvert* pConvert;CoCreateInstance(&CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmConvert, (void**) &pConvert);
IltmmConvert* pConvert;CoCreateInstance(CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER, IID_IltmmConvert, (void**) &pConvert);
The function creates an instance of ltmmConvert and returns an IltmmConvert interface pointer. It is through the IltmmConvert interface that the conversion process is controlled.
Define a window to send conversion status messages:
HWND hwndNotify;#define WM_CONVERTNOTIFY (WM_USER + 1000)IltmmConvert_SetNotifyWindow (pConvert, (long) hwndNotify, WM_CONVERTNOTIFY);
HWND hwndNotify;#define WM_CONVERTNOTIFY (WM_USER + 1000)pConvert->SetNotifyWindow ((long) hwndNotify, WM_CONVERTNOTIFY);
The above code instructs the convert object to send WM_CONVERTNOTIFY messages to the window procedure for hwndNotify. The wParam parameter of the window message will contain the notification code.
Note
A conversion can be accomplished without the use of the notification window, but the user would be required to poll the object's state to determine when the conversion has finished.
Define the source or input file as demonstrated with the following code:
BSTR bstr;// create a string containing the source file pathbstr = SysAllocString(L"c:\\source.avi");// assign the source file path to the convert objectIltmmConvert_put_SourceFile (pConvert, bstr);// free the stringSysFreeString(bstr);
BSTR bstr;// create a string containing the source file pathbstr = SysAllocString(L"c:\\source.avi");// assign the source file path to the convert objectpConvert->put_SourceFile (bstr);// free the stringSysFreeString(bstr);
The code above allocates a string containing an AVI file path and assigns the path to the convert object with a call to put_SourceFile.
Define audio and video compressors to be used for the conversion process. If you do not want to change the current compression, then you should just skip this step. The ltmmConvert object contains audio and video compressor collection objects. These objects allow the user to enumerate the registered audio and video compressors and to select the compressors to use during the conversion process.
The following code demonstrates how to enumerate the registered audio filters:
IltmmCompressors* pCompressors;long lCount;long i;// get an interface into audio compressors collectionIltmmConvert_get_AudioCompressors (pConvert, &pCompressors);// get the total number of registered compressorsIltmmCompressors_get_Count (pCompressors, &lCount);// enumerate all of the compressorsfor(i = 0; i < lCount; i++){IltmmCompressor* pCompressor;BSTR bstrName;BSTR bstrFriendlyName;VARIANT_BOOL fSelected;// get an interface for the ith compressorIltmmCompressors_Item (pCompressors, i, &pCompressor);// get the compressors "full name" (used to uniquely identify the compressor)IltmmCompressor_get_Name (pCompressor, &bstrName);// get the compressors "friendly name" (used for readable display)IltmmCompressor_get_FriendlyName (pCompressor, &bstrFriendlyName);// query whether the compressor is currently selectedIltmmCompressor_get_Selected (pCompressor, &fSelected);//// add additional code here//// free stringsSysFreeString(bstrName);SysFreeString(bstrFriendlyName);// release the compressor interfaceIUnknown_Release(pCompressor);}// release the compressors interfaceIUnknown_Release(pCompressors);
IltmmCompressors* pCompressors;long lCount;long i;// get an interface into audio compressors collectionpConvert->get_AudioCompressors (&pCompressors);// get the total number of registered compressorspCompressors->get_Count (&lCount);// enumerate all of the compressorsfor(i = 0; i < lCount; i++){IltmmCompressor* pCompressor;BSTR bstrName;BSTR bstrFriendlyName;VARIANT_BOOL fSelected;// get an interface for the ith compressorpCompressors->Item (i, &pCompressor);// get the compressors "full name" (used to uniquely identify the compressor)pCompressor->get_Name (&bstrName);// get the compressors "friendly name" (used for readable display)pCompressor->get_FriendlyName (&bstrFriendlyName);// query whether the compressor is currently selectedpCompressor->get_Selected (&fSelected);//// add additional code here//// free stringsSysFreeString(bstrName);SysFreeString(bstrFriendlyName);// release the compressor interfacepCompressor->Release();}// release the compressors interfacepCompressors->Release();
The registered video compressors can be enumerated with the following code:
IltmmCompressors* pCompressors;long lCount;long i;// get an interface into video compressors collectionIltmmConvert_get_VideoCompressors (pConvert, &pCompressors);// get the total number of registered compressorsIltmmCompressors_get_Count (pCompressors, &lCount);// enumerate all of the compressorsfor(i = 0; i < lCount; i++){IltmmCompressor* pCompressor;BSTR bstrName;BSTR bstrFriendlyName;VARIANT_BOOL fSelected;// get an interface for the ith compressorIltmmCompressors_Item (pCompressors, i, &pCompressor);// get the compressors "full name" (used to uniquely identify the compressor)IltmmCompressor_get_Name (pCompressor, &bstrName);// get the compressors "friendly name" (used for readable display)IltmmCompressor_get_FriendlyName (pCompressor, &bstrFriendlyName);// query whether the compressor is currently selectedIltmmCompressor_get_Selected (pCompressor, &fSelected);//// add additional code here//// free stringsSysFreeString(bstrName);SysFreeString(bstrFriendlyName);// release the compressor interfaceIUnknown_Release(pCompressor);}// release the compressors interfaceIUnknown_Release(pCompressors);
IltmmCompressors* pCompressors;long lCount;long i;// get an interface into video compressors collectionpConvert->get_VideoCompressors (&pCompressors);// get the total number of registered compressorspCompressors->get_Count (&lCount);// enumerate all of the compressorsfor(i = 0; i < lCount; i++){IltmmCompressor* pCompressor;BSTR bstrName;BSTR bstrFriendlyName;VARIANT_BOOL fSelected;// get an interface for the ith compressorpCompressors->Item (i, &pCompressor);// get the compressors "full name" (used to uniquely identify the compressor)pCompressor->get_Name (&bstrName);// get the compressors "friendly name" (used for readable display)pCompressor->get_FriendlyName (&bstrFriendlyName);// query whether the compressor is currently selectedpCompressor->get_Selected (&fSelected);//// add additional code here//// free stringsSysFreeString(bstrName);SysFreeString(bstrFriendlyName);// release the compressor interfacepCompressor->Release();}// release the compressors interfacepCompressors->Release();
Note
The only difference between enumerating audio and video compressors is in the initial collection object retrieved.
An individual compressor can be selected for the conversion process by calling the compressor collection's put_Selection function:
IltmmCompressors* pCompressors;// get an interface into audio compressors collectionIltmmConvert_get_AudioCompressors(pConvert, &pCompressors);// select compressorIltmmCompressors_put_Selection (pCompressors, 10);// release collectionIUnknown_Release(pCompressors);
IltmmCompressors* pCompressors;// get an interface into audio compressors collectionpConvert->get_AudioCompressors (&pCompressors);// select compressorpCompressors->put_Selection (10);// release collectionpCompressors->Release();
Define the target or output file. As demonstrated with the following code:
BSTR bstr;// create a string containing the target file pathbstr = SysAllocString(L"c:\\target.avi");// assign the target file path to the convert objectIltmmConvert_put_TargetFile(pConvert, bstr);// free the stringSysFreeString(bstr);
BSTR bstr;// create a string containing the target file pathbstr = SysAllocString(L"c:\\target.avi");// assign the target file path to the convert objectpConvert->put_TargetFile (bstr);// free the stringSysFreeString(bstr);
Optionally, you may decide that you would like to generate an WMV, WAV, or MP3 output file. For information about Windows Media Support, click here. You can change the target format with the following code:
// set the output format to WAVE audioIltmmConvert_put_TargetFormat (pConvert, ltmmConvert_TargetFormat_WAVE);
// set the output format to WAVE audiopConvert->put_TargetFormat (ltmmConvert_TargetFormat_WAVE);
You can now (optionally) set compressor and format properties using the ShowDialog function:
HWND hwndMain;// audio compression propertiesIltmmConvert_ShowDialog (pConvert, ltmmConvert_Dlg_AudioCompressor, (long) hwndMain);// video compression propertiesIltmmConvert_ShowDialog(pConvert, ltmmConvert_Dlg_VideoCompressor, (long) hwndMain);// target format propertiesIltmmConvert_ShowDialog(pConvert, ltmmConvert_Dlg_TargetFormat, (long) hwndMain);
HWND hwndMain;// audio compression propertiespConvert->ShowDialog (ltmmConvert_Dlg_AudioCompressor, (long) hwndMain);// video compression propertiespConvert->ShowDialog(ltmmConvert_Dlg_VideoCompressor, (long) hwndMain);// target format propertiespConvert->ShowDialog (ltmmConvert_Dlg_TargetFormat, (long) hwndMain);
You are now ready to start the conversion. This is accomplished with the following code:
IltmmConvert_StartConvert (pConvert); pConvert->StartConvert (); The notification window will be sent messages indicating the current conversion progress:
LRESULT ConvertWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){if(msg == WM_CONVERTNOTIFY){switch(wParam){case ltmmConvert_Notify_Started:// conversion startedbreak;case ltmmConvert_Notify_Complete:// conversion successfully completedbreak;case ltmmConvert_Notify_ErrorAbort:// a conversion error occurred// the error code is contained in lParambreak;case ltmmConvert_Notify_UserAbort:// the StopConvert function was calledbreak;case ltmmConvert_Notify_Progress:// the current completion percentage is in lParambreak;}}return 0;}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
