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 the video devices to be used as the capture source. The ltmmCapture object contains video device collection objects. The first video device can be selected for capture by calling the device collection's put_Selection function:
IltmmDevices* pDevices;// get an interface into video devices collectionIltmmCapture_get_VideoDevices(pCapture, &pDevices);// select the first video deviceIltmmDevices_put_Selection (pDevices, 0);// release collectionIUnknown_Release(pDevices);
IltmmDevices* pDevices;// get an interface into video devices collectionpCapture->get_VideoDevices(&pDevices);// select devicepDevices->put_Selection(0);// release collectionpDevices->Release();
Define the target or output file, as demonstrated with the following code:
BSTR bstr;// create a string containing the target file pathbstr = SysAllocString(L"c:\\target.mpg");// assign the target file path to the capture objectIltmmCapture_put_TargetFile (pCapture, bstr);// free the stringSysFreeString(bstr);
BSTR bstr;// create a string containing the target file pathbstr = SysAllocString(L"c:\\target.mpg");// assign the target file path to the capture objectpCapture->put_TargetFile (bstr);// free the stringSysFreeString(bstr);
Select the Video and Audio compressors, as demonstrated with the following code:
long index;IltmmCompressors* pCompressors;// select the MS MPEG-4 Video CodecIltmmCapture_get_VideoCompressors(pCapture, &pCompressors);bstr = SysAllocString(L"@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\\Microsoft MPEG-4 Video Codec V2");IltmmCompressors_Find(pCompressors, bstr, &index);SysFreeString(bstr);if(index >= 0)IltmmCompressors_put_Selection(pCompressors, index);IUnknown_Release(pCompressors);// select the MP3 audio video compressorIltmmCapture_get_AudioCompressors(pCapture, &pCompressors);bstr = SysAllocString(L"@device:cm:{33D9A761-90C8-11D0-BD43-00A0C911CE86}\\85MPEG Layer-3");IltmmCompressors_Find(pCompressors, bstr, &index);SysFreeString(bstr);if(index >= 0)IltmmCompressors_put_Selection(pCompressors, index);IUnknown_Release(pCompressors);
IltmmCompressors* pCompressors;long index;// select the MS MPEG-4 Video CodecpCapture->get_VideoCompressors (&pCompressors);bstr = SysAllocString(L"@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\\Microsoft MPEG-4 Video Codec V2");pCompressors->Find (bstr, &index);SysFreeString(bstr);if(index < 0){// compressor isn't registeredpCompressors->Release ();return E_FAIL;}pCompressors->put_Selection (index);pCompressors->Release();// select the MP3 audio video compressorpCapture->get_AudioCompressors (&pCompressors);bstr = SysAllocString(L"@device:cm:{33D9A761-90C8-11D0-BD43-00A0C911CE86}\\85MPEG Layer-3");pCompressors->Find (bstr, &index);SysFreeString(bstr);if(index < 0){// compressor isn't registeredpCompressors->Release ();return E_FAIL;}pCompressors->put_Selection (index);pCompressors->Release();
To view the graph in DirectShow GraphEdit
IltmmCapture_EditGraph(pCapture); pCapture->EditGraph(); Set the MPEG multiplexer. This example will use an AVI multiplexer because it is available on all computers. You should use a real MPEG multiplexer, as demonstrated with the following code:
IltmmTargetFormats* pTargetFormats;IltmmTargetFormat* pTargetFormat;IltmmCapture_get_TargetFormats(pCapture, &pTargetFormats);// retrieve collection itemIltmmTargetFormats_Item(pTargetFormats, 0, &pTargetFormat);// assign the required Mux// this case: AVIbstr = SysAllocString(L"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\\{E2510970-F137-11CE-8B67-00AA00A3F1A6}");IltmmTargetFormat_put_Mux(pTargetFormat, bstr);SysFreeString(bstr);// assign the optional SinkSubType// this case: MEDIASUBTYPE_Avibstr = SysAllocString(L"{E436EB88-524F-11CE-9F53-0020AF0BA770}");IltmmTargetFormat_put_SinkSubType(pTargetFormat, bstr);SysFreeString(bstr);// assign an optional Sink// this case: defaultbstr = SysAllocString(L"");IltmmTargetFormat_put_Sink(pTargetFormat, bstr);SysFreeString(bstr);IUnknown_Release(pTargetFormat);
IltmmTargetFormats* pTargetFormats;IltmmTargetFormat* pTargetFormat;pCapture->get_TargetFormats(&pTargetFormats);// retrieve collection itempTargetFormats->Item(0, &pTargetFormat);// assign the required Mux// this case: AVIbstr = SysAllocString(L"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\\{E2510970-F137-11CE-8B67-00AA00A3F1A6}");pTargetFormat->put_Mux(bstr);SysFreeString(bstr);// assign the optional SinkSubType// this case: MEDIASUBTYPE_Avibstr = SysAllocString(L"{E436EB88-524F-11CE-9F53-0020AF0BA770}");pTargetFormat->put_SinkSubType(bstr);SysFreeString(bstr);// assign an optional Sink// this case: defaultbstr = SysAllocString(L"");pTargetFormat->put_Sink(bstr);SysFreeString(bstr);pTargetFormat->Release();
Set a frame rate supported by MPEG. Look at the documentation for your MPEG multiplexer to see which frame rates it supports. Common frame rates are: 23.976, 24, 25, 29.97, 30fps, as demonstrated with the following code:
// set rate to 30 fpsIltmmCapture_put_UseFrameRate(pCapture, VARIANT_TRUE);IltmmCapture_put_FrameRate(pCapture, 30.0);// you should check with their particular compressor which frame rates are supported.
// set rate to 30 fpspCapture->put_UseFrameRate(VARIANT_TRUE);pCapture->put_FrameRate(30.0);// you should check with their particular compressor which frame rates are supported.
Now start to capture the data and save it to the target file by calling the following function:
// start runningIltmmCapture_StartCapture(pCapture, ltmmCapture_Mode_VideoAndAudio);
// start runningpCapture->StartCapture(ltmmCapture_Mode_VideoAndAudio);
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
