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

directshow 之 视频文件AVI格式摄制

2012年11月16日 ⁄ 综合 ⁄ 共 2818字 ⁄ 字号 评论关闭

HRESULT CVideoSource::RecoderAVIFrames(char* szFile)
{
 
 HRESULT hr = NULL;
 OFSTRUCT os;

 //IBaseFilter *pMux;
 IFileSinkFilter *pSink;
 IConfigAviMux * pConfigAviMux;

 if(OpenFile(szFile, &os, OF_EXIST) == HFILE_ERROR)
 {
  // bring up dialog, and set new file size
  /*CFile f;
  bool bFile  = f.Open(szFile,CFile::modeCreate|CFile::modeWrite);
  if (!bFile)
  {
   MessageBox(AfxGetMainWnd()->m_hWnd, TEXT("很抱歉,不能创建文件,请检查该文件夹是否有权限的严格控制"),
    TEXT("Error"),
    MB_OK | MB_ICONEXCLAMATION);
  }*/
  hr = m_pBuilder->AllocCapFile(LPCOLESTR(szFile),(DWORDLONG)100* 1024 * 1024);
  if (hr != NOERROR)
  {
   MessageBox(AfxGetMainWnd()->m_hWnd, TEXT("很抱歉,磁盘空间不够,请调整磁盘空间"),
    TEXT("Error"),
    MB_OK | MB_ICONEXCLAMATION);
   return FALSE;
  }
  
 }

 //hr = m_pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi,(LPCOLESTR)szFile, &m_pMux, NULL);
 //hr = m_pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi,(LPCOLESTR)szFile, &m_pMux, &pSink);
 hr = m_pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi,(LPCOLESTR)szFile, &m_pVideoRender, &pSink);
 
 if(hr != NOERROR)
 {
  ErrMsg(TEXT("Cannot set output file")); 
 }
 
 // Now tell the AVIMUX to write out AVI files that old apps can read properly.
 // If we don't, most apps won't be able to tell where the keyframes are,
 // slowing down editing considerably
 // Doing this will cause one seek (over the area the index will go) when
 // you capture past 1 Gig, but that's no big deal.
 // NOTE: This is on by default, so it's not necessary to turn it on

 // Also, set the proper MASTER STREAM
 hr = m_pVideoRender->QueryInterface(IID_IConfigAviMux, (void **)&pConfigAviMux);
 if (hr == NOERROR && pConfigAviMux)
 {
  hr = pConfigAviMux->SetOutputCompatibilityIndex(TRUE);
 }

 

 // Render the video capture and preview pins - even if the capture filter only
 // has a capture pin (and no preview pin) this should work... because the
 // capture graph builder will use a smart tee filter to provide both capture
 // and preview.  We don't have to worry.  It will just work.
 //

 // NOTE that we try to render the interleaved pin before the video pin, because
 // if BOTH exist, it's a DV filter and the only way to get the audio is to use
 // the interleaved pin.  Using the Video pin on a DV filter is only useful if
 // you don't want the audio.
 //m_pBuilder->GetFiltergraph(&m_pGrapher);
 //有声音录制,需设置
 /*if(gcap.fCapAudio)
 {
  hr = gcap.pConfigAviMux->SetMasterStream(gcap.iMasterStream);
  if(hr != NOERROR)
   ErrMsg(TEXT("SetMasterStream failed!"));
 }*/
 
 
 hr = m_pBuilder->RenderStream(&PIN_CATEGORY_CAPTURE,&MEDIATYPE_Interleaved,m_pVideoCap, NULL, m_pVideoRender);
 //hr = m_pBuilder->RenderStream(&PIN_CATEGORY_CAPTURE,&MEDIATYPE_Interleaved,m_pVideoCap, NULL, m_pMux);
 if(hr != NOERROR)
 {
  hr = m_pBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pVideoCap, NULL, m_pVideoRender);
  //hr = m_pBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pVideoCap, NULL, m_pMux);
  if(hr != NOERROR)
  {
   ErrMsg(TEXT("Cannot render video capture stream"));    
  }
 }
 // tell the file writer to use the new filename
 if(m_pFileSink)
 {
  //m_pFileSink->SetFileName(T2W(szFile), NULL);
 }
 StartCapture();
 

 return hr;
}

抱歉!评论已关闭.