用vfw进行视频录制转化为avi时,总感觉整个资源都被占用了,一动甚至感觉录制被中断了。网上查了一下有些说是用多线程,但感觉效果也不理想。后面还是老老实实查看msdn,调试时发现主要卡在capCaptureSequence,capFileSaveAs 这两个函数。
msdn上有说明capCaptureSequence 函数 第二点,By default, the capture window does not allow other applications to continue running during capture. To override this, either set the fYield member of the CAPTUREPARMS structure to TRUE, or install a yield callback function.
因此先获取,在那要求设置
UINT RecordVideo(LPVOID pParam)
{
HWND m_hCapWnd = (HWND)pParam;
CAPTUREPARMS CapParms;
capCaptureGetSetup(m_hCapWnd,&CapParms,sizeof(CAPTUREPARMS));
CapParms.fYield = TRUE;
capCaptureSetSetup(m_hCapWnd,&CapParms,sizeof(CAPTUREPARMS));
capCaptureSequence(m_hCapWnd);
capFileSaveAs(m_hCapWnd,(LPTSTR)(m_aviname).GetBuffer());
return 0;
}
m_aviname 为avi的名称,之前设置 capFileSetCaptureFile(m_hCapWnd,m_aviname.GetBuffer(255));
msdn上有说明capCaptureSequence 函数 第二点,By default, the capture window does not allow other applications to continue running during capture. To override this, either set the fYield member of the CAPTUREPARMS structure to TRUE, or install a yield callback function.
因此先获取,在那要求设置
UINT RecordVideo(LPVOID pParam)
{
HWND m_hCapWnd = (HWND)pParam;
CAPTUREPARMS CapParms;
capCaptureGetSetup(m_hCapWnd,&CapParms,sizeof(CAPTUREPARMS));
CapParms.fYield = TRUE;
capCaptureSetSetup(m_hCapWnd,&CapParms,sizeof(CAPTUREPARMS));
capCaptureSequence(m_hCapWnd);
capFileSaveAs(m_hCapWnd,(LPTSTR)(m_aviname).GetBuffer());
return 0;
}
m_aviname 为avi的名称,之前设置 capFileSetCaptureFile(m_hCapWnd,m_aviname.GetBuffer(255));
至此通过线程和msdn解决了vfw录像时卡住的问题。
ps: 进行拍照时,设置分辨率不同可能引起视频窗口之拍摄到一个角落,调用库函数 capPreviewScale(m_hCapWnd,TRUE);