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 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);
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:
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);
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();
The registered video compressors can be enumerated with the following code:
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);
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.
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 collection
IltmmConvert_get_AudioCompressors(pConvert, &pCompressors);
// select compressor
IltmmCompressors_put_Selection (pCompressors, 10);
// release collection
IUnknown_Release(pCompressors);
IltmmCompressors* pCompressors;
// get an interface into audio compressors collection
pConvert->get_AudioCompressors (&pCompressors);
// select compressor
pCompressors->put_Selection (10);
// release collection
pCompressors->Release();
Define the target or output file. As demonstrated with the following code:
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);
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);
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 audio
IltmmConvert_put_TargetFormat (pConvert, ltmmConvert_TargetFormat_WAVE);
// set the output format to WAVE audio
pConvert->put_TargetFormat (ltmmConvert_TargetFormat_WAVE);
You can now (optionally) set compressor and format properties using the ShowDialog function:
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);
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 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 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