The ltmmCapture object allows the user to capture data from video and audio hardware devices.
C Source
IltmmCapture* pCapture;
CoCreateInstance(&CLSID_ltmmCapture, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmCapture, (void**)&pCapture);
C++ Source
IltmmCapture* pCapture;
CoCreateInstance(CLSID_ltmmCapture, NULL, CLSCTX_INPROC_SERVER, IID_IltmmCapture, (void**)&pCapture);
C Source
HWND hwndNotify;
#define WM_CAPTURENOTIFY (WM_USER + 1000)
IltmmCapture_SetNotifyWindow(pCapture, (long)hwndNotify, WM_CAPTURENOTIFY);
C++ Source
HWND hwndNotify;
#define WM_CAPTURENOTIFY (WM_USER + 1000)
pCapture->SetNotifyWindow((long)hwndNotify, WM_CAPTURENOTIFY);
The above code instructs the capture object to send WM_CAPTURENOTIFY messages to the window procedure for hwndNotify. The wParam parameter of the window message will contain the notification code.
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.
C Source
HWND hwndFrame;
IltmmCapture_put_VideoWindowFrame(pCapture, (long)hwndFrame);
C++ Source
HWND hwndFrame;
pCapture->put_VideoWindowFrame((long)hwndFrame);
The user is required to create the window that serves as the video frame. ltmmCapture will subclass this window, so there is no need to forward any messages to the ltmmCapture object. By default, ltmmCapture will automatically maximize the video within the frame window. The video will automatically resize when the frame window size changes.
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:
C Source
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);
C++ Source
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();
C Source
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);
C++ Source
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.
C Source
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);
C++ Source
IltmmDevices* pDevices;
// get an interface into video devices collection
pCapture->get_AudioDevices(&pDevices);
// select device
pDevices->put_Selection(10);
// release collection
pDevices->Release();
The previous code selects the 10th device to be captured. You can also deselect any device by passing a 1 as the item 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 capture object
IltmmCapture_put_TargetFile(pCapture, 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 capture object
pCapture->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 capture object with a call to put_TargetFile.
C Source
// capture properties
IltmmCapture_ShowDialog(pCapture, ltmmCapture_Dlg_Capture, (long)hwndMain);
// preview properties
IltmmCapture_ShowDialog(pCapture, ltmmCapture_Dlg_Preview, (long)hwndMain);
C++ Source
// capture properties
pCapture->ShowDialog(ltmmCapture_Dlg_Capture, (long)hwndMain);
// preview properties
pCapture->ShowDialog(ltmmCapture_Dlg_Preview, (long)hwndMain);
Use the HasDialog function to test for the existence of any dialog.
C Source
IltmmCapture_StartCapture (pCapture, ltmmCapture_Mode_VideoOrAudio);
C++ Source
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:
C Source
IltmmCapture_StopCapture (pCapture);
C++ Source
pCapture->StopCapture ();
C Source
IltmmCapture_StartCapture (pCapture, ltmmCapture_Mode_ManualFrames);
C++ Source
pCapture->StartCapture (ltmmCapture_Mode_ManualFrames);
C Source
IltmmCapture_CaptureFrame (pCapture);
C++ Source
pCapture->CaptureFrame ();
C Source
// set the trigger time to 5 seconds
IltmmCapture_put_FrameDelay(pCapture, 5.0);
// start capturing frame sequence
IltmmCapture_StartCapture(pCapture, ltmmCapture_Mode_AutoFrames);
C++ Source
// set the trigger time to 5 seconds
pCapture->put_FrameDelay(5.0);
// start capturing frame sequence
pCapture->StartCapture(ltmmCapture_Mode_AutoFrames);
The above code will schedule a frame to be captured every 5 seconds.
C Source
HGLOBAL hDIB;
IltmmCapture_CaptureDIB(pCapture, (long*)&hDIB);
C++ Source
HGLOBAL hDIB;
pCapture->CaptureDIB((long*)&hDIB);
The above code can be used without assigning the TargetFile. The user is responsible for freeing the returned bitmap.
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