The following code demonstrates how to recompress an AVI file to a DV device:
#define MAKE_MEDIA_PATH(pFileName) (TEXT("C:\\Program Files (x86)\\LEAD Technologies\\LEADTOOLS 19\\Media\\")TEXT(pFileName))// define helper macros for using interfaces under C#ifndef COBJMACROS#define COBJMACROS#endif// include the LEAD Multimedia TOOLKIT header#include "ltmm.h"#include "resource.h"#include <tchar.h>#include <stdio.h>#include <assert.h>IltmmConvert* g_pConvert; // convert object's interface pointer// user defined message id used for conversion events#define WM_CONVERTNOTIFY (WM_USER + 1000)//// ConvertDlgProc// starts the conversion process and provides status feedback//// controls:// IDC_CONVERTSTATUS - static control used for status messages// IDC_CONVERTPROGRESS - static control used for conversion progress// IDC_USERABORT - button control used to abort the conversion or exit the dialogBOOL CALLBACK ConvertDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){TCHAR sz[256];BSTR bstr1 = NULL;BSTR bstr2 = NULL;HRESULT hr;long state;long type;long streams;IltmmVCRControl* pVCR;switch (msg){case WM_INITDIALOG:// assign the notification windowIltmmConvert_SetNotifyWindow (g_pConvert, (long) hwnd, WM_CONVERTNOTIFY);// set the abort button textSetDlgItemText(hwnd, IDC_USERABORT, _T("Abort"));// uncomment the following line to view the the graph in DirectShow GraphEdit// IltmmConvert_EditGraph(g_pConvert);IltmmConvert_get_UnrenderedStreams(g_pConvert, &streams);if(streams != 0)MessageBox(hwnd, _T("Not all the streams could be rendered."), _T("Convert"), MB_ICONEXCLAMATION | MB_OK);IltmmConvert_get_TargetVCRControl(g_pConvert, &pVCR);hr = IltmmVCRControl_Record(pVCR);IUnknown_Release(pVCR);if(SUCCEEDED(hr))Sleep(2000);// start the conversionhr = IltmmConvert_StartConvert (g_pConvert);if(FAILED(hr)){_stprintf(sz, _T("conversion error 0x%.8X"), lParam);SetDlgItemText(hwnd, IDC_CONVERTSTATUS, sz);UpdateWindow(GetDlgItem(hwnd, IDC_CONVERTSTATUS));SetDlgItemText(hwnd, IDC_USERABORT, _T("Exit"));MessageBeep(0);// stop, if VCRIltmmConvert_get_TargetVCRControl(g_pConvert, &pVCR);IltmmVCRControl_Stop (pVCR);IUnknown_Release(pVCR);}return TRUE;break;case WM_DESTROY:// reset the notification windowIltmmConvert_SetNotifyWindow (g_pConvert, (long) NULL, 0);#ifdef _DEBUG{long state, err, pc;double start, end, dur;TCHAR sz[1024];// get the current stateIltmmConvert_get_State (g_pConvert, &state);// get the current stateIltmmConvert_get_ConvertError(g_pConvert, &err);// get the amount convertedIltmmConvert_get_PercentComplete(g_pConvert, &pc);// get the startIltmmConvert_get_SelectionStart (g_pConvert, &start);// get the endIltmmConvert_get_SelectionEnd(g_pConvert, &end);// get the durationIltmmConvert_get_Duration(g_pConvert, &dur);_stprintf(sz, _T("state = %d, error = 0x%.8X, complete = %d complete"), lParam);SetDlgItemText(hwnd, IDC_CONVERTPROGRESS, sz);UpdateWindow(GetDlgItem(hwnd, IDC_CONVERTPROGRESS));break;}return TRUE;break;}return FALSE;}//// RecompressFileToDVDevice// recompresses file to DV device//// pszSource = source file path//HRESULT RecompressFileToDVDevice(LPCTSTR pszSource, HINSTANCE hInstance){HRESULT hr;BSTR bstr;#ifndef _UNICODEWCHAR wsz[MAX_PATH];#endifIltmmTargetDevices* pDevices;IltmmCompressors* pCompressors;// set source file#ifdef _UNICODEbstr = SysAllocString(pszSource);#elseswprintf(wsz, L"%hs", pszSource);bstr = SysAllocString(wsz);#endifhr = IltmmConvert_put_SourceFile(g_pConvert, bstr);SysFreeString(bstr);if(FAILED(hr))return hr;// set target devicehr = IltmmConvert_put_TargetFormat(g_pConvert, ltmmConvert_TargetFormat_dvsd);if(FAILED(hr))return hr;IltmmConvert_get_AudioCompressors(g_pConvert, &pCompressors);hr = IltmmCompressors_put_Selection(pCompressors, -1);IUnknown_Release(pCompressors);if(FAILED(hr))return hr;IltmmConvert_get_VideoCompressors(g_pConvert,&pCompressors);hr = IltmmCompressors_put_Selection(pCompressors, -1);IUnknown_Release(pCompressors);if(FAILED(hr))return hr;IltmmConvert_get_TargetDevices(g_pConvert, &pDevices);hr = IltmmTargetDevices_put_Selection(pDevices, 0);IUnknown_Release(pDevices);if(FAILED(hr))return hr;// do conversionhr = (HRESULT) DialogBox(hInstance, (LPCTSTR)IDD_CONVERTDLG, NULL, ConvertDlgProc);return hr;}void RecompressingAVIFileToDVDevice_Example ( HINSTANCE hInstance /*application instance handle*/ ){HRESULT hr;// initialize COM libraryhr = CoInitialize(NULL);if(FAILED(hr))goto error;// create the convert objecthr = CoCreateInstance(&CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmConvert, (void**) &g_pConvert);if(FAILED(hr))goto error;hr = RecompressFileToDVDevice(MAKE_MEDIA_PATH("source.avi"), hInstance);if(FAILED(hr))goto error;error:// cleanupif(g_pConvert)IUnknown_Release(g_pConvert);CoUninitialize();}
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
