The ltmmCapture object allows the user to capture data from video and audio hardware devices.
To begin simple capturing you will first need to create an instance of the ltmmCapture class. This is accomplished using the Win32 CoCreateInstance function as follows:
IltmmCapture* pCapture;
CoCreateInstance(&CLSID_ltmmCapture, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmCapture, (void**)&pCapture);
IltmmCapture* pCapture;
CoCreateInstance(CLSID_ltmmCapture, NULL, CLSCTX_INPROC_SERVER, IID_IltmmCapture, (void**)&pCapture);
Define a window to send capture status messages:
HWND hwndNotify;
#define WM_CAPTURENOTIFY (WM_USER + 1000)
IltmmCapture_SetNotifyWindow(pCapture, (long)hwndNotify, WM_CAPTURENOTIFY);
HWND hwndNotify;
#define WM_CAPTURENOTIFY (WM_USER + 1000)
pCapture->SetNotifyWindow((long)hwndNotify, WM_CAPTURENOTIFY);
Note
A capture can be accomplished without the use of the notification window, but the user would be required to poll the objects state to determine when the capture has finished.
Define a frame window for the video preview:
HWND hwndFrame;
IltmmCapture_put_VideoWindowFrame(pCapture, (long)hwndFrame);
HWND hwndFrame;
pCapture->put_VideoWindowFrame((long)hwndFrame);
Note
The notification window and the video frame window can be the same.
Define audio and video devices to be used as the capture source. The ltmmCapture object contains audio and video device collection objects. These objects allow the user to enumerate the registered audio and video devices and to select which devices to capture.
Enumerate the registered video devices:
IltmmDevices* pDevices;
long lCount;
long i;
// get an interface into video devices collection
IltmmCapture_get_VideoDevices(pCapture, &pDevices);
// get the total number of registered devices
IltmmDevices_get_Count(pDevices, &lCount);
// enumerate all of the devices
for (i = 0; i < lCount; i++)
{
IltmmDevice* pDevice;
BSTR bstrName;
BSTR bstrFriendlyName;
VARIANT_BOOL fSelected;
// get an interface for the ith device
IltmmDevices_Item(pDevices, i, &pDevice);
// get the devices "full name" (used to uniquely identify the device)
IltmmDevice_get_Name(pDevice, &bstrName);
// get the devices "friendly name" (used for readable display)
IltmmDevice_get_FriendlyName(pDevice, &bstrFriendlyName);
// query whether the device is currently selected
IltmmDevice_get_Selected(pDevice, &fSelected);
//
// add additional code here
//
// free strings
SysFreeString(bstrName);
SysFreeString(bstrFriendlyName);
// release the device interface
IUnknown_Release(pDevice);
}
// release the devices interface
IUnknown_Release(pDevices);
IltmmDevices* pDevices;
long lCount;
long i;
// get an interface into video devices collection
pCapture->get_VideoDevices(&pDevices);
// get the total number of registered devices
pDevices->get_Count(&lCount);
// enumerate all of the devices
for (i = 0; i < lCount; i++)
{
IltmmDevice* pDevice;
BSTR bstrName;
BSTR bstrFriendlyName;
VARIANT_BOOL fSelected;
// get an interface for the ith device
pDevices->Item(i, &pDevice);
// get the devices "full name" (used to uniquely identify the device)
pDevice->get_Name(&bstrName);
// get the devices "friendly name" (used for readable display)
pDevice->get_FriendlyName(&bstrFriendlyName);
// query whether the device is currently selected
pDevice->get_Selected(&fSelected);
//
// add additional code here
//
// free strings
SysFreeString(bstrName);
SysFreeString(bstrFriendlyName);
// release the device interface
pDevice->Release();
}
// release the devices interface
pDevices->Release();
The registered audio devices can be enumerated with the following code:
IltmmDevices* pDevices;
long lCount;
long i;
// get an interface into audio devices collection
IltmmCapture_get_AudioDevices(pCapture, &pDevices);
// get the total number of registered devices
IltmmDevices_get_Count(pDevices, &lCount);
// enumerate all of the devices
for (i = 0; i < lCount; i++)
{
IltmmDevice* pDevice;
BSTR bstrName;
BSTR bstrFriendlyName;
VARIANT_BOOL fSelected;
// get an interface for the ith device
IltmmDevices_Item(pDevices, i, &pDevice);
// get the devices "full name" (used to uniquely identify the device)
IltmmDevice_get_Name(pDevice, &bstrName);
// get the devices "friendly name" (used for readable display)
IltmmDevice_get_Selected(pDevice, bstrFriendlyName);
// query whether the device is currently selected
IltmmDevice_get_Selected(pDevice, &fSelected);
//
// add additional code here
//
// free strings
SysFreeString(bstrName);
SysFreeString(bstrFriendlyName);
// release the device interface
IUnknown_Release(pDevice);
}
// release the devices interface
IUnknown_Release(pDevices);
IltmmDevices* pDevices;
long lCount;
long i;
// get an interface into audio devices collection
pCapture->get_AudioDevices(&pDevices);
// get the total number of registered devices
pDevices->get_Count(&lCount);
// enumerate all of the devices
for (i = 0; i < lCount; i++)
{
IltmmDevice* pDevice;
BSTR bstrName;
BSTR bstrFriendlyName;
VARIANT_BOOL fSelected;
// get an interface for the ith device
pDevices->Item(i, &pDevice);
// get the devices "full name" (used to uniquely identify the device)
pDevice->get_Name(&bstrName);
// get the devices "friendly name" (used for readable display)
pDevice->get_Name(&bstrFriendlyName);
// query whether the device is currently selected
pDevice->get_Selected(&fSelected);
//
// add additional code here
//
// free strings
SysFreeString(bstrName);
SysFreeString(bstrFriendlyName);
// release the device interface
pDevice->Release();
}
// release the devices interface
pDevices->Release();
Note
The only difference between enumerating video and audio devices is the initial collection object retrieved.
An individual device can be selected for capture by calling the device collections put_Selection function:
IltmmDevices* pDevices;
// get an interface into video devices collection
IltmmCapture_get_AudioDevices(pCapture, &pDevices);
// select device
IltmmDevices_put_Selection(10);
// release collection
IUnknown_Release(pDevices);
IltmmDevices* pDevices;
// get an interface into video devices collection
pCapture->get_AudioDevices(&pDevices);
// select device
pDevices->put_Selection(10);
// release collection
pDevices->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 capture object
IltmmCapture_put_TargetFile(pCapture, 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 capture object
pCapture->put_TargetFile(bstr);
// free the string
SysFreeString(bstr);
You can now, optionally, set capture and preview properties using the ShowDialog function:
// capture properties
IltmmCapture_ShowDialog(pCapture, ltmmCapture_Dlg_Capture, (long)hwndMain);
// preview properties
IltmmCapture_ShowDialog(pCapture, ltmmCapture_Dlg_Preview, (long)hwndMain);
// capture properties
pCapture->ShowDialog(ltmmCapture_Dlg_Capture, (long)hwndMain);
// preview properties
pCapture->ShowDialog(ltmmCapture_Dlg_Preview, (long)hwndMain);
You are now ready to start the capturing data. This is accomplished with the following code:
IltmmCapture_StartCapture (pCapture, ltmmCapture_Mode_VideoOrAudio);
pCapture->StartCapture (ltmmCapture_Mode_VideoOrAudio);
The notification window will be sent messages indicating the current capture progress:
LRESULT CaptureWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (msg == WM_CAPTURENOTIFY)
{
switch (wParam)
{
case ltmmCapture_Notify_Started:
// capture started
break;
case ltmmCapture_Notify_Complete:
// capture successfully completed
break;
case ltmmCapture_Notify_ErrorAbort:
// a capture error occurred
// the error code is contained in lParam
break;
case ltmmCapture_Notify_Progress:
// the current capture time (milliseconds) is in lParam
break;
}
}
return 0;
}
To stop capturing the data, call the StopCapture function as follows:
IltmmCapture_StopCapture (pCapture);
pCapture->StopCapture ();
You can, optionally, capture a manual sequence of frames. To start a manual frame capture sequence call StartCapture as follows:
IltmmCapture_StartCapture (pCapture, ltmmCapture_Mode_ManualFrames);
pCapture->StartCapture (ltmmCapture_Mode_ManualFrames);
To trigger the capture of each frame call the CaptureFrame as follows:
IltmmCapture_CaptureFrame (pCapture);
pCapture->CaptureFrame ();
If you would like the capture object to automatically trigger the single frame captures, then you would start the capture as follows:
// set the trigger time to 5 seconds
IltmmCapture_put_FrameDelay(pCapture, 5.0);
// start capturing frame sequence
IltmmCapture_StartCapture(pCapture, ltmmCapture_Mode_AutoFrames);
// set the trigger time to 5 seconds
pCapture->put_FrameDelay(5.0);
// start capturing frame sequence
pCapture->StartCapture(ltmmCapture_Mode_AutoFrames);
Another variation captures a single still image as a device independent bitmap or an automation picture object. A DIB can be captured as follows:
HGLOBAL hDIB;
IltmmCapture_CaptureDIB(pCapture, (long*)&hDIB);
HGLOBAL hDIB;
pCapture->CaptureDIB((long*)&hDIB);
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