现在的位置: 首页 > 综合 > 正文

directshow学习1

2013年08月01日 ⁄ 综合 ⁄ 共 1372字 ⁄ 字号 评论关闭

HRESULT hr;
 IGraphBuilder *pGraph;
 CoInitialize(NULL);
 
 hr = CoCreateInstance(CLSID_FilterGraph /*类标识符*/,
  NULL,
  CLSCTX_INPROC_SERVER,
  IID_IGraphBuilder/*接口标识符*/,
  (void **)&pGraph
  );

 ICaptureGraphBuilder2 *pBuild; // Capture Graph Builder
 // Initialize pBuild (not shown).
 IBaseFilter *pCap; // Video capture filter.
 /* Initialize pCap and add it to the filter graph (not shown). */
 hr= pBuild->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
  pCap, NULL, NULL);
 IBaseFilter *pMux;
 hr=pBuild->SetOutputFileName(
  &MEDIASUBTYPE_Avi, // Specifies AVI for the target file.
  L"C://Example.avi", // File name.
  &pMux, // Receives a pointer to the mux.
  NULL); // (Optional) Receives a pointer to the file sink.
 hr = pBuild->RenderStream(
  &PIN_CATEGORY_CAPTURE, // Pin category.
  &MEDIATYPE_Video, // Media type.
  pCap, // Capture filter.
  NULL, // Intermediate filter (optional).
  pMux); // Mux or file sink filter.
 // Release the mux filter.
 pMux->Release();
 
 IConfigAviMux *pConfigMux = NULL;
 hr = pMux->QueryInterface(IID_IConfigAviMux, (void**)&pConfigMux);
 if (SUCCEEDED(hr))
 {
  pConfigMux->SetMasterStream(1);
  pConfigMux->Release();
 }
 
 IBaseFilter *pEncoder;
 IFilterGraph * pGraph1;
 /* Create the encoder filter (not shown). */
 // Add it to the filter graph.
 pGraph1->AddFilter(pEncoder, L"Encoder");
  /* Call SetOutputFileName as shown previously. */
  // Render the stream.
  hr = pBuild->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,pCap, pEncoder, pMux);
 pEncoder->Release();

抱歉!评论已关闭.