视频存储问题
发表在C语言图书答疑 2010-08-21
是否精华
版块置顶:
我现在在做视频存储的工作,点击“保存”按钮对摄像头采集的视频进行算法处理后以AVI的格式存储到硬盘中,保存按钮函数的内容是:
void CShowStreamDlg::OnBaocun() 
{      
         CString        filename;
         CFileDialog FileDlg(FALSE,_T("avi"));
         if(FileDlg.DoModal()==IDOK)
{
               ilename=FileDlg.GetPathName();
               nFrames=0;
               m_bIsbaocun=true;
}

}
下面是回调函数里的内容,但是保存成AVI视频文件时,文件占存储空间,但是打不开,用暴风影音打开提示说文件头不完整,不是标准的视频文件。
我个人觉得可能是这个函数的参数设置的不对AVIStreamSetFormat(ps,nFrames,&(OutHeader),sizeof(OutHeader));您看能不能给我指点指点,学生感激不尽!
                  if(m_bIsbaocun==true)
{
  if(nFrames==0)
  {
                          AVIFileInit();
                          AVIFileOpen(&pfile,filename,OF_WRITE|OF_CREATE,NULL);
     memset(&strhdr,0,sizeof(strhdr));
     strhdr.fccType=streamtypeVIDEO;
     strhdr.fccHandler=0;
     strhdr.dwScale=1;
     strhdr.dwRate=25;
     strhdr.dwSuggestedBufferSize=pInfo->bmiHeader.biSizeImage;
SetRect(&strhdr.rcFrame,0,0,pInfo->bmiHeader.biWidth,pInfo->bmiHeader.biHeight);
     AVIFileCreateStream(pfile,&ps,&strhdr);
   }
            AVIStreamSetFormat(ps,nFrames,&(OutHeader),sizeof(OutHeader));
   AVIStreamWrite(ps,nFrames,1,(LPBYTE)GrayImage,OutHeader.biSizeImage,AVIIF_KEYFRAME,NULL,NULL);
  nFrames++;
}
    if(m_bIstingzhibaocun==true)
{
   AVIStreamClose(ps);
   if(pfile!=NULL)
 AVIFileExit();
   MessageBox("保存成功");
   m_bIsbaocun=false;
   m_bIstingzhibaocun=false;
}
分享到:
精彩评论 1
liangshui
学分:0 LV1
2010-08-23
沙发
AVIFileInit();
//创建AVI文件
if(AVIFileOpen(&m_aviFile,aviFileFullName,OF_CREATE|OF_WRITE,0))
{
MessageBox("create file '"+aviFileFullName+"' error");
return;
}
//设置视频流格式
AVISTREAMINFOW m_aviVideoStreamInfo;
m_aviVideoStreamInfo.fccType = streamtypeVIDEO;
m_aviVideoStreamInfo.fccHandler = 0;
m_aviVideoStreamInfo.dwFlags = 0;
m_aviVideoStreamInfo.dwCaps = 0;
m_aviVideoStreamInfo.wPriority = 0;
m_aviVideoStreamInfo.wLanguage = 0;
m_aviVideoStreamInfo.dwRate = 5; //每秒5帧
m_aviVideoStreamInfo.dwScale = 1;
m_aviVideoStreamInfo.dwQuality = 0;
m_aviVideoStreamInfo.dwSuggestedBufferSize = m_ImageWidth*m_ImageHeight*3;
m_aviVideoStreamInfo.dwStart = 0;
m_aviVideoStreamInfo.dwInitialFrames = 0;
m_aviVideoStreamInfo.dwSampleSize = 0;
m_aviVideoStreamInfo.rcFrame.left = 0;
m_aviVideoStreamInfo.rcFrame.top = 0;
m_aviVideoStreamInfo.rcFrame.right = m_ImageWidth;
m_aviVideoStreamInfo.rcFrame.bottom = m_ImageHeight;
m_aviVideoStreamInfo.dwEditCount = 0;
m_aviVideoStreamInfo.dwFormatChangeCount = 0;
strcpy((char *)m_aviVideoStreamInfo.szName,"ScreenCap.avi");
m_aviVideoStreamInfo.dwLength = 0;
//设置音频流格式
AVISTREAMINFOW m_aviAudioStreamInfo;
m_aviAudioStreamInfo.fccType = streamtypeAUDIO;
m_aviAudioStreamInfo.fccHandler = 0;
m_aviAudioStreamInfo.dwFlags = 0;
m_aviAudioStreamInfo.dwCaps = 0;
m_aviAudioStreamInfo.wPriority = 0;
m_aviAudioStreamInfo.wLanguage = 0;
m_aviAudioStreamInfo.dwScale = 1; //声道数
m_aviAudioStreamInfo.dwRate = 8000; //Hz
m_aviAudioStreamInfo.dwStart = 0;
m_aviAudioStreamInfo.dwInitialFrames = 0;
m_aviAudioStreamInfo.dwSuggestedBufferSize = m_dwBufferSize;
m_aviAudioStreamInfo.dwQuality = 0;
m_aviAudioStreamInfo.dwSampleSize = 1;
m_aviAudioStreamInfo.rcFrame.bottom = 0;
m_aviAudioStreamInfo.rcFrame.left = 0;
m_aviAudioStreamInfo.rcFrame.right = 0;
m_aviAudioStreamInfo.rcFrame.top = 0;
m_aviAudioStreamInfo.dwEditCount = 0;
m_aviAudioStreamInfo.dwFormatChangeCount = 0;
m_aviAudioStreamInfo.dwLength = 0;
//创建数据流
AVIFileCreateStream(m_aviFile,&m_aviVideoStream,(AVISTREAMINFO *)&m_aviVideoStreamInfo);
AVIFileCreateStream(m_aviFile,&m_aviAudioStream,(AVISTREAMINFO *)&m_aviAudioStreamInfo);
//写数据流
//-----视屏流
BITMAPINFOHEADER bmpInfoHdr;
bmpInfoHdr.biSize = sizeof(BITMAPINFOHEADER);
bmpInfoHdr.biWidth = m_ImageWidth;
bmpInfoHdr.biHeight = m_ImageHeight;
bmpInfoHdr.biBitCount = image1.GetBPP();
bmpInfoHdr.biCompression = BI_RGB;
bmpInfoHdr.biSizeImage = 0;
bmpInfoHdr.biClrImportant = 0;
bmpInfoHdr.biClrUsed = 0;
bmpInfoHdr.biXPelsPerMeter = 0;
bmpInfoHdr.biYPelsPerMeter = 0;
bmpInfoHdr.biPlanes = 1;
//设置帧格式
AVIStreamSetFormat(m_aviVideoStream,m_aviVideoFrames,&bmpInfoHdr,sizeof(bmpInfoHdr));
//写数据
AVIStreamWrite(m_aviVideoStream,m_aviVideoFrames ,1,(LPBYTE) buffer,size ,AVIIF_KEYFRAME,NULL,NULL);
m_aviVideoFrames++;
///-------------
//----音频流
WAVEFORMAT waveFormat;
waveFormat.nAvgBytesPerSec = m_Format.nAvgBytesPerSec;
waveFormat.nBlockAlign = m_Format.nBlockAlign;
waveFormat.nChannels = m_Format.nChannels;
waveFormat.nSamplesPerSec = m_Format.nSamplesPerSec;
waveFormat.wFormatTag = m_Format.wFormatTag;
//设置音频格式
AVIStreamSetFormat(m_aviAudioStream,m_aviAudioFrames,&m_Format,sizeof(m_Format));
//写数据
AVIStreamWrite(m_aviAudioStream,m_aviAudioFrames ,1,(LPBYTE)pBuffer,pWaveHdr->dwBytesRecorded ,AVIIF_KEYFRAME,NULL,NULL);
m_aviAudioFrames++;
///-----------
//释放数据流及文件
if(m_aviVideoStream)
{
m_aviVideoStream->Release();
m_aviVideoStream = NULL;
}

if(m_aviAudioStream)
{
m_aviAudioStream->Release();
m_aviAudioStream = NULL;
}

if(m_aviFile)
{
m_aviFile->Release();
m_aviFile = NULL;
}
AVIFileExit();
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照