The ltmmConvert object allows the user to recompress multimedia files or convert from one multimedia format to another.
C Source
IltmmConvert* pConvert;
CoCreateInstance(&CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmConvert, (void**) &pConvert);
C++ Source
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.
C Source
HWND hwndNotify;
#define WM_CONVERTNOTIFY (WM_USER + 1000)
IltmmConvert_SetNotifyWindow (pConvert, (long) hwndNotify, WM_CONVERTNOTIFY);
C++ Source
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.
C Source
BSTR bstr;
// create a string containing the source file path
bstr = SysAllocString(L"c:\\source.avi");
// assign the source file path to the convert object
IltmmConvert_put_SourceFile (pConvert, bstr);
// free the string
SysFreeString(bstr);
C++ Source
BSTR bstr;
// create a string containing the source file path
bstr = SysAllocString(L"c:\\source.avi");
// assign the source file path to the convert object
pConvert->put_SourceFile (bstr);
// free the string
SysFreeString(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:
C Source
IltmmCompressors* pCompressors;
long lCount;
long i;
// get an interface into audio compressors collection
IltmmConvert_get_AudioCompressors (pConvert, &pCompressors);
// get the total number of registered compressors
IltmmCompressors_get_Count (pCompressors, &lCount);
// enumerate all of the compressors
for(i = 0; i < lCount; i++)
{
IltmmCompressor* pCompressor;
BSTR bstrName;
BSTR bstrFriendlyName;
VARIANT_BOOL fSelected;
// get an interface for the ith compressor
IltmmCompressors_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 selected
IltmmCompressor_get_Selected (pCompressor, &fSelected);
//
// add additional code here
//
// free strings
SysFreeString(bstrName);
SysFreeString(bstrFriendlyName);
// release the compressor interface
IUnknown_Release(pCompressor);
}
// release the compressors interface
IUnknown_Release(pCompressors);
C++ Source
IltmmCompressors* pCompressors;
long lCount;
long i;
// get an interface into audio compressors collection
pConvert->get_AudioCompressors (&pCompressors);
// get the total number of registered compressors
pCompressors->get_Count (&lCount);
// enumerate all of the compressors
for(i = 0; i < lCount; i++)
{
IltmmCompressor* pCompressor;
BSTR bstrName;
BSTR bstrFriendlyName;
VARIANT_BOOL fSelected;
// get an interface for the ith compressor
pCompressors->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 selected
pCompressor->get_Selected (&fSelected);
//
// add additional code here
//
// free strings
SysFreeString(bstrName);
SysFreeString(bstrFriendlyName);
// release the compressor interface
pCompressor->Release();
}
// release the compressors interface
pCompressors->Release();
C Source
IltmmCompressors* pCompressors;
long lCount;
long i;
// get an interface into video compressors collection
IltmmConvert_get_VideoCompressors (pConvert, &pCompressors);
// get the total number of registered compressors
IltmmCompressors_get_Count (pCompressors, &lCount);
// enumerate all of the compressors
for(i = 0; i < lCount; i++)
{
IltmmCompressor* pCompressor;
BSTR bstrName;
BSTR bstrFriendlyName;
VARIANT_BOOL fSelected;
// get an interface for the ith compressor
IltmmCompressors_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 selected
IltmmCompressor_get_Selected (pCompressor, &fSelected);
//
// add additional code here
//
// free strings
SysFreeString(bstrName);
SysFreeString(bstrFriendlyName);
// release the compressor interface
IUnknown_Release(pCompressor);
}
// release the compressors interface
IUnknown_Release(pCompressors);
C++ Source
IltmmCompressors* pCompressors;
long lCount;
long i;
// get an interface into video compressors collection
pConvert->get_VideoCompressors (&pCompressors);
// get the total number of registered compressors
pCompressors->get_Count (&lCount);
// enumerate all of the compressors
for(i = 0; i < lCount; i++)
{
IltmmCompressor* pCompressor;
BSTR bstrName;
BSTR bstrFriendlyName;
VARIANT_BOOL fSelected;
// get an interface for the ith compressor
pCompressors->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 selected
pCompressor->get_Selected (&fSelected);
//
// add additional code here
//
// free strings
SysFreeString(bstrName);
SysFreeString(bstrFriendlyName);
// release the compressor interface
pCompressor->Release();
}
// release the compressors interface
pCompressors->Release();
Note: The only difference between enumerating audio and video compressors is in the initial collection object retrieved.
C Source
IltmmCompressors* pCompressors;
// get an interface into audio compressors collection
IltmmConvert_get_AudioCompressors(pConvert, &pCompressors);
// select compressor
IltmmCompressors_put_Selection (pCompressors, 10);
// release collection
IUnknown_Release(pCompressors);
C++ Source
IltmmCompressors* pCompressors;
// get an interface into audio compressors collection
pConvert->get_AudioCompressors (&pCompressors);
// select compressor
pCompressors->put_Selection (10);
// release collection
pCompressors->Release();
The previous code selects the 10th compressor to be used for the conversion. You can also deselect any compressor by passing a 1 as the item's index.
C Source
BSTR bstr;
// create a string containing the target file path
bstr = SysAllocString(L"c:\\target.avi");
// assign the target file path to the convert object
IltmmConvert_put_TargetFile(pConvert, bstr);
// free the string
SysFreeString(bstr);
C++ Source
BSTR bstr;
// create a string containing the target file path
bstr = SysAllocString(L"c:\\target.avi");
// assign the target file path to the convert object
pConvert->put_TargetFile (bstr);
// free the string
SysFreeString(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_TargetFile.
C Source
// set the output format to WAVE audio
IltmmConvert_put_TargetFormat (pConvert, ltmmConvert_TargetFormat_WAVE);
C++ Source
// set the output format to WAVE audio
pConvert->put_TargetFormat (ltmmConvert_TargetFormat_WAVE);
Some formats require specific compressors. For example, ltmmConvert_TargetFormat_Asf requires that you not select any additional compressors, whereas ltmmConvert_TargetFormat_MPEG1Audio requires that you select a MPEG (MP3) audio compressor.
C Source
HWND hwndMain;
// audio compression properties
IltmmConvert_ShowDialog (pConvert, ltmmConvert_Dlg_AudioCompressor, (long) hwndMain);
// video compression properties
IltmmConvert_ShowDialog(pConvert, ltmmConvert_Dlg_VideoCompressor, (long) hwndMain);
// target format properties
IltmmConvert_ShowDialog(pConvert, ltmmConvert_Dlg_TargetFormat, (long) hwndMain);
C++ Source
HWND hwndMain;
// audio compression properties
pConvert->ShowDialog (ltmmConvert_Dlg_AudioCompressor, (long) hwndMain);
// video compression properties
pConvert->ShowDialog(ltmmConvert_Dlg_VideoCompressor, (long) hwndMain);
// target format properties
pConvert->ShowDialog (ltmmConvert_Dlg_TargetFormat, (long) hwndMain);
You can test for the existence of any dialog with the HasDialog function.
C Source
IltmmConvert_StartConvert (pConvert);
C++ Source
pConvert->StartConvert ();
LRESULT ConvertWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if(msg == WM_CONVERTNOTIFY)
{
switch(wParam)
{
case ltmmConvert_Notify_Started:
// conversion started
break;
case ltmmConvert_Notify_Complete:
// conversion successfully completed
break;
case ltmmConvert_Notify_ErrorAbort:
// a conversion error occurred
// the error code is contained in lParam
break;
case ltmmConvert_Notify_UserAbort:
// the StopConvert function was called
break;
case ltmmConvert_Notify_Progress:
// the current completion percentage is in lParam
break;
}
}
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