从视频监控设备收到标准的264编码数据,以AVIFile API封装成.avi文件。
保存后,用暴风或其它播放器打开,视频数据不连续,几秒跳一帧(视频是没问题的,实时看是正常的)
AVIFile部分的代码如下,哪位大侠给说说。
HRESULT CAVIFile::OpenFile(LPCTSTR szFileName)
{
HRESULT result;
int m_ImageWidth = 352;
int m_ImageHeight = 288;
int m_dwBufferSize = 102400;
result = AVIFileOpen(&m_aviFile,szFileName,OF_CREATE|OF_WRITE,0);
//设置视频流格式
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 = 18; //上传的视频是每秒18帧。
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;
//创建数据流
result = AVIFileCreateStream(m_aviFile,&m_aviVideoStream,(AVISTREAMINFO *)&m_aviVideoStreamInfo);
//设置帧格式
BITMAPINFOHEADER bmpInfoHdr;
bmpInfoHdr.biSize = sizeof(BITMAPINFOHEADER);
bmpInfoHdr.biWidth = m_ImageWidth;
bmpInfoHdr.biHeight = m_ImageHeight;
bmpInfoHdr.biBitCount = 8;//image1.GetBPP();
bmpInfoHdr.biCompression = 0x34363248;//BI_RGB;
bmpInfoHdr.biSizeImage = 0;
bmpInfoHdr.biClrImportant = 0;
bmpInfoHdr.biClrUsed = 0;
bmpInfoHdr.biXPelsPerMeter = 0;
bmpInfoHdr.biYPelsPerMeter = 0;
bmpInfoHdr.biPlanes = 1;
result = AVIStreamSetFormat(m_aviVideoStream,m_aviVideoFrames,&bmpInfoHdr,sizeof(bmpInfoHdr));
//设置音频流格式
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;
//创建数据流
//result = AVIFileCreateStream(m_aviFile,&m_aviAudioStream,(AVISTREAMINFO *)&m_aviAudioStreamInfo);
//设置音频格式
/*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));
*/
return 0;
}
HRESULT CAVIFile::Write(LPVOID lpBuffer, LONG cbBuffer)
{
HRESULT result;
result = AVIStreamWrite(m_aviVideoStream,m_aviVideoFrames,1,lpBuffer,cbBuffer,AVIIF_KEYFRAME,NULL,NULL);
m_aviVideoFrames++;
return 0;
}
void CAVIFile::Close()
{
if(m_aviVideoStream)
{
m_aviVideoStream->Release();
m_aviVideoStream = NULL;