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 collectionIltmmCapture_get_VideoDevices(pCapture, &pDevices);// get the total number of registered devicesIltmmDevices_get_Count(pDevices, &lCount);// enumerate all of the devicesfor (i = 0; i < lCount; i++){IltmmDevice* pDevice;BSTR bstrName;BSTR bstrFriendlyName;VARIANT_BOOL fSelected;// get an interface for the ith deviceIltmmDevices_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 selectedIltmmDevice_get_Selected(pDevice, &fSelected);//// add additional code here//// free stringsSysFreeString(bstrName);SysFreeString(bstrFriendlyName);// release the device interfaceIUnknown_Release(pDevice);}// release the devices interfaceIUnknown_Release(pDevices);
C++ Source
IltmmDevices* pDevices;long lCount;long i;// get an interface into video devices collectionpCapture->get_VideoDevices(&pDevices);// get the total number of registered devicespDevices->get_Count(&lCount);// enumerate all of the devicesfor (i = 0; i < lCount; i++){IltmmDevice* pDevice;BSTR bstrName;BSTR bstrFriendlyName;VARIANT_BOOL fSelected;// get an interface for the ith devicepDevices->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 selectedpDevice->get_Selected(&fSelected);//// add additional code here//// free stringsSysFreeString(bstrName);SysFreeString(bstrFriendlyName);// release the device interfacepDevice->Release();}// release the devices interfacepDevices->Release();
C Source
IltmmDevices* pDevices;long lCount;long i;// get an interface into audio devices collectionIltmmCapture_get_AudioDevices(pCapture, &pDevices);// get the total number of registered devicesIltmmDevices_get_Count(pDevices, &lCount);// enumerate all of the devicesfor (i = 0; i < lCount; i++){IltmmDevice* pDevice;BSTR bstrName;BSTR bstrFriendlyName;VARIANT_BOOL fSelected;// get an interface for the ith deviceIltmmDevices_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 selectedIltmmDevice_get_Selected(pDevice, &fSelected);//// add additional code here//// free stringsSysFreeString(bstrName);SysFreeString(bstrFriendlyName);// release the device interfaceIUnknown_Release(pDevice);}// release the devices interfaceIUnknown_Release(pDevices);
C++ Source
IltmmDevices* pDevices;long lCount;long i;// get an interface into audio devices collectionpCapture->get_AudioDevices(&pDevices);// get the total number of registered devicespDevices->get_Count(&lCount);// enumerate all of the devicesfor (i = 0; i < lCount; i++){IltmmDevice* pDevice;BSTR bstrName;BSTR bstrFriendlyName;VARIANT_BOOL fSelected;// get an interface for the ith devicepDevices->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 selectedpDevice->get_Selected(&fSelected);//// add additional code here//// free stringsSysFreeString(bstrName);SysFreeString(bstrFriendlyName);// release the device interfacepDevice->Release();}// release the devices interfacepDevices->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 collectionIltmmCapture_get_AudioDevices(pCapture, &pDevices);// select deviceIltmmDevices_put_Selection(10);// release collectionIUnknown_Release(pDevices);
C++ Source
IltmmDevices* pDevices;// get an interface into video devices collectionpCapture->get_AudioDevices(&pDevices);// select devicepDevices->put_Selection(10);// release collectionpDevices->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 pathbstr = SysAllocString(L"c:\\target.avi");// assign the target file path to the capture objectIltmmCapture_put_TargetFile(pCapture, bstr);// free the stringSysFreeString(bstr);
C++ Source
BSTR bstr;// create a string containing the target file pathbstr = SysAllocString(L"c:\\target.avi");// assign the target file path to the capture objectpCapture->put_TargetFile(bstr);// free the stringSysFreeString(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 propertiesIltmmCapture_ShowDialog(pCapture, ltmmCapture_Dlg_Capture, (long)hwndMain);// preview propertiesIltmmCapture_ShowDialog(pCapture, ltmmCapture_Dlg_Preview, (long)hwndMain);
C++ Source
// capture propertiespCapture->ShowDialog(ltmmCapture_Dlg_Capture, (long)hwndMain);// preview propertiespCapture->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 startedbreak;case ltmmCapture_Notify_Complete:// capture successfully completedbreak;case ltmmCapture_Notify_ErrorAbort:// a capture error occurred// the error code is contained in lParambreak;case ltmmCapture_Notify_Progress:// the current capture time (milliseconds) is in lParambreak;}}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 secondsIltmmCapture_put_FrameDelay(pCapture, 5.0);// start capturing frame sequenceIltmmCapture_StartCapture(pCapture, ltmmCapture_Mode_AutoFrames);
C++ Source
// set the trigger time to 5 secondspCapture->put_FrameDelay(5.0);// start capturing frame sequencepCapture->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
