下面为我用VFW进行视频录像的代码,其中,点击"开始录像"按钮,调用OnStartlu(),开始录像,
然后创建一个录像进程进行录像,在点击"结束录像"按钮时调用OnEndlu(),结束录像,现在的问题是:点击了开始录像按钮后,不管过多久点击结束录像按钮所录下来录像都只是录了7秒>怎么回事?
//开始录像
void CMyView::OnStartlu() 
{
// TODO: Add your command handler code here
//选择压缩算法
capDlgVideoCompression(hwndc);
CAPTUREPARMS capparm;
capparm.fAbortLeftMouse=FALSE;
       capparm.fAbortRightMouse=FALSE;
 capparm.fLimitEnabled=FALSE;
capCaptureSetSetup(hwndc,&capparm,sizeof(CAPTUREPARMS));
//新建AVI文件来存储录像
isrecording=TRUE;
isvideothreadend=FALSE;
if(!isrecordfileopen)//如果当前没有文件被打开
{
OPENFILENAME ofn;//打开文件结构体 //初始化
ZeroMemory(&ofn,sizeof(OPENFILENAME));
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.lpstrFile=recordfile;
ofn.nMaxFile=sizeof(recordfile);
ofn.lpstrFilter="Video\0*.avi";
ofn.nFilterIndex=1;
ofn.lpstrFileTitle=NULL;
ofn.nMaxFileTitle=0;
ofn.lpstrInitialDir=NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
ofn.hwndOwner = hwndc; //显示保存文件对话框
if(GetSaveFileName(&ofn) == TRUE)
{
strcpy(recordfile, ofn.lpstrFile);
strcat(recordfile, ".avi"); isrecordfileopen=TRUE;  //创建一个录像进程
DWORD id;
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
            videothread=CreateThread(&sa, (ULONG)0, 
videothreadproc, (LPVOID)(ULONG)0, (ULONG)0, &id);
if(videothread==NULL)
AfxMessageBox("创建录像进程失败!");
return;
}
}}//录像进程处理过程
DWORD WINAPI videothreadproc(LPVOID lpParameter)
{
//开始捕捉视频
capCaptureSequence(hwndc);
while(!isvideothreadend);//不断执行
AfxMessageBox("录像结束!");
return 0;}//结束录像
void CMyView::OnEndlu() 
{
// TODO: Add your command handler code her
if(isrecordfileopen)//如果当前已有文件被打开
{
       if(isrecording)//如果正在录像
   {
          isvideothreadend=TRUE;
  //结束捕捉过程并保存为指定文件
  capFileSaveAs(hwndc,recordfile);
  strroot2=recordfile;
  int folderlen1=strroot2.ReverseFind('\\');
         CString strPicFolder1=strroot2.Left(folderlen1+1);
//
       tempfilename2=strroot2.Right(strroot2.GetLength()-strPicFolder1.GetLength());   selchg1=TRUE;
  //CMainFrame* pmain53=(CMainFrame*)AfxGetMainWnd();
 // pmain53->ShowControlBar(&(pmain53->m_wndToolBar1),TRUE,TRUE);
  isrecording=FALSE;
  isrecordfileopen=FALSE;
  return;
   }
   if(!isrecording)//如果不在录像
   {
   int temp=0;
   temp=MessageBox("是否要覆盖此文件?","警告",MB_YESNO | MB_ICONWARNING);
   if(temp!=IDYES)//不覆盖,则不进行录像,退出
   {
              isrecordfileopen=FALSE;
   }
   if(temp==IDYES)
   {
   capCaptureSequence(hwndc);//开始录像
   isrecording=TRUE;
   }
   return;
   }
}
}

解决方案 »

  1.   

    while(!isvideothreadend);//不断执行 -- isvideothreadend 是全局吗 在线程里?
    至于时间 用capCaptureSetSetup设置一下试试:
    CAPTUREPARMS
     DWORD dwMCIStartTime; DWORD dwMCIStopTime; 
      

  2.   

    while(!isvideothreadend);//不断执行 -- isvideothreadend 是全局吗 在线程里? 
    是全局的至于时间 用capCaptureSetSetup设置一下试试: 
    CAPTUREPARMS 
    DWORD dwMCIStartTime; DWORD dwMCIStopTime; 用了默认设置...
      

  3.   

    下面为我用VFW进行视频录像的代码,其中,点击"开始录像"按钮,调用OnStartlu(),开始录像, 
    然后创建一个录像进程进行录像,在点击"结束录像"按钮时调用OnEndlu(),结束录像,现在的问题是:点击了开始录像按钮后,不管过多久点击结束录像按钮所录下来录像都只是录了7秒>怎么回事? 
    *********************************
    现在变成1分30秒了.........盼高手指点,,时间比较紧,,,