#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_TCHAR *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 = pMediaType->put_Type(bstr);SysFreeString(bstr);if(FAILED(hr))goto error;// set subtype to MEDIASUBTYPE_RGB24bstr = SysAllocString(L"{e436eb7d-524f-11ce-9f53-0020af0ba770}");hr = pMediaType->put_Subtype(bstr);SysFreeString(bstr);if(FAILED(hr))goto error;// set the accepted media typehr = pSampleTarget->SetAcceptedMediaType(pMediaType);if(FAILED(hr))goto error;// release the media type, since we don't need it anymorepMediaType->Release();pMediaType = NULL;// set the convert input file namebstr = SysAllocString(pszAviFile);hr = pConvert->put_SourceFile(bstr);SysFreeString(bstr);if(FAILED(hr))goto error;// set the convert object targethr = pConvert->put_TargetObject(pSampleTarget);if(FAILED(hr))goto error;// start the conversionhr = pConvert->StartConvert();if(FAILED(hr))goto error;// get the connected media typehr = pSampleTarget->GetConnectedMediaType(&pMediaType);if(FAILED(hr))goto error;// get the VIDEOINFOHEADERhr = pMediaType->get_Format(&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 = pSampleTarget->GetSample(1000, &pMediaSample);if(FAILED(hr) || !pMediaSample)break;// access the image bitshr = pMediaSample->get_Buffer(&varBuffer);if(FAILED(hr)){pMediaSample->Release();pConvert->StopConvert();goto converterror;}hr = SafeArrayAccessData(V_ARRAY(&varBuffer), &pBuffer);if(FAILED(hr)){VariantClear(&varBuffer);pMediaSample->Release();pConvert->StopConvert();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_LEAD1JTIF, 0, 25, SAVEFILE_MULTIPAGE, NULL, NULL, NULL);// release the sampleSafeArrayUnaccessData(V_ARRAY(&varBuffer));VariantClear(&varBuffer);pMediaSample->Release();if(nRet != SUCCESS){// an error occured - abort the processhr = E_FAIL;pConvert->StopConvert();goto converterror;}}// stophr = pConvert->StopConvert();if(FAILED(hr))goto converterror;// cleanup and exithr = S_OK; converterror:SafeArrayUnaccessData(V_ARRAY(&varFormat));VariantClear(&varFormat); error:if(pConvert)pConvert->Release();if(pSampleTarget)pSampleTarget->Release();if(pMediaType)pMediaType->Release();CoUninitialize();return hr;}int main(int argc, char* argv[]){AviToTIFF((OLECHAR*)MAKE_MEDIA_PATH("count.avi"), MAKE_MEDIA_PATH("multi.tif"), 100);return 0;}
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
