将采集卡采到的每帧数据保存为AVI视频的问题
每一帧图像大小是1024*1024,数据位是8位(灰度图像)。现在我将每一帧的数据写入到AVI文件中,但是在播放时候却不不是灰度图像,而是彩色图像。是怎么回事?谢谢,跪求。。。我将源码贴下
PAVIFILE m_pAviFile;
if(FAILED(AVIFileOpen(&m_pAviFile, m_szFileName, OF_CREATE|OF_WRITE, NULL)))
{
SetErrorMessage("Unable to Create the Movie File");
return E_FAIL;
}
AVISTREAMINFO m_AviStreamInfo;
ZeroMemory(&m_AviStreamInfo,sizeof(AVISTREAMINFO));
m_AviStreamInfo.fccType = streamtypeVIDEO;
m_AviStreamInfo.fccHandler = m_dwFCCHandler;
m_AviStreamInfo.dwScale = 1;
m_AviStreamInfo.dwRate = m_dwFrameRate; // Frames Per Second;
m_AviStreamInfo.dwQuality = -1; // Default Quality
m_AviStreamInfo.dwSuggestedBufferSize = 1024*1024;
SetRect(&m_AviStreamInfo.rcFrame, 0, 0, 1024, 1024);
_tcscpy(m_AviStreamInfo.szName, _T("Video Stream"));
PAVISTREAM m_pAviStream;
if(FAILED(AVIFileCreateStream(m_pAviFile,&m_pAviStream,&m_AviStreamInfo)))
{
SetErrorMessage("Unable to Create Video Stream in the Movie File");
return E_FAIL;
}
AVICOMPRESSOPTIONS m_AviCompressOptions;
ZeroMemory(&m_AviCompressOptions,sizeof(AVICOMPRESSOPTIONS));
m_AviCompressOptions.fccType=streamtypeVIDEO;
m_AviCompressOptions.fccHandler=mmioFOURCC('M','S','V','C');
m_AviCompressOptions.dwFlags=AVICOMPRESSF_KEYFRAMES|AVICOMPRESSF_VALID;
m_AviCompressOptions.dwKeyFrameEvery=1;
PAVISTREAM m_pAviCompressedStream;
if(FAILED(AVIMakeCompressedStream(&m_pAviCompressedStream,m_pAviStream,&m_AviCompressOptions,NULL)))
{
// One reason this error might occur is if you are using a Codec that is not
// available on your system. Check the mmioFOURCC() code you are using and make
// sure you have that codec installed properly on your machine.
SetErrorMessage("Unable to Create Compressed Stream: Check your CODEC options");
return E_FAIL;
}
BITMAPINFO bmpInfo;
ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biWidth = 1024;
bmpInfo.bmiHeader.biHeight = 1024;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biBitCount = 8;
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biSizeImage = bmpInfo.bmiHeader.biWidth*bmpInfo.bmiHeader.biHeight*bmpInfo.bmiHeader.biBitCount/8;
if(FAILED(AVIStreamSetFormat(m_pAviCompressedStream,0,(LPVOID)&bmpInfo, bmpInfo.bmiHeader.biSize))) {
// One reason this error might occur is if your bitmap does not meet the Codec requirements.
// For example,
// your bitmap is 32bpp while the Codec supports only 16 or 24 bpp; Or
// your bitmap is 274 * 258 size, while the Codec supports only sizes that are powers of 2; etc...
// Possible solution to avoid this is: make your bitmap suit the codec requirements,
// or Choose a codec that is suitable for your bitmap.
SetErrorMessage("Unable to Set Video Stream Format");
return E_FAIL;
}
return S_OK; // Everything went Fine
}
DWORD dwSize=nWidth*nHeight*nBitsPerPixel/8;
if(FAILED(AVIStreamWrite(m_pAviCompressedStream,m_lSample++,1,pBits(指向数据位的指针),dwSize,0,NULL,NULL)))
{
SetErrorMessage(_T("Unable to Write Video Stream to the output Movie File"));
ReleaseMemory();
return E_FAIL;
}
把每帧图像保存成AVI视频没有问题,但是播放的时候有失真,不是黑白视频。例如,同一个保存的视频第一次播放是蓝色,第二次或许就成了红色。是不是我保存的时候没有将颜色表保存进去?但是我如果要在蓝色字体前面加上如下代码
for (i=0;i<256;i++)
{
bmpInfo.bmiHeader.bmiColors[i].rgbBlue = i ;
bmpInfo.bmiHeader.bmiColors[i].rgbGreen = i ;
bmpInfo.bmiHeader.bmiColors[i].rgbRed = i ;
bmpInfo.bmiHeader.bmiColors[i].rgbReserved = 0 ;
}的话。那么程序运行到蓝色那里就自动退出了。软件就关闭了。是什么原因呢?请各位帮忙改一下啊,谢谢啦。
PAVIFILE m_pAviFile;
if(FAILED(AVIFileOpen(&m_pAviFile, m_szFileName, OF_CREATE|OF_WRITE, NULL)))
{
SetErrorMessage("Unable to Create the Movie File");
return E_FAIL;
}
AVISTREAMINFO m_AviStreamInfo;
ZeroMemory(&m_AviStreamInfo,sizeof(AVISTREAMINFO));
m_AviStreamInfo.fccType = streamtypeVIDEO;
m_AviStreamInfo.fccHandler = m_dwFCCHandler;
m_AviStreamInfo.dwScale = 1;
m_AviStreamInfo.dwRate = m_dwFrameRate; // Frames Per Second;
m_AviStreamInfo.dwQuality = -1; // Default Quality
m_AviStreamInfo.dwSuggestedBufferSize = 1024*1024;
SetRect(&m_AviStreamInfo.rcFrame, 0, 0, 1024, 1024);
_tcscpy(m_AviStreamInfo.szName, _T("Video Stream"));
PAVISTREAM m_pAviStream;
if(FAILED(AVIFileCreateStream(m_pAviFile,&m_pAviStream,&m_AviStreamInfo)))
{
SetErrorMessage("Unable to Create Video Stream in the Movie File");
return E_FAIL;
}
AVICOMPRESSOPTIONS m_AviCompressOptions;
ZeroMemory(&m_AviCompressOptions,sizeof(AVICOMPRESSOPTIONS));
m_AviCompressOptions.fccType=streamtypeVIDEO;
m_AviCompressOptions.fccHandler=mmioFOURCC('M','S','V','C');
m_AviCompressOptions.dwFlags=AVICOMPRESSF_KEYFRAMES|AVICOMPRESSF_VALID;
m_AviCompressOptions.dwKeyFrameEvery=1;
PAVISTREAM m_pAviCompressedStream;
if(FAILED(AVIMakeCompressedStream(&m_pAviCompressedStream,m_pAviStream,&m_AviCompressOptions,NULL)))
{
// One reason this error might occur is if you are using a Codec that is not
// available on your system. Check the mmioFOURCC() code you are using and make
// sure you have that codec installed properly on your machine.
SetErrorMessage("Unable to Create Compressed Stream: Check your CODEC options");
return E_FAIL;
}
BITMAPINFO bmpInfo;
ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biWidth = 1024;
bmpInfo.bmiHeader.biHeight = 1024;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biBitCount = 8;
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biSizeImage = bmpInfo.bmiHeader.biWidth*bmpInfo.bmiHeader.biHeight*bmpInfo.bmiHeader.biBitCount/8;
if(FAILED(AVIStreamSetFormat(m_pAviCompressedStream,0,(LPVOID)&bmpInfo, bmpInfo.bmiHeader.biSize))) {
// One reason this error might occur is if your bitmap does not meet the Codec requirements.
// For example,
// your bitmap is 32bpp while the Codec supports only 16 or 24 bpp; Or
// your bitmap is 274 * 258 size, while the Codec supports only sizes that are powers of 2; etc...
// Possible solution to avoid this is: make your bitmap suit the codec requirements,
// or Choose a codec that is suitable for your bitmap.
SetErrorMessage("Unable to Set Video Stream Format");
return E_FAIL;
}
return S_OK; // Everything went Fine
}
DWORD dwSize=nWidth*nHeight*nBitsPerPixel/8;
if(FAILED(AVIStreamWrite(m_pAviCompressedStream,m_lSample++,1,pBits(指向数据位的指针),dwSize,0,NULL,NULL)))
{
SetErrorMessage(_T("Unable to Write Video Stream to the output Movie File"));
ReleaseMemory();
return E_FAIL;
}
把每帧图像保存成AVI视频没有问题,但是播放的时候有失真,不是黑白视频。例如,同一个保存的视频第一次播放是蓝色,第二次或许就成了红色。是不是我保存的时候没有将颜色表保存进去?但是我如果要在蓝色字体前面加上如下代码
for (i=0;i<256;i++)
{
bmpInfo.bmiHeader.bmiColors[i].rgbBlue = i ;
bmpInfo.bmiHeader.bmiColors[i].rgbGreen = i ;
bmpInfo.bmiHeader.bmiColors[i].rgbRed = i ;
bmpInfo.bmiHeader.bmiColors[i].rgbReserved = 0 ;
}的话。那么程序运行到蓝色那里就自动退出了。软件就关闭了。是什么原因呢?请各位帮忙改一下啊,谢谢啦。
...全文
相关推荐
SDK2000视频采集卡驱动
SDK2000视频采集卡驱动FOR WIN XP
AVI视频一键拆解成单帧图片的小巧Windows工具
直接打开AVI文件,按顺序把每一帧画面保存为独立图片,支持BMP、PNG等常用格式,不用装编解码器或大型视频软件。整个工具包基于Visual Studio开发,带完整工程文件(.sln)、调试目录(Debug)和可编译源码,主程序逻辑集中在getfrImg项目里。适合嵌入到其他应用中做帧提取,也方便开发者修改截图条件、跳过黑场、指定起止帧等。核心解析完全自主实现,不调用FFmpeg或其他第三方库,对老式AVI、无压缩AVI、Cinepak编码等兼容性稳定。资源包里包含示例图片(如20.JPG、3.JPG)、
C#海康视频采集卡开发包
C# 海康视频采集卡开发包 实时视频 录像 播放录像 抓图等 都做了封装
一个通过视频采集卡采集视频的实例
一个通过视频采集卡采集视频的实例,对进行视频采集相关开发很有用的
视频采集卡视频采集程序
用于摄像头视频采集,可进行预览以及图像的保存。


图形处理/算法
