#include "ltmm.h"#include "Filters/ILMMpg2MxT.h"#include <time.h>HRESULT UseFilterCache_Example (IltmmCapture* pCapture){HRESULT hr;IltmmDevices* devices = NULL;IltmmCompressors* compressors = NULL;IltmmTargetFormats* pformats = NULL;IltmmTargetFormat* pformat = NULL;IUnknown* pUnknown = NULL;ILMMpg2MxT* pMpgMux = NULL;long lIndex = 0;BSTR bstr;// mpeg2 compressorstatic TCHAR SZ_MPEG2_Compressor[] = "@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\\LEAD MPEG2 Encoder (3.0)";// get the video devices collectionhr = IltmmCapture_get_VideoDevices(pCapture, &devices);if(FAILED(hr))return hr;// select the capture devicehr = IltmmDevices_put_Selection(devices, 1); // Use a different video device if you want// release the video devices collection objectIltmmDevices_Release(devices);if(FAILED(hr))return hr;// get the video compressors collectionhr = IltmmCapture_get_VideoCompressors(pCapture, &compressors);if(FAILED(hr))return hr;// find mpeg2 compressorhr = IltmmCompressors_Find(compressors, T2OLE(SZ_MPEG2_Compressor), &lIndex);if(FAILED(hr) || lIndex == -1){// release the compressors collection objectIltmmCompressors_Release(compressors);return S_FALSE;}// set the video compressor (only if the capture device is not already capturing compressed video)IltmmCompressors_put_Selection(compressors, lIndex);// release the compressors collection objectIltmmCompressors_Release(compressors);// set the target output filebstr = SysAllocString(L"c:\\CaptureKLV.avi");IltmmCapture_put_TargetFile(pCapture, bstr);SysFreeString(bstr);// just 10 seconds of capture timeIltmmCapture_put_UseTimeLimit (pCapture, VARIANT_TRUE);IltmmCapture_put_TimeLimit(pCapture, 10);// get the target formats collectionhr = IltmmCapture_get_TargetFormats(pCapture, &pformats);if(FAILED(hr))return hr;// get the MPEG2Transport target format objecthr = IltmmTargetFormats_Item(pformats, ltmmCapture_TargetFormat_MPEG2_TRANSPORT, &pformat);if(FAILED(hr)){// release the formats collection objectIltmmTargetFormats_Release(pformats);return hr;}// IN a capture situation// in order to get the mux in a capture situation, set the UseFilterCache property for the target format to TRUE// This tells the toolkit to create a Mux object and keep it around when building or rebuilding graphs// enable filter cachehr = IltmmTargetFormat_put_UseFilterCache(pformat, VARIANT_TRUE);if(FAILED(hr)){// release the format and collection objectsIltmmTargetFormat_Release(pformat);IltmmTargetFormats_Release(pformats);return hr;}// select MPEG2Transport target formathr = IltmmCapture_put_TargetFormat (pCapture, ltmmCapture_TargetFormat_MPEG2_TRANSPORT);if(FAILED(hr))return hr;// get the multiplexer object for this formathr = IltmmTargetFormat_GetCacheObject(pformat, ltmmTargetFormat_Object_Mux, &pUnknown);if(FAILED(hr)){// release the format and collection objectsIltmmTargetFormat_Release(pformat);IltmmTargetFormats_Release(pformats);return hr;}// release the format and collection objectsIltmmTargetFormat_Release(pformat);IltmmTargetFormats_Release(pformats);hr = IUnknown_QueryInterface(pUnknown, &IID_ILMMpg2MxT, (void **)&pMpgMux);IUnknown_Release(pUnknown);if(FAILED(hr))return hr;if(pMpgMux){ILMMpg2MxT_put_PrivateDataPID(pMpgMux, 0x70);ILMMpg2MxT_put_PrivateDataFormatID(pMpgMux, 0x41564c4b);ILMMpg2MxT_put_EnablePrivateData(pMpgMux, VARIANT_TRUE);}// release the multiplexer objectILMMpg2MxT_Release(pMpgMux);// start capturehr = IltmmCapture_StartCapture(pCapture, ltmmCapture_Mode_Video);if(FAILED(hr))return hr;hr = WriteKLVData(pMpgMux);return hr;}HRESULT WriteKLVData (ILMMpg2MxT* pMpgMux ){HRESULT hr = S_OK;time_t basetime;unsigned __int64 timestamp ;ILMKlvBuilder* builder = NULL;VARIANT v;BSTR bstr;time(&basetime);timestamp = ((unsigned __int64) basetime * 1000000);// get the mux builderhr = ILMMpg2MxT_get_KlvBuilder(pMpgMux, &builder);if(FAILED(hr))goto abort;// clear out any existing dataILMKlvBuilder_Clear(builder);bstr = SysAllocString(L"06 0E 2B 34 01 01 01 03 07 02 01 01 01 05 00 00");// write the UDS timestamphr = ILMKlvBuilder_InsertUInt64(builder, -1L, bstr, timestamp);SysFreeString(bstr);if(FAILED(hr)){ILMKlvBuilder_Release(builder);goto abort;}// get KLV dataVariantInit(&v);hr = ILMKlvBuilder_GetData(builder, &v);if(FAILED(hr)){ILMKlvBuilder_Release(builder);goto abort;}// write one KLV data at the beginninghr = ILMMpg2MxT_WritePrivateData(pMpgMux, Mpg2MxT_WriteFlag_PTSValid | Mpg2MxT_WriteFlag_PTSInSeconds, 1.0, v, -1);VariantClear(&v);if(FAILED(hr)){ILMKlvBuilder_Release(builder);goto abort;}ILMKlvBuilder_Release(builder);abort:// close the streamILMMpg2MxT_ClosePrivateData(pMpgMux);return hr;}
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
