This example shows how to add and remove header scripts from a convert graph.
#define MAKE_MEDIA_PATH(pFileName) (TEXT("C:\\LEADTOOLS 20\\Media\\")TEXT(pFileName))void ManageHeaderScripts(IltmmConvert* pConvert){HRESULT hr = S_OK;IUnknown *punk;IltmmWMScript *pWMScript;// source and target path namesBSTR bstrSource = SysAllocString(MAKE_MEDIA_PATH("source.avi"));BSTR bstrTarget = SysAllocString(MAKE_MEDIA_PATH("source_script.wmv"));// set the source, target and WMV target formats for our conversionpConvert->put_SourceFile(bstrSource);pConvert->put_TargetFile(bstrTarget);pConvert->put_TargetFormat(ltmmConvert_TargetFormat_WMV_Mux);// free the BSTRsSysFreeString(bstrSource);SysFreeString(bstrTarget);// get the target objectpConvert->GetSubObject(ltmmConvert_Object_TargetFilter, &punk);if (punk){// get the WMScript objectpunk->QueryInterface(IID_IltmmWMScript, (void**)&pWMScript);if (pWMScript){double duration;long lScriptCnt;WCHAR szTemp[128];double scriptTime;BSTR bstrScriptType, bstrScriptCmd;// turn off stream scripts and remove any header scriptspWMScript->put_EnableScriptStream(VARIANT_FALSE);pWMScript->RemoveAllHeaderScripts();// get the source durationhr = pConvert->get_Duration(&duration);if (FAILED(hr))duration = 0.5 ;//assume a relatively small duration// create a sample header script (type of caption) and set it to execute @ 0 secs// we will delete this one later for demonstation purposesscriptTime = 0.;swprintf_s(szTemp, _countof(szTemp), L"Sample caption script at %g seconds", scriptTime);bstrScriptCmd = SysAllocString(szTemp);// add the header scripthr = pWMScript->AddHeaderScript(L"caption", bstrScriptCmd, scriptTime);// free the BSTRSysFreeString(bstrScriptCmd);// create a sample header script (type of caption) and set it to execute @ duration / 2scriptTime = duration/2.0;swprintf_s(szTemp, _countof(szTemp), L"Sample caption script at %g seconds", scriptTime);bstrScriptCmd = SysAllocString(szTemp);// add the header scripthr = pWMScript->AddHeaderScript(L"caption", bstrScriptCmd, scriptTime);// free the BSTRSysFreeString(bstrScriptCmd);// now get the header script count, should be 2 from abovehr = pWMScript->get_HeaderScriptCount(&lScriptCnt);if (SUCCEEDED(hr) && lScriptCnt>0){long i;// iterate through the script indexesfor (i=0; i<lScriptCnt; i++){if (i==0) // if first one, delete it (demonstration purposes){pWMScript->RemoveHeaderScript(i);}else if (i==1) // if second one, just get it and display a msg box with properties{hr = pWMScript->GetHeaderScript(i, &bstrScriptType, &bstrScriptCmd, &scriptTime);if (SUCCEEDED(hr)){WCHAR szTemp[255];swprintf_s(szTemp, _countof(szTemp), L"type: %s\ncmd: %s\ntime: %g", bstrScriptType, bstrScriptCmd, scriptTime);::MessageBox(NULL, szTemp, L"Script Properties", MB_OK);// free the BSTRsSysFreeString(bstrScriptType);SysFreeString(bstrScriptCmd);}}}}// release the ASF mux script interfacepWMScript->Release();}// release the target filterpunk->Release();// if all is well, run the convert nowif (SUCCEEDED(hr))hr = pConvert->StartConvert();}}
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
