视频捕获编程如何使用压缩管理器(ICM)? (200分)

  • 主题发起人 主题发起人 Ironhero
  • 开始时间 开始时间
I

Ironhero

Unregistered / Unconfirmed
GUEST, unregistred user!
Video for Windows编程支持压缩管理器(ICM),用于管理用于视频压缩-解压缩的编
解码器(CODEC),但不知如何使用?
哪位大虾有此方面的开发经验,恳请赐教一二!
 
是这么理解的吗?
 
我只知道用这几个函数,还望各位高手指点。
压缩
ICCompressbegin

ICCompress
ICCompressEnd
解压
ICDecompressbegin

ICDecompress
ICDecompressEnd
 
一个枚举压缩方法
bool __fastcall TVideoCompressorClass::EnumVideoCompressor()
{
DWORD fccWalk = ICTYPE_VIDEO;
ICINFO icInfo;

VideoICINFOList->Clear();
for (int i=0;
ICInfo(fccWalk, i, &icInfo);
i++)
{
HIC hic = ICOpen(icInfo.fccType, icInfo.fccHandler, ICMODE_QUERY);
if (hic)
{
ICGetInfo(hic, &icInfo, sizeof(icInfo));
ICClose(hic);
ICINFO* tmpICINFO = new ICINFO;
memcpy(tmpICINFO, &icInfo, sizeof(ICINFO));
VideoICINFOList->Add(tmpICINFO);
}
}
return true;
 
谢谢comfan2001,能不能再提供思路说明压缩与解压缩。
 
to comfan2001:
可以把这段程序改成DELPHI版吗?我没学过C++,请提示!
 
to comfan2001:
我已经可以得到列表,但如何选取该压缩CODE,并捕获视频起作用,还知道怎么做。请教高手。
 
我想了解
 
[8D]

直接用名字指定压缩方法:
VidCap1.Compressor = "h263"

http://www.banasoft.net/AVPhone.htm
 
没有videocap1.compressor 这个方法
 
comfan2001 已经将压缩算法的hic放入列表,现在就可以使用你ICCompressbegin
ICCompress
ICCompressEnd 解压 ICDecompressbegin
ICDecompress ICDecompressEnd 等等函数进行压缩
和解压缩了,注意要使用 已经列出的hic(取出列表中的hic作为函数参数)即可
 
关注
QQ:6903836
 
怎么实现实时视频捕捉和压缩 和解压缩播放?
哪位高手能指点一下,可以给予相应的报酬。
 
一 压缩
(1) 开始压缩前的准备
if (CompressHic==NULL)
{
memset(&compVars, 0, sizeof(COMPVARS));
compVars.cbSize = sizeof(COMPVARS);
//准备好于压缩数据的输入格式
bpiCompressIn.bmiHeader.biWidth = ImageWidth;
bpiCompressIn.bmiHeader.biHeight = ImageHeight;
bpiCompressIn.bmiHeader.biPlanes = 1;
bpiCompressIn.bmiHeader.biBitCount = ColorBits;
bpiCompressIn.bmiHeader.biCompression = BI_RGB;
bpiCompressIn.bmiHeader.biSizeImage = 0;
bpiCompressIn.bmiHeader.biXPelsPerMeter = 0;
bpiCompressIn.bmiHeader.biYPelsPerMeter = 0;
bpiCompressIn.bmiHeader.biClrUsed = 0;
bpiCompressIn.bmiHeader.biClrImportant = 0;
//准备好于压缩数据的输出格式
bpiCompressOut.bmiHeader.biWidth = ImageWidth;
bpiCompressOut.bmiHeader.biHeight = ImageHeight;
bpiCompressOut.bmiHeader.biPlanes = 1;
bpiCompressOut.bmiHeader.biBitCount = ColorBits;
bpiCompressOut.bmiHeader.biCompression = BI_RGB;
bpiCompressOut.bmiHeader.biSizeImage = 0;
bpiCompressOut.bmiHeader.biXPelsPerMeter = 0;
bpiCompressOut.bmiHeader.biYPelsPerMeter = 0;
bpiCompressOut.bmiHeader.biClrUsed = 0;
bpiCompressOut.bmiHeader.biClrImportant = 0;
//选择一个压缩算法
if (!ICCompressorChoose(FormMain->Handle, ICMF_CHOOSE_ALLCOMPRESSORS, NULL, NULL, &compVars, "Select a compressor"))
{

return;
}
else

{
CompressHic = compVars.hic;

bpiCompressOut.bmiHeader.biCompression = compVars.fccHandler;
//确定上面指定的输入输出格式是否被支持
if (ICCompressQuery(CompressHic, &bpiCompressIn, &bpiCompressOut)!=ICERR_OK)
{
//确定输入格式是否被支持,忽略输出格式的指定
if (ICCompressQuery(CompressHic, &bpiCompressIn, NULL)!=ICERR_OK)
{

ICCompressorFree(&compVars);
//if (ICClose(CompressHic)!=ICERR_OK) //不需要
//;
CompressHic = NULL;
return;
}
else

{
//若输入格式被支持,取得默认的输出格式
DWORD dwFormatSize = 0;
dwFormatSize = ICCompressGetFormatSize(CompressHic, &bpiCompressIn);
if (dwFormatSize==0xffffffff || dwFormatSize==0)
{
ICCompressorFree(&compVars);
if (ICClose(CompressHic)!=ICERR_OK) //估计也是不需要
;
return;
}
HANDLE h = GlobalAlloc(GHND, dwFormatSize);
BITMAPINFO *tmpBmi = (LPBITMAPINFO)GlobalLock(h);
if (ICCompressGetFormat(CompressHic, &bpiCompressIn, tmpBmi)!=ICERR_OK)
{
GlobalFree(tmpBmi);

ICCompressorFree(&compVars);
if (ICClose(CompressHic)!=ICERR_OK) //估计也是不需要
;
return;
}
memcpy(&bpiCompressOut, tmpBmi, dwFormatSize>sizeof(BITMAPINFOHEADER)?sizeof(BITMAPINFOHEADER):dwFormatSize);
GlobalFree(tmpBmi);
}
}
//准备开始
if (!ICSeqCompressFrameStart(&compVars, &bpiCompressIn))
{

ICCompressorFree(&compVars);
if (ICClose(CompressHic)!=ICERR_OK) //估计也是不需要
;
return;
}
}
}
(2). 停止压缩
ICSeqCompressFrameEnd(&compVars);
ICCompressorFree(&compVars);
CompressHic = NULL;
(3). 每次压缩一系列影像数据前只需执行一次步骤(1), 然后针对每个影像执行下面的操作.
想结束压缩时执行一次步骤(2)
static DWord FrameID = 0, tmpDWord;
memcpy(CompressDataBufferIn,..., size)//取得影像数据
//下面参数的含义可参看VFW的帮助.需要指出,输出buffer由函数自动分配内存,其它的buffer得自己预先分配好内存
if (ICCompress(CompressHic, 0, &bpiCompressOut.bmiHeader, CompressDataBufferOut,
&bpiCompressIn.bmiHeader, CompressDataBufferIn,
NULL, &tmpDWord, FrameID, 0, SuggestedQuality,
&bpiCompressIn.bmiHeader, CompressDataBufferInPrev)!=ICERR_OK)
{
//Error
return;
}
FrameID++;
size = ThisPtr->bpiCompressOut.bmiHeader.biSizeImage;//取得压缩后的数据大小

二 解压缩
(1) 开始前的准备
//根据原始影像数据定义解压缩的输入格式
bpiDecompressIn.bmiHeader.biWidth = ImageWidth;
bpiDecompressIn.bmiHeader.biHeight = ImageHeight;
bpiDecompressIn.bmiHeader.biPlanes = 1;
bpiDecompressIn.bmiHeader.biBitCount = ColorBits;
bpiDecompressIn.bmiHeader.biCompression = compVars.fccHandler;
bpiDecompressIn.bmiHeader.biSizeImage = 0;
bpiDecompressIn.bmiHeader.biXPelsPerMeter = 0;
bpiDecompressIn.bmiHeader.biYPelsPerMeter = 0;
bpiDecompressIn.bmiHeader.biClrUsed = 0;
bpiDecompressIn.bmiHeader.biClrImportant = 0;

bpiDecompressOut.bmiHeader.biWidth = ImageWidth;
bpiDecompressOut.bmiHeader.biHeight = ImageHeight;
bpiDecompressOut.bmiHeader.biPlanes = 1;
bpiDecompressOut.bmiHeader.biBitCount = ColorBits;
bpiDecompressOut.bmiHeader.biCompression = BI_RGB;
bpiDecompressOut.bmiHeader.biSizeImage = 0;//ImageWidth*ImageHeight*(int)((ColorBits+1)/8);
bpiDecompressOut.bmiHeader.biXPelsPerMeter = 0;
bpiDecompressOut.bmiHeader.biYPelsPerMeter = 0;
bpiDecompressOut.bmiHeader.biClrUsed = 0;
bpiDecompressOut.bmiHeader.biClrImportant = 0;
//按照指定的数据格式打开解压算法
DecompressHic = ICDecompressOpen(ICTYPE_VIDEO, compVars.fccHandler, &(bpiDecompressIn.bmiHeader), &(bpiDecompressOut.bmiHeader));
if (DecompressHic==NULL)
{
//
DecompressHic = ICDecompressOpen(ICTYPE_VIDEO, compVars.fccHandler, &(bpiDecompressIn.bmiHeader), NULL);
if (DecompressHic==NULL)
{
//不支持输入数据格式,无法解压缩
return;
}
else

{
//取得默认的输出数据格式
DWORD dwFormatSize = 0;
dwFormatSize = ICDecompressGetFormatSize(DecompressHic, &bpiDecompressIn);
if (dwFormatSize==0xffffffff || dwFormatSize==0)
{
if (ICClose(DecompressHic)!=ICERR_OK)
;
return;
}
HANDLE h = GlobalAlloc(GHND, dwFormatSize);
BITMAPINFO *tmpBmi = (LPBITMAPINFO)GlobalLock(h);
if (ICDecompressGetFormat(DecompressHic, &bpiDecompressIn, tmpBmi)!=ICERR_OK)
{
if (ICClose(DecompressHic)!=ICERR_OK)
;
GlobalFree(tmpBmi);
return;
}
memcpy(&bpiDecompressOut, tmpBmi, dwFormatSize>sizeof(BITMAPINFOHEADER)?sizeof(BITMAPINFOHEADER):dwFormatSize);
GlobalFree(tmpBmi);
}
}
//开始
if (ICDecompressbegin
(DecompressHic, &bpiDecompressIn, &bpiDecompressOut)!=ICERR_OK)
{
if (ICClose(DecompressHic)!=ICERR_OK)
;
return;
}
}
(2) 结束解压缩
if (ICDecompressEnd(DecompressHic)==ICERR_OK)
{
if (ICClose(DecompressHic)!=ICERR_OK)
;
DecompressHic = NULL;
}
(3) 和压缩数据类似, 开始前执行一次步骤(1), 准备好解压缩算法, 然后针对每一个需要解压的影像数据
执行下面的操作.结束解压缩时执行步骤(2)
bpiDecompressIn.bmiHeader.biSizeImage = size;
//解压缩并显示. 请预先分配好需要的buffer
if (ICDecompress(DecompressHic, 0, &(bpiDecompressIn.bmiHeader), CompressDataBufferOut,
&bpiDecompressOut.bmiHeader, DecompressDataBufferOut)==ICERR_OK)
{

//显示解压缩影像或作其它处理
HDC hDC = GetDC(PanelDecomDisplay->Handle);
if (StretchDIBits(hDC, 0, 0, PanelDecomDisplay->Width ,PanelDecomDisplay->Height,
0, 0, width, height,DecompressDataBufferOut, &(bpiDecompressOut) ,
DIB_RGB_COLORS, SRCCOPY)==GDI_ERROR)
;//error
ReleaseDC(PanelDecomDisplay->Handle,hDC);
}

上面的代码片断是经过实际运行通过的, 很抱歉不能给出全部代码. 祝好运!
欢迎有经验的朋友跟我联系, 大家共同提高.
wolf-lee@163.com



 
多人接受答案了。
 
Video for Windows编程支持压缩管理器(ICM),用于管理用于视频压缩-解压缩的编
解码器(CODEC),但不知如何使用?
我想对视频流进行压缩和解压缩,请问如何实现 最好有源码
 
后退
顶部