Products | Support | Send comments on this topic. | Email a link to this topic. | Back to Getting Started | Help Version 18.0.10.24
LEADTOOLS Multimedia API Help

IltmmWMScript CreateScriptStream Example for C++

Show in webframe

This example shows how to add stream scripts from a capture graph.

#define MAKE_MEDIA_PATH(pFileName) (TEXT("C:\\LEADTOOLS 18\\Media\\")TEXT(pFileName))


void CreateScriptStream(IltmmCapture *pCapture)
{
   HRESULT hr = S_OK;
   IUnknown *punk;
   IltmmWMScript *pWMScript;

   // source and target path names
   BSTR bstrTarget = SysAllocString(MAKE_MEDIA_PATH("source_script.wmv"));
   
   // set the source, target and WMV target formats for our conversion
   hr = SelectCaptureDevices(pCapture);
   if (FAILED(hr))
   {
      MessageBox(NULL, L"Unable to select capture devices", L"WMScripting Example", MB_OK);
      return;
   }

   pCapture->put_TargetFile(bstrTarget);
   pCapture->put_TargetFormat(ltmmCapture_TargetFormat_WMV_Mux);

   // free the BSTR
   SysFreeString(bstrTarget);

   // get the target object
   pCapture->GetSubObject(ltmmCapture_Object_TargetFilter, &punk);

   if (punk)
   {
      // get the WMScript object
      punk->QueryInterface(IID_IltmmWMScript, (void**)&pWMScript);
      if (pWMScript)
      {
         WCHAR szTemp[128];
         double scriptTime;
         BSTR bstrScriptCmd;

         // turn off stream scripts and remove any header scripts
         pWMScript->put_EnableScriptStream(VARIANT_TRUE);
         pWMScript->RemoveAllHeaderScripts();

         // create a sample header script (type of caption) and set it to execute @ 2 secs into capture
         scriptTime = 2.0;
         swprintf_s(szTemp, _countof(szTemp), L"Sample caption script at %g seconds", scriptTime);      
         bstrScriptCmd = SysAllocString(szTemp);

         // add the header script
         hr = pWMScript->WriteScriptStream(L"caption", bstrScriptCmd, scriptTime);
         // free the bstr
         SysFreeString(bstrScriptCmd);

         // now close the script stream
         hr = pWMScript->CloseScriptStream();

         pWMScript->Release();
      }
            
      // if all is well, run the capture now
      if (SUCCEEDED(hr))
         hr = pCapture->StartCapture(ltmmCapture_Mode_VideoAndAudio);

      punk->Release();
   }
}

BOOL SelectDeviceLike(IltmmDevices *pDevices, LPTSTR szDevSrch)
{
   BOOL bFound = FALSE;
   long i, count = 0;
   
   pDevices->put_Selection(-1);
   pDevices->get_Count(&count);

   for(i = 0; i < count; i++)
   {
      IltmmDevice *pDevice;
      BSTR name;
      pDevices->Item(i, &pDevice);

      if (pDevice)
      {
         // get the friendly name for comparisson check
         pDevice->get_FriendlyName(&name);

         // if the device name contains our search string, select it
         if(!wcsstr(name, szDevSrch))
         {
            pDevices->put_Selection(i);
            pDevice->Release();
            SysFreeString(name);

            bFound = TRUE;
            break;
         }
         
         SysFreeString(name);
         pDevice->Release();
         pDevice = NULL;
      }
   }

   return bFound;
}

HRESULT SelectCaptureDevices(IltmmCapture *pCapture)
{
   IltmmDevices *pDevices;
   BOOL bSelected = FALSE;
   
   pCapture->get_VideoDevices(&pDevices);
   if (!pDevices)
      return E_FAIL;

   bSelected = SelectDeviceLike(pDevices, L"Logitech");

   pDevices->Release();
   pDevices = NULL;

   if (!bSelected)
      return E_FAIL;

   bSelected = FALSE;
   pCapture->get_AudioDevices(&pDevices);
   if (!pDevices)
      return E_FAIL;

   bSelected = SelectDeviceLike(pDevices, L"Logitech");
   
   pDevices->Release();

   if (!bSelected)
      return E_FAIL;

   return S_OK;
}
Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.