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))// include the LEAD Multimedia TOOLKIT header#include "ltmm.h"#include "resource.h"#include <tchar.h>#include <stdio.h>#include <assert.h>HINSTANCE g_hInstance; // application instance handleIltmmConvert* 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;BSTR bstr2;HRESULT hr;long state;long type;long streams;IltmmVCRControl* pVCR;switch (msg){case WM_INITDIALOG:// assign the notification windowg_pConvert->SetNotifyWindow((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// g_pConvert->EditGraph();g_pConvert->get_UnrenderedStreams(&streams);if(streams != 0)MessageBox(hwnd, _T("Not all the streams could be rendered."), _T("Convert"), MB_ICONEXCLAMATION | MB_OK);g_pConvert->get_TargetVCRControl(&pVCR);hr = pVCR->Record();pVCR->Release();if(SUCCEEDED(hr))Sleep(2000);// start the conversionhr = g_pConvert->StartConvert();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 vcrg_pConvert->get_TargetVCRControl(&pVCR);pVCR->Stop();pVCR->Release();}return TRUE;break;case WM_DESTROY:// reset the notification windowg_pConvert->SetNotifyWindow((long) NULL, 0);#ifdef _DEBUG{long state, err, pc;double start, end, dur;TCHAR sz[1024];// get the current stateg_pConvert->get_State(&state);// get the current stateg_pConvert->get_ConvertError(&err);// get the amount convertedg_pConvert->get_PercentComplete(&pc);// get the startg_pConvert->get_SelectionStart(&start);// get the endg_pConvert->get_SelectionEnd(&end);// get the durationg_pConvert->get_Duration(&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;}//// SetAVIRecompression// sets up LEAD video compression, MP3 audio compression, and AVI file output//// hwndParent = parent window for compressor property dialog boxes//HRESULT SetAVIRecompression(HWND hwndParent){IltmmCompressors* pCompressors;long index;VARIANT_BOOL f;BSTR bstr;// select the LEAD video compressorg_pConvert->get_VideoCompressors(&pCompressors);bstr = SysAllocString(L"@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\\LEAD MCMP/MJPEG Codec (2.0)");pCompressors->Find(bstr, &index);SysFreeString(bstr);if(index < 0){// compressor isn't registeredpCompressors->Release();return E_FAIL;}pCompressors->put_Selection(index);pCompressors->Release();// select the MP3 audio video compressorg_pConvert->get_AudioCompressors(&pCompressors);bstr = SysAllocString(L"@device:cm:{33D9A761-90C8-11D0-BD43-00A0C911CE86}\\85MPEG Layer-3");pCompressors->Find(bstr, &index);SysFreeString(bstr);if(index < 0){// compressor isn't registeredpCompressors->Release();return E_FAIL;}pCompressors->put_Selection(index);pCompressors->Release();// set output format to AVIg_pConvert->put_TargetFormat(ltmmConvert_TargetFormat_Avi);#ifdef _DEBUG{long v;g_pConvert->get_TargetFormat(&v);assert(v == ltmmConvert_TargetFormat_Avi);}#endif// set video compressor propertiesg_pConvert->HasDialog(ltmmConvert_Dlg_VideoCompressor, &f);if(f)g_pConvert->ShowDialog(ltmmConvert_Dlg_VideoCompressor, (long) hwndParent);// set audio compressor propertiesg_pConvert->HasDialog(ltmmConvert_Dlg_AudioCompressor, &f);if(f)g_pConvert->ShowDialog(ltmmConvert_Dlg_AudioCompressor, (long) hwndParent);return S_OK;}// RecompressFileToDVDevice// recompresses file to DV device//// pszSource = source file path////HRESULT RecompressFileToDVDevice(LPCTSTR pszSource){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 = g_pConvert->put_SourceFile(bstr);SysFreeString(bstr);if(FAILED(hr))return hr;// set target devicehr = g_pConvert->put_TargetFormat(ltmmConvert_TargetFormat_dvsd);if(FAILED(hr))return hr;g_pConvert->get_AudioCompressors(&pCompressors);hr = pCompressors->put_Selection(-1);pCompressors->Release();if(FAILED(hr))return hr;g_pConvert->get_VideoCompressors(&pCompressors);hr = pCompressors->put_Selection(-1);pCompressors->Release();if(FAILED(hr))return hr;g_pConvert->get_TargetDevices(&pDevices);hr = pDevices->put_Selection(0);pDevices->Release();if(FAILED(hr))return hr;// do conversionhr = (HRESULT) DialogBox(g_hInstance, (LPCTSTR)IDD_CONVERTDLG, NULL, ConvertDlgProc);return hr;}int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){HRESULT hr;g_hInstance = hInstance;// 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"));if(FAILED(hr))goto error;error:// cleanupif(g_pConvert)g_pConvert->Release();CoUninitialize();return 0;}
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
