#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;// mpeg2 compressorstatic TCHAR SZ_MPEG2_Compressor[] = "@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\\LEAD MPEG2 Encoder (3.0)";// get the video devices collectionhr = m_capture->get_VideoDevices(&devices);if(FAILED(hr))return hr;// select the capture devicehr = devices->put_Selection(0); // Use a different video device if you want// release the video devices collection objectdevices->Release();if(FAILED(hr))return hr;// get the video compressors collectionhr = m_capture->get_VideoCompressors(&compressors);if(FAILED(hr))return hr;USES_CONVERSION;// find mpeg2 compressorhr = compressors->Find(T2OLE(SZ_MPEG2_Compressor), &lIndex);if(FAILED(hr) || lIndex == -1){// release the compressors collection objectcompressors->Release();return S_FALSE;}// set the video compressor (only if the capture device is not already capturing compressed video)compressors->put_Selection(lIndex);// release the compressors collection objectcompressors->Release();// set the target output fileBSTR bstr = SysAllocString(L"c:\\CaptureKLV.avi");m_capture->put_TargetFile(bstr);SysFreeString(bstr);// just 10 seconds of capture timem_capture->put_UseTimeLimit (VARIANT_TRUE);m_capture->put_TimeLimit(10);// get the target formats collectionhr = m_capture->get_TargetFormats(&pformats);if(FAILED(hr))return hr;// get the MPEG2Transport target format objecthr = pformats->Item(ltmmCapture_TargetFormat_MPEG2_TRANSPORT, &pformat);if(FAILED(hr)){// release the formats collection objectpformats->Release();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 = pformat->put_UseFilterCache(VARIANT_TRUE);if(FAILED(hr)){// release the format and collection objectspformat->Release();pformats->Release();return hr;}// select MPEG2Transport target formathr = m_capture->put_TargetFormat (ltmmCapture_TargetFormat_MPEG2_TRANSPORT);if(FAILED(hr))return hr;// get the multiplexer object for this formathr = pformat->GetCacheObject(ltmmTargetFormat_Object_Mux, &pUnknown);if(FAILED(hr)){// release the format and collection objectspformat->Release();pformats->Release();return hr;}// release the format and collection objectspformat->Release();pformats->Release();hr = pUnknown->QueryInterface(IID_ILMMpg2MxT, (void **)&pMpgMux);pUnknown->Release();if(FAILED(hr))return hr;if(pMpgMux){pMpgMux->put_PrivateDataPID(0x70);pMpgMux->put_PrivateDataFormatID(0x41564c4b);pMpgMux->put_EnablePrivateData(VARIANT_TRUE);}// release the multiplexer objectpMpgMux->Release();// start capturehr = m_capture->StartCapture(ltmmCapture_Mode_Video);if(FAILED(hr))return hr;hr = WriteKLVData(pMpgMux);return hr;}HRESULT WriteKLVData (ILMMpg2MxT* pMpgMux ){HRESULT hr = S_OK;time_t basetime;time(&basetime);unsigned __int64 timestamp = ((unsigned __int64) basetime * 1000000);// get the mux builderILMKlvBuilder* builder;hr = pMpgMux->get_KlvBuilder(&builder);if(FAILED(hr))goto abort;// clear out any existing databuilder->Clear();// write the UDS timestamphr = builder->InsertUInt64(-1L, CComBSTR(L"06 0E 2B 34 01 01 01 03 07 02 01 01 01 05 00 00"), timestamp);if(FAILED(hr)){builder->Release();goto abort;}// get KLV dataVARIANT v;VariantInit(&v);hr = builder->GetData(&v);if(FAILED(hr)){builder->Release();goto abort;}// write one KLV data at the beginninghr = pMpgMux->WritePrivateData(Mpg2MxT_WriteFlag_PTSValid | Mpg2MxT_WriteFlag_PTSInSeconds, 1.0, v, -1);VariantClear(&v);if(FAILED(hr)){builder->Release();goto abort;}builder->Release();abort:// close the streampMpgMux->ClosePrivateData();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
