// define helper macros for using interfaces under C#ifndef COBJMACROS#define COBJMACROS#endif#include "stdafx.h"// include the LEAD Multimedia TOOLKIT header#include "ltmm.h"#include "l_bitmap.h"// include amvideo.h for VIDEOINFOHEADER, available in the Visual Studio 6.0 or the DirectX SDK#include <amvideo.h>// includes for string handling#include <tchar.h>#include <wchar.h>#include <string.h>#include <stdio.h>/////////////////////////////////////////////////////////////////// AviToTIFF// Creates a multipage TIFF file from an AVI file// pszAviFile - source file name// pszOutputFile - the name of the output TIF file// nMaxFrames - maximum number of pages (frames) to append to the file//HRESULT AviToTIFF(LPCWSTR pszAviFile, L_CHAR* pszOutputFile, int nMaxFrames){HRESULT hr;IltmmConvert* pConvert = NULL;IltmmSampleTarget* pSampleTarget = NULL;IltmmMediaTypeDisp* pMediaType = NULL;IltmmMediaSampleDisp* pMediaSample;VARIANT varFormat;VARIANT varBuffer;VIDEOINFOHEADER* pVIH;void* pBuffer;BSTR bstr;int n;BITMAPHANDLE Bitmap;L_INT nRet;// initialize COM libraryhr = CoInitialize(NULL);if(FAILED(hr))goto error;// create the convert objecthr = CoCreateInstance(&CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmConvert, (void**) &pConvert);if(FAILED(hr))goto error;// create the target objecthr = CoCreateInstance(&CLSID_ltmmSampleTarget, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmSampleTarget, (void**) &pSampleTarget);if(FAILED(hr))goto error;// create the media type objecthr = CoCreateInstance(&CLSID_ltmmMediaType, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmMediaTypeDisp, (void**) &pMediaType);if(FAILED(hr))goto error;// set type to MEDIATYPE_Videobstr = SysAllocString(L"{73646976-0000-0010-8000-00AA00389B71}");hr = IltmmMediaTypeDisp_put_Type (pMediaType, bstr);SysFreeString(bstr);if(FAILED(hr))goto error;// set subtype to MEDIASUBTYPE_RGB24bstr = SysAllocString(L"{e436eb7d-524f-11ce-9f53-0020af0ba770}");hr = IltmmMediaTypeDisp_put_Subtype (pMediaType, bstr);SysFreeString(bstr);if(FAILED(hr))goto error;// set the accepted media typehr = IltmmSampleTarget_SetAcceptedMediaType(pSampleTarget, pMediaType);if(FAILED(hr))goto error;// release the media type, since we don't need it anymoreIltmmMediaTypeDisp_Release(pMediaType);pMediaType = NULL;// set the convert input file namebstr = SysAllocString(pszAviFile);hr = IltmmConvert_put_SourceFile(pConvert, bstr);SysFreeString(bstr);if(FAILED(hr))goto error;// set the convert object targethr = IltmmConvert_put_TargetObject(pConvert, (IUnknown*)pSampleTarget);if(FAILED(hr))goto error;// start the conversionhr = IltmmConvert_StartConvert(pConvert);if(FAILED(hr))goto error;// get the connected media typehr = IltmmSampleTarget_GetConnectedMediaType(pSampleTarget, &pMediaType);if(FAILED(hr))goto error;// get the VIDEOINFOHEADERhr = IltmmMediaTypeDisp_get_Format(pMediaType, &varFormat);if(FAILED(hr))goto error;hr = SafeArrayAccessData(V_ARRAY(&varFormat), (void**) &pVIH);if(FAILED(hr)){VariantClear(&varFormat);goto error;}// set the shell bitmap handle to match the sample datanRet = L_CreateBitmap(&Bitmap,sizeof(BITMAPHANDLE),TYPE_USER,pVIH->bmiHeader.biWidth,abs(pVIH->bmiHeader.biHeight),pVIH->bmiHeader.biBitCount,ORDER_BGR,NULL,pVIH->bmiHeader.biHeight > 0 ? BOTTOM_LEFT : TOP_LEFT,NULL,pVIH->bmiHeader.biSizeImage);if(nRet != SUCCESS){hr = FAILURE;// make sure the bitmap handle is initialized so L_FreeBitmap does not crashL_InitBitmap(&Bitmap, sizeof(BITMAPHANDLE), 1, 1, 1);goto converterror;}for(n = 0; n < 1 * nMaxFrames; n++){// fetch a samplehr = IltmmSampleTarget_GetSample(pSampleTarget, 1000, &pMediaSample);if(FAILED(hr) || !pMediaSample)break;// access the image bitshr = IltmmMediaSampleDisp_get_Buffer(pMediaSample, &varBuffer);if(FAILED(hr)){IltmmMediaSampleDisp_Release(pMediaSample);IltmmConvert_StopConvert(pConvert);goto converterror;}hr = SafeArrayAccessData(V_ARRAY(&varBuffer), &pBuffer);if(FAILED(hr)){VariantClear(&varBuffer);IltmmMediaSampleDisp_Release(pMediaSample);IltmmConvert_StopConvert(pConvert);goto converterror;}// set the data pointer for the bitmap to be the samplenRet = L_SetBitmapDataPointer(&Bitmap, (L_UCHAR*)pBuffer, pVIH->bmiHeader.biSizeImage);if(nRet == SUCCESS)// append a JPEG-compressed page to the output filenRet = L_SaveFile(pszOutputFile, &Bitmap, FILE_TIF_JPEG_411, 0, 25, SAVEFILE_MULTIPAGE, NULL, NULL, NULL);// release the sampleSafeArrayUnaccessData(V_ARRAY(&varBuffer));VariantClear(&varBuffer);IltmmMediaSampleDisp_Release(pMediaSample);if(nRet != SUCCESS){// an error occured - abort the processhr = E_FAIL;IltmmConvert_StopConvert(pConvert);goto converterror;}}// stophr = IltmmConvert_StopConvert(pConvert);if(FAILED(hr))goto converterror;// cleanup and exithr = S_OK;converterror:SafeArrayUnaccessData(V_ARRAY(&varFormat));VariantClear(&varFormat);error:if(pConvert)IltmmConvert_Release(pConvert);if(pSampleTarget)IltmmSampleTarget_Release(pSampleTarget);if(pMediaType)IltmmMediaType_Release(pMediaType);CoUninitialize();return hr;}void SplittingAVIFileIntoMultipageTIFFFileUsingltmmSampleTarget_Example ( ){AviToTIFF((OLECHAR*)MAKE_MEDIA_PATH("count.avi"), MAKE_MEDIA_PATH("multi.tif"), 100);}
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
