请问怎样实现摄像头视频压缩(usb),例如将avi转为mepg4,有相应源码么?(100分)

  • 主题发起人 主题发起人 david_fwj
  • 开始时间 开始时间
D

david_fwj

Unregistered / Unconfirmed
GUEST, unregistred user!
最近在研究这个,我是个新手,各位大侠帮帮忙
 
我是压缩帧图后发送。收后再合成
 
有demo么?
 
我也要,劳驾
yaoluntao@163.com
 
我也想要wuchunhua81@yahoo.com.cn 谢谢!
 
楼主,这类东西没有源码的,C++的在网上比较多,自己下下来,自己改成DELPHI就可以了
 
谢谢楼上
如果用dspack(directshow)能否实现在视频窗口中叠加文字或图片,比如大头贴的效果,可以在图片框中看到里面的视频(图片框在视频上面):
 
to网中戏
你是通过控件实现的么?还是vfm?
 
有一个,QQ 87797301
 
偶也想要一份啊,3Q
 
不好意思,偶的mail:zhengsq@gmail.com
 
怎么没个建设性的回答呢?高手门速度啊,Email:david_fwj@126.com
有demo的请发个,谢谢,收到就给分了。
 
http://www.ysza.com 原创作品里有,n年前得了
------------------------------------
http://gezi.sms1001.com 千里挑一百万格子
http://www.haha77.com 成人笑话
http://www.dudu66.com 美图天下
http://www.sms1001.com 免费影视中心
 
话题116436的标题是: 想知道视频铺捉、实时压缩的技术细节。 (200分)
分类:多媒体 dyb (1999-06-21 11:17:00)
想做个简易IP可视电话,VC中微软相关SDK资料太简洁,特别缺乏例子
说明,谁能给个详细说明、程序范例,或能找到相关资料、范例的INTERNET
地址?

kucio (2000-01-18 18:01:00)
哎,竟然没有一个大富翁会这个问题,太可悲了.

cAkk (2000-01-18 21:36:00)
有啥可悲的? 知耻而后勇嘛! 您老就给大家启蒙一下吧!

Wilbur (2000-01-20 0:48:00)
如果你不介意使用 Netmeeting 的话请参考 NetMeeting SDK。


jxl (2000-02-13 15:19:00)
为何不用视频捕足卡+压缩卡???

g622 (2000-02-13 16:32:00)
我也想知道

g622 (2000-02-22 20:22:00)
在www.vclxx.com上发现有相关的控件,你可以自己找一找

ry (2000-02-23 10:47:00)
我来说说吧!
首先,你所谓的简单的ip可视电话,简单到什么程度?
通常,一个可视电话涉及软件和硬件两个方面.
硬件方面:
需要视频采集卡,摄像头,音频采集卡和话筒,耳机.
视频采集卡和摄像头可以用一个USB的摄像头代替,
音频采集卡一般用声卡就可以了.
软件方面:
需要考虑协议,当然如果是自己作着玩,用比较简单
的协议就可以了.具体可以参考h.324,h.323和h.320.
主要考虑视频压缩/解压缩,音频压缩/解压缩,音频视频复用,
复用后数据打包.通常视频压缩采用h.263,音频不是太清楚,
我们用的是g.723.1,复用是h.245和h.232(记不太清楚了).
h.263的源代码网上有,其他就得自己编或者购买.
大体上就是这个样子了!


ghg_qh (2000-02-28 13:47:00)
want konw more

阿蒙 (2000-02-28 20:00:00)
listen

sahee (2000-04-19 14:20:00)
这个好像不是很容易哦!

程云 (2000-07-17 15:13:00)
你真想要,我给你点。

视频捕获笔记

目 录
一. 视频捕获快速入门 2
二.基本的捕获设置 3
1.设置捕获速度: 3
2.设置终止捕获 4
3.捕获的时间限制 4
三.关于捕获窗口 4
1.创建一个AVICAP捕获窗口 5
2.将一个捕获窗口连接至捕获设备 5
3. 父窗口与子窗口的交互 5
4.捕获窗口的状态 6
四.视频捕获驱动和音频驱动 6
1.视频捕获驱动的性能: 6
2.视频对话框: 6
3.PREVIEW 和 OVERLAY模式: 7
4.视频格式 7
5.视频捕获设置 7
6.声频格式 8
五.使用视频捕获 8
1.创建捕获窗口(CREATING A CAPTURE WINDOW) 8
2.连接到捕获驱动(CONNECTING TO A CAPTURE DRIVER) 9
3.列举所有已安装的捕获驱动(ENUMERATING INSTALLED CAPTURE DRIVERS) 9
4.得到捕获驱动的性能(OBTAINING THE CAPABILITIES OF A CAPTURE DRIVER) 9
5.得到捕获窗口的状态(OBTAINING THE STATUS OF A CAPTURE WINDOW) 10
6.显示对话框设置视频特征(DISPLAYING DIALOG BOXES TO SET VIDEO CHARACTERISTICS) 10
7.得到和设置视频格式(OBTAINING AND SETTING THE VIDEO FORMAT) 11
8. 预览视频(PREVIEWING VIDEO) 12
9.将视频设置为OVERLAY模式(ENABLING VIDEO OVERLAY) 12
10.命名捕获文件(NAMING THE CAPTURE FILE) 12
11.格式化声频捕获(FORMATTING AUDIO CAPTURE) 12
12.改变视频捕获设置(CHANGING A VIDEO CAPTURE SETTING) 13
13.捕获数据(CAPTURING DATA) 13
14.增加一个信息块(ADDING AN INFORMATION CHUNK) 14
15.在程序中加入一个回调函数(ADDING CALLBACK FUNCTIONS TO AN APPLICATION) 14
16.创建一个状态回调函数(CREATING A STATUS CALLBACK FUNCTION) 16
17.创建一个错误回调函数( CREATING AN ERROR CALLBACK FUNCTION) 17
18.创建一个框架回调函数(CREATING A FRAME CALLBACK FUNCTION) 18
六.将四个标准对话框改成函数调用形式 18
AUDIOFORMAT对话框 19
VIDEOFORMAT对话框 19
VIDEOSOURCE对话框 20
VIDEO COMPRESSION对话框 20


前 言
视频捕获是指由专用的视频采集卡捕获声频和视频信息,然后将其进行数据化处理,再经过软件的压缩进行处理,这时就可对这些数据进行保存、回放、传输等各种操作。
Windows专门提供了Video for Windows来对视频处理进行支持,提供的接口可以被大多数的视频采集卡支持,并有多种视频压缩驱动供选择(当然视频压缩可以自己开发),采集卡支持摄像头,TV等多种输入。

一. 视频捕获快速入门
视频捕捉将一个视频流和音频流数字化, 然后存储在硬盘或其他存储介质上.
一个AVICap视窗口句柄描述了声频与视频流的细节, 这样就使你的应用程序从AVI文件格式, 声频视频缓冲管理, 低层声频视频驱动访问等等解脱出来, AVICap为应用程序提供了一个灵活的介面, 你可以仅仅使用如下几行代码就可以将视频捕捉加入你的程序:
hWndC = capCreateCaptureWindow ( "My Own Capture Window",
WS_CHILD | WS_VISIBLE , 0, 0, 160, 120, hwndParent, nID);
SendMessage (hWndC, WM_CAP_DRIVER_CONNECT, 0 /* wIndex */, 0L);
SendMessage (hWndC, WM_CAP_SEQUENCE, 0, 0L);
一个宏其实也是使用SendMessage, 只不过提供给程序一个更易读的代码而已, 下面的这些示例就是使用宏的方法将视频捕捉加入程序:
hWndC = capCreateCaptureWindow ( "My Own Capture Window",
WS_CHILD | WS_VISIBLE , 0, 0, 160, 120, hwndParent, nID);
capDriverConnect (hWndC, 0);
capCaptureSequence (hWndC);


当你创建了一个AVICap类的捕捉窗口并将它连接到一个视频驱动时, 此捕捉窗口即可以开始捕捉数据,你的程序可以简单的发送WM_CAP_SEQUENCE 消息(或者使用capCaptureSequence 宏)来开始捕捉.
如果是缺省的设置, WM_CAP_SEQUENCE会开始捕捉视频音频流到CAPTURE.AVI文件中, 直到下面的某一事件发生为止:
用户按下了ESC键或者一个鼠标键
你的应用程序终止或异常中断捕捉操作
磁盘已满

在一个应用程序里, 你可以发送WM_CAP_STOP消息来终止捕捉数据(或者使用capCaptureStop宏), 你也可以发送WM_CAP_ABORT消息(或者使用capCaptureAbort宏)来终止.

二.基本的捕获设置
基本的捕获设置包括:设置捕获速度(每秒捕获多少帧),是否同时捕获声频,捕获缓冲,允许最大丢失多少帧,是否使用DOS内存,以及用键盘的哪个键或鼠标的哪个键来终止捕获等等。这些基本的设置都可以使用CAPTUREPARAMS结构来描述,你可以使用capCaptureGetSetup宏来得到当前的设置,然后改变此结构的成员变量,再使用capCaptureSetSetup宏设置新的设置。
例如:
1.设置捕获速度:
捕捉速度是指捕捉任务每秒钟捕获的帧数, 你可以发送WM_CAP_GET_SEQUENCE_SETUP消息(或者使用capCaptureGetSetup宏)来得到当前的捕捉速度, 当前的捕捉速度保存在CAPTUREPARAMS结构的dwRequestMicroSecPerFrame成员变量中, 你可以通过设置此变量来改变当前设置, 单位是每毫秒连续的帧数, 你可以发送WM_CAP_SET_SEQUENCE_SETUP消息(或者使用capCaptureSetSetup宏), dwRequestMicroSecPerFrame的值是66667, 相当于每秒15帧.

2.设置终止捕获
你可以允许用户按下某键或某组合键或者鼠标的左右键来终止一个捕获任务, 如果是实时的捕获, 则捕获的文件将会被丢弃;
如果是单步捕获, 在终止之前所捕获的内容将会被保存.
你可以通过发送WM_CAP_GETQUENCE_SETUP消息(或者使用capCaptureGetSetup宏)来得到当前的设置, 当前的按键设置保存在CAPTUREPARAMS的vKeyAbort成员中, 当前的鼠标设置保存在fAbortLeftMouse和fAbortRightMouse成员中. 你可以设置新的按键或按键组合, 或者鼠标左右键, 当你修改的CAPTUREPARAMS后,应该发送WM_CAP_SET_SEQUENCE_SETUP消息来进行更新(或者使用capCaptureSetSetup宏). 缺省的按键是VK_ESCAPE. 你必须在指定按键之前使用RegisterHotKey函数, 鼠标缺省的值是fAbortLeftMouse和fAbortRightMouse都为TRUE.

3.捕获的时间限制
CAPTUREPARAMS结构中的fLimitEnabled指示是否有时间限度, wTimeLimit指示最大的持续时间, 单位为秒.
得到fLimitEnabled和wTimeLimit的值可以发送WM_CAP_GET_SEQUENCE_SETUP消息(或使用capCatureGetSetup宏), 当设置了这些成员变量后, 应该发送消息WM_CAP_SET_SEQUENCE_SETUP消息(或capCaptureSetSetup宏)来更新CAPTUREPARAMS结构.

三.关于捕获窗口
在捕获之前必须创建一个捕获窗口(capture window),在发送消息或使用宏的过程中都需要使用此窗口。
1.创建一个AVICap捕获窗口
你可以使用capCreateCaptureWindow函数来创建一个AVICap捕获窗口, 此函数将会返回一个句柄, 此句柄以后在发送消息时要用.
你可以在一个程序里创建一个或多个捕获窗口, 然后给每一个窗口连接不同的捕获设置.

2.将一个捕获窗口连接至捕获设备
你可以动态的在一个捕获窗口与一个捕获设备之前连接或断接, 你可以发送WM_CAP_DRIVER_CONNECT消息来使一个捕获窗口与一个捕获设备连接或关联. 当连接上以后, 你就可以通过捕获窗口向捕获设备发送各种消息.
如果你的系统里装有多个捕获设备, 你可以在发送WM_CAP_DRIVER_CONNECT消息时用wParam参数指定使用哪一个, 此参数是登记在SYSTEM.INI文件的[drivers]一节里的列表中的某一项, 0为第一个.
你可以使用capGetDriverDescription函数来得到已安装的捕获设备的名称及版本, 这样你的程序就可以列举所有已安装的捕获设备和驱动, 这样用户就可以选择其中的一个来与你的捕获窗口连接.
你可以发送WM_CAP_DRIVER_GET_NAME消息(或capDriverGetName宏)来得到连接到捕获窗口的捕获设备的名称, 得到版本发送WM_CAP_DRIVER_GET_VERSION消息(或capDriverGetVersion宏)
你可以发送WM_CAP_DRIVER_DISCONNECT消息(或capDriverDisconnect宏)来断接.

3. 父窗口与子窗口的交互
一些象WM_PALETTECHANGED和WM_QUERYNEWPALETTE的系统级消息只能发送到顶级窗口或OVERLAPPED窗口, 如果一个捕获窗口是子窗口,就必须通过父窗口转送.
同样的, 如果父窗口的尺寸改变了, 它就需要通知捕获窗口, 相反地, 如果捕获窗口的尺寸改变了, 捕获窗口就需要发送消息给父窗口, 一个简单的方法就是始终保持捕获窗口的尺寸与视频流的尺寸一致, 并随时将尺寸的改变通知父窗口.

4.捕获窗口的状态
你可以发送WM_CAP_GET_STATUS消息(或capGetStatus宏)来得到当前捕获窗口的状态, 得到的是一个CAPSTATUS结构的拷贝, 它包含图片的尺寸, 卷轴的当前位置, overlay和preview是否已设置.
因为CAPSTATUS信息是动态的, 你的程序应该只要捕获的视频流的尺寸或格式可能发生了改变就应该进行刷新(例如: 显示了捕获设备的视频格式以后).
改变捕获窗口的尺寸并不影响实际的捕获的视频流的尺寸, 视频捕获设备的格式对话框捕获频流的尺寸.

四.视频捕获驱动和音频驱动
1.视频捕获驱动的性能:
你可以通过发送WM_CAP_DRIVER_GET_CAPS消息(或者capDriverGetCaps宏)来得到当前连接的视频驱动的硬件性能. 得到的信息保存在CAPDRIVERCAPS结构中.

2.视频对话框:
每一个视频驱动能够提供四个对话框来控制视频捕获和数字化处理, 定义压缩品质等, 这些对话框都定义在视频捕获驱动中.
Video Source对话框用于控制选择视频来源, 此对话框列举了此视频捕获卡连接的所有视频源(典型的例如:SVHS和合成输入), 并提供了改变色调, 对比度, 饱和度. 如果视频驱动支持此对话框, 你就可以显示并更新它, 使用WM_CAP_DLG_VIDEOSOURCE消息(或capDlgVideoSource宏).
Video Format对话框定义视频帧的尺寸以及精度, 视频捕获卡的压缩设置. 如果卡支持的话, 可以发送消息WM_CAP_DLG_VIDEOFORMAT消息或(capDlgVideoFormat宏).
Video Display对话框控制在视频捕获期间在显示器上的显示, 此控制不会影响视频数字数据, 但是他们可能会影响数字信号的表现形式, 例如: 如果捕获设备支持overlay, 可能允许改变色调和饱和度, 关键色彩 或者overlay队列. 如果卡支持, 你可以发送WM_CAP_DLG_VIDEODISPLAY消息(或者使用capDlgVideoDisplay宏).
Video Compression对话框控制压缩品质, 如果卡支持, 发送消息WM_CAP_DLG_VIDEOCOMPRESSION(或capDlgVideoCompression宏).

3.Preview 和 Overlay模式:
一个视频捕获驱动对进入的视频流有两种工作模式: Preview模式和overlay模式, 如果一个捕获驱动能够执行两种方法, 用户可以在其中选择一种.
Preview模式把从捕获硬件传来的数据送入系统内存并使用图形设备介面(GDI)将数字化帧显示在捕获窗口内. 应用程序可以在父窗口失去焦点时减缓显示速度, 当重新又得到焦点后加快显示速度, 此种模式要占用大量CPU时间.
有三种消息控制Preview操作:
WM_CAP_SET_PREIVEW消息(capPreview宏)允许或禁止preview模式
WM_CAP_SET_PREVIEWRATE(capPreviewRate宏)当帧在preview模式显示时设置速度.
WM_CAP_SET_SCALE(capPreviewScale宏)允许或禁止preview视频的缩放比例.
当preview和scaling同时使用, 捕获的视频帧将会根据捕获窗口的尺寸自动缩放, 允许preview模式会自动关闭overlay模式.
overlay模式是一个硬件函数它将数据送入捕获缓冲区中因而不占用CPU资源. 你可以发送消息WM_CAP_SET_OVERLAY(或capOverlay宏)给捕获窗口来启用或终止overlay模式, 允许overlay模式会自动禁止preview模式.
你同时也可以在preview模式或overlay模式里发送WM_CAP_SET_SCROLL消息(或capSetScrollPos宏)来设置视频帧的客户区卷轴位置.

4.视频格式
你可以通过发送WM_CAP_GET_VIDEOFORMAT消息(或capGetVideoFormat和capGetVideoFormatSize宏)来得到视频格式的结构或结构的尺寸. 你可以通过发送CAP_SET_VIDEOFORMAT消息(或capSetVideoFormat宏)来设置视频格式.

5.视频捕获设置
CAPTUREPARMS结构包含了对视频捕获流的控制参数, 你可以完成以下这些任务:
指定帧数
指定分配多少视频缓冲
允许或禁止声频捕获
指定捕获的时间间隔
指定在捕获的过程中是否使用MCI设置(VCR或者videodisc)
指定终止流的键盘或鼠标
specify the type of video averaging applied during capture.

得到:WM_CAP_GET_SEQUENCE_SETUP消息(或capCaptureGetSetup宏)
设置:WM_CAP_SET_SEQUENCE_SETUP消息(或capCaptureSetSetup宏)

6.声频格式
你可以通过发送WM_CAP_GET_AUDIOFORMAT消息(或capGetAudioFormat宏和capGetAudioFormatSize宏)来得到当前捕获音频数据的格式或尺寸格式。缺省的声频格式是:单声道、8位、11kHz PCM。 当你使用WM_CAP_GET_AUDIOFORMAT时,总是使用WAVEFORMATEX结构。
设置发送消息WM_CAP_SET_AUDIOFORMAT消息(或capSetAudioFormat宏),可以传送WAVEFORMAT,WAVEFORMATEX,PCMWAVEFORMAT结构指针。
五.使用视频捕获
1.创建捕获窗口(Creating a Capture Window)
hWndC = capCreateCaptureWindow (
(LPSTR) "My Capture Window", // window name if pop-up
WS_CHILD | WS_VISIBLE, // window style
0, 0, 160, 120, // window position and dimensions
(HWND) hwndParent,
(int) nID /* child ID */);


2.连接到捕获驱动(Connecting to a Capture Driver)
下面的例子是将MSVIDEO驱动连接到句柄为hWndC的捕获窗口, 然后调用capDriverDisconnect宏来断接.
fOK = SendMessage (hWndC, WM_CAP_DRIVER_CONNECT, 0, 0L);

//
// Or, use the macro to connect to the MSVIDEO driver:
// fOK = capDriverConnect(hWndC, 0);

//
// Place code to set up and capture video here.
//
capDriverDisconnect (hWndC);


3.列举所有已安装的捕获驱动(Enumerating Installed Capture Drivers)
下面的例子使用capGetDriverDescription函数得到已安装的捕获驱动的名称及版本:
char szDeviceName[80];
char szDeviceVersion[80];

for (wIndex = 0;
wIndex < 10;
wIndex++)
{
if (capGetDriverDescription (wIndex, szDeviceName,
sizeof (szDeviceName), szDeviceVersion,
sizeof (szDeviceVersion))
{
// Append name to list of installed capture drivers
// and then
let the user select a driver to use.
}
}

4.得到捕获驱动的性能(Obtaining the Capabilities of a Capture Driver)
发送WM_CAP_DRIVER_GET_CAPS消息可以得到捕获驱动的性能,并保存入一个CAPDRIVERCAPS结构.每当程序连接一个新的捕获驱动到一个捕获窗口时, 就应该更新CAPDRIVERCAPS结构. 下面的程序举例说明了如何使用capDriverGetCaps宏来得到捕获驱动的性能:

CAPDRIVERCAPS CapDrvCaps;

SendMessage (hWndC, WM_CAP_DRIVER_GET_CAPS,
sizeof (CAPDRIVERCAPS), (LONG) (LPVOID) &CapDrvCaps);

// Or, use the macro to retrieve the driver capabilities.
// capDriverGetCaps(hWndC, &CapDrvCaps, sizeof (CAPDRIVERCAPS));

5.得到捕获窗口的状态(Obtaining the Status of a Capture Window)
下面的例子使用SetWindowPos函数使捕获窗口与进来的视频流尺寸保持一致, 视频流的基本信息是使用capGetStatus宏得到的, 保存在CAPSTATUS结构中.

CAPSTATUS CapStatus;
capGetStatus(hWndC, &CapStatus, sizeof (CAPSTATUS));

SetWindowPos(hWndC, NULL, 0, 0, CapStatus.uiImageWidth,
CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE);


6.显示对话框设置视频特征(Displaying Dialog Boxes to Set Video Characteristics)
每个视频捕获卡一般能提供三个不同的对话框用于控制视频捕获及数字化处理. 下面的例子说明如何显示这些对话框, 在显示这些对话框之前,使用了capDriverGetCaps宏来检查CAPDRIVERCAPS结构, 以检测该卡是否有显示这些对话框:

CAPDRIVERCAPS CapDrvCaps;

capDriverGetCaps(hWndC, &CapDrvCaps, sizeof (CAPDRIVERCAPS));


// Video source dialog box.
if (CapDriverCaps.fHasDlgVideoSource)
capDlgVideoSource(hWndC);


// Video format dialog box.
if (CapDriverCaps.fHasDlgVideoFormat)
{
capDlgVideoFormat(hWndC);

// Are there new image dimensions?
capGetStatus(hWndC, &CapStatus, sizeof (CAPSTATUS));
// If so, notify the parent of a size change.
}

// Video display dialog box.
if (CapDriverCaps.fHasDlgVideoDisplay)
capDlgVideoDisplay(hWndC);


7.得到和设置视频格式(Obtaining and Setting the Video Format)
BITMAPINFO结构的长度既适应于标准的也适应于压缩的数据格式, 所有程序必须总是询问此结构的尺寸以便在得到当前的视频格式之前分配内存. 下面的例子就是使用capGetVideoFormatSize宏来得到缓冲区尺寸并调用capGetVideoFormat宏来得到当前的视频格式.

LPBITMAPINFO lpbi;
DWORD dwSize;
dwSize = capGetVideoFormatSize(hWndC);
lpbi = GlobalAllocPtr (GHND, dwSize);
capGetVideoFormat(hWndC, lpbi, dwSize);


// Access the video format and then
free the allocated memory.

程序可以使用capSetVideoFormat宏(或WM_CAP_SET_VIDEOFORMAT消息)发送一个BITMAPINFO头结构给捕获窗口, 因为视频格式是设备细节, 你的程序应该检查返回值以便确定此格式是否已被接受.

8. 预览视频(Previewing Video)
下面的例子使用capPreviewRate宏来设置每66毫秒显示一帧, 并使用capPreview宏将它放置在捕获窗口里.

capPreviewRate(hWndC, 66);
// rate, in milliseconds
capPreview(hWndC, TRUE);
// starts preview
// Preview
capPreview(hWnd, FALSE);
// disables preview

9.将视频设置为overlay模式(Enabling Video Overlay)
下面的例子: capDriverGetCaps宏确定此捕获卡是否有overlay功能, 如果有就使用宏来设置它

CAPDRIVERCAPS CapDrvCaps;

capDriverGetCaps(hWndC, &CapDrvCaps, sizeof (CAPDRIVERCAPS));


if (CapDrvCaps.fHasOverlay)
capOverlay(hWndC, TRUE);

10.命名捕获文件(Naming the Capture File)
下面的例子: 使用capFileSetCaptureFile宏来指定预备文件名为:MYCAP.AVI, capFileAlloc宏预先指定它的大小为5M.

char szCaptureFile[] = &quot;MYCAP.AVI&quot;;
capFileSetCaptureFile( hWndC, szCaptureFile);

capFileAlloc( hWndC, (1024L * 1024L * 5));


11.格式化声频捕获(Formatting Audio Capture)
下面的例子使用capSetAudioFormat来设置声频格式为:11kHz, PCM 8位, 立体声

WAVEFORMATEX wfex;
wfex.wFormatTag = WAVE_FORMAT_PCM;
wfex.nChannels = 2;
// Use stereo
wfex.nSamplesPerSec = 11025;
wfex.nAvgBytesPerSec = 22050;
wfex.nBlockAlign = 2;
wfex.wBitsPerSample = 8;
wfex.cbSize = 0;

capSetAudioFormat(hWndC, &wfex, sizeof(WAVEFORMATEX));


12.改变视频捕获设置(Changing a Video Capture Setting)
下面的例子使用capCaptureGetSetup和capCaptureSetSetup宏得将捕获帧数从缺省的15帧改成每秒10帧.

CAPTUREPARMS CaptureParms;
float FramesPerSec = 10.0;

capCaptureGetSetup(hWndC, &CaptureParms, sizeof(CAPTUREPARMS));

CaptureParms.dwRequestMicroSecPerFrame = (DWORD) (1.0e6 /FramesPerSec);
capCaptureSetSetup(hWndC, &CaptureParms, sizeof (CAPTUREPARMS));


13.捕获数据(Capturing Data)
下面的例子使用capCaptureSequence宏来开始捕获视频并使用capFileSaveAs宏来将捕获的数据拷贝至NEWFILE.AVI文件中.

char szNewName[] = &quot;NEWFILE.AVI&quot;;
// Set up the capture operation.
capCaptureSequence(hWndC);

// Capture.
capFileSaveAs(hWndC, szNewName);

14.增加一个信息块(Adding an Information Chunk)
如果你需要在你的程序捕获的声频和视频数据中加入你的其他信息, 你可以创建一个信息块并将它们插入捕获文件中, 信息块可以包含一些典型的信息, 例如:版权信息,视频来源, 外部定位信息等. 下面的例子使用capFileSetInfoChunk宏来插入一个信息块, 里面包含了一个SMPTE的时间代码.

// This example assumes the application controls
// the video source for preroll and postroll.
CAPINFOCHUNK cic;
// .
// .
// .
cic.fccInfoID = infotypeSMPTE_TIME;
cic.lpData = &quot;00:20:30:12&quot;;

cic.cbData = strlen (cic.lpData) + 1;
capFileSetInfoChunk (hwndC, &cic);


15.在程序中加入一个回调函数(Adding Callback Functions to an Application)
一个程序可以为捕获窗口登记一个回调函数以便在以下的这些情况下通知程序.

状态改变
错误发生
视频框架和声频缓冲区变得可用
程序应用在捕获视频流的过程中接收

下面的例子创建一个捕获窗口并登记状态,错误,视频流和框架回调函数在消息处理对列中, 也包括了一个终止回调函数的说明.

case WM_CREATE:
{
char achDeviceName[80] ;

char achDeviceVersion[100] ;

char achBuffer[100] ;

WORD wDriverCount = 0 ;

WORD wIndex ;

WORD wError ;

HMENU hMenu ;


// Create a capture window using the capCreateCaptureWindow macro.
ghWndCap = capCreateCaptureWindow((LPSTR)&quot;Capture Window&quot;,
WS_CHILD | WS_VISIBLE, 0, 0, 160, 120, (HWND) hWnd, (int) 0);


// Register the error callback function using the
// capSetCallbackOnError macro.
capSetCallbackOnError(ghWndCap, fpErrorCallback);


// Register the status callback function using the
// capSetCallbackOnStatus macro.
capSetCallbackOnStatus(ghWndCap, fpStatusCallback);


// Register the video-stream callback function using the
// capSetCallbackOnVideoStream macro.
capSetCallbackOnVideoStream(ghWndCap, fpVideoCallback);


// Register the frame callback function using the
// capSetCallbackOnFrame macro.
capSetCallbackOnFrame(ghWndCap, fpFrameCallback);


// Connect to a capture driver

break;

}
case WM_CLOSE:
{
// Use the capSetCallbackOnFrame macro to
// disable the frame callback. Similar calls exist for the other
// callback functions.

capSetCallbackOnFrame(hWndC, NULL);


break;

}

16.创建一个状态回调函数(Creating a Status Callback Function)
下面的例子是创建一个简单的状态回调函数,登记此回调函数使用capSetCallbackOnStatus宏.

// StatusCallbackProc: status callback function
// hWnd: capture window handle
// nID: status code for the current status
// lpStatusText: status text string for the current status
//
LRESULT PASCAL StatusCallbackProc(HWND hWnd, int nID,
LPSTR lpStatusText)
{
if (!ghWndMain)
return FALSE;


if (nID == 0) { // Clear old status messages.
SetWindowText(ghWndMain, (LPSTR) gachAppName);

return (LRESULT) TRUE;

}
// Show the status ID and status text...
wsprintf(gachBuffer, &quot;Status# %d: %s&quot;, nID, lpStatusText);


SetWindowText(ghWndMain, (LPSTR)gachBuffer);

return (LRESULT) TRUE;

}

17.创建一个错误回调函数( Creating an Error Callback Function)
下面的例子是创建一个简单的错误回调函数,登记此回调函数使用capsetCallbackOnError宏:

// ErrorCallbackProc: error callback function
// hWnd: capture window handle
// nErrID: error code for the encountered error
// lpErrorText: error text string for the encountered error
//
LRESULT PASCAL ErrorCallbackProc(HWND hWnd, int nErrID,
LPSTR lpErrorText)
{
if (!ghWndMain)
return FALSE;


if (nErrID == 0) // Starting a new major function.
return TRUE;
// Clear out old errors.

// Show the error identifier and text.
wsprintf(gachBuffer, &quot;Error# %d&quot;, nErrID);


MessageBox(hWnd, lpErrorText, gachBuffer,
MB_OK | MB_ICONEXCLAMATION);


return (LRESULT) TRUE;

}

18.创建一个框架回调函数(Creating a Frame Callback Function)
登记此回调函数使用capSetCallbackOnFrame宏:

// FrameCallbackProc: frame callback function
// hWnd: capture window handle
// lpVHdr: pointer to struct containing captured
// frame information
//
LRESULT PASCAL FrameCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr)
{
if (!ghWndMain)
return FALSE;


wsprintf(gachBuffer, &quot;Preview frame# %ld &quot;, gdwFrameNum++);

SetWindowText(ghWndMain, (LPSTR)gachBuffer);

return (LRESULT) TRUE ;

}



六.将四个标准对话框改成函数调用形式
系统提供了四个标准的对话框:AudioFormat, VideoFormat, VideoSource, Video Compression,但有时程序希望通过函数控制它们,而不是使用系统提供的那个单一的对话框,此时就应该使用函数调用的方法:

AudioFormat对话框
可以通过使用capSetAudioFormat来实现,此时要使用WAVEFORMATEX结构。
例如:改成PCM格式,立体声,16声道,12.05kHz,则:
WAVEFORMATEX audioFormat;
// 确定宽度
acmMetrics(NULL, ACM_METRIC_MAX_SIZE_FORMAT,&dwSize);
dwSize = max (dwSize, capGetAudioFormatSize (m_hwCapCapturing));
// 设置参数
audioFormat.wFormatTag = WAVE_FORMAT_PCM;
audioFormat.nChannels = 2;
audioFormat.nSamplesPerSec = 120500;
audioFormat.wBitsPerSample =16;
audioFormat.nBlockAlign = nBitsPerSample * nChannels / 8;
audioFormat.nAvgBytesPerSec =
audioFormat.nBlockAlign * nSamplesPerSec;
// 更新
capSetAudioFormat(ghCapWnd,&audioFormat,dwSize);
VideoFormat对话框
可以通过使用capSetVideoFormat来实现,此时要使用BITMAPINFOHEADER结构。
例如:设置图片大小为RGB24位岁,大小为230X160
BITMAPINFOHEADER bi;
DWORD dwSize,dw;
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = 320;
// 起作用
bi.biHeight = 160;
// 起作用
bi.biPlanes = 1;
bi.biBitCount = 24;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 176;
bi.biYPelsPerMeter = 144;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
dwSize = bi.biSize + ((bi.biBitCount > 8 || bi.biClrUsed) ? (bi.biClrUsed * sizeof(PALETTEENTRY)) : (2 ^ bi.biBitCount * sizeof(PALETTEENTRY)));
dw = capSetVideoFormat(m_hwCapCapturing, &bi, dwSize);
VideoSource对话框
没有找到现成的方法,但视频捕获卡提供的CD里面有一个动态链接库可以实现。
Video Compression对话框
可以通过使用ICOpen,ICInfo等函数联合起来,得到当前系统里面的视频压缩驱动的列表,并可选择其一,MSDN里面有一个程序示范了此用户,程序名叫:ICWalk。

注:此文绝大部分是我译自MSDN的资料。


黄豆 (2000-07-17 15:51:00)
啊,真不错!以前我的程序只能用显示对话框+发送回车符来实现压缩驱动的选择,现在看来不必了!
谢谢!

BrainTwist (2000-08-13 18:40:00)
向程云同志致敬!!!

hengnuo (2000-09-23 23:42:00)
也向程云同志致敬!!!


程云 (2000-09-25 8:45:00)
文章是不是长了点,
将就点好吧!
:->

zl (2000-10-04 6:35:00)
程云网友:刚拜读了您的文章,感到很是兴奋,学了很多东西.
不过还有两面三个问题:A真的没有办法使用语句来控制VideoSource了吗?我不想用对话框.
B如何实时将AVI转换成Mpeg.

请指点迷津!!!

zl (2000-10-04 6:46:00)
有没有办法实现AVI 到Mpeg 的实时转换,有一个软件WinVCR就是这样的,
它可以实时将采集的图像存为Mpeg文件(可不是用压缩卡),我试了一个速
度奇快,同压缩卡无异.我想在我的软件中也实现这样的功能,可无从下手!!

xiecy (2000-10-04 13:34:00)


wjiachun (2000-11-10 21:49:00)
接受答案了.

DelphiMen (2002-01-28 8:46:00)
各位请回答一下http://www.delphibbs.com/delphibbs/dispq.asp?lid=888408
好吗?

soglad_2001 (2002-05-18 14:06:00)
拜读了各位的发言,收益非浅
期望还有更多高手参与讨论。


lxq10000 (2002-05-21 11:10:00)
用Delphi编写视频捕捉程序:
首先,在窗体中放入TMediaPlayer,TMainMenu,TOpendialog,TPaintBox,TButton组件,并调整好位置。
唉,懒得详细介绍了,自己看代码吧!(其中视频播放位置在rect(200,0,400,200),视频捕捉位置在rect(0,0,200,200))
整个程序的源代码如下:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, MPlayer, Menus;

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
file1: TMenuItem;
open1: TMenuItem;
exit1: TMenuItem;
OpenDialog1: TOpenDialog;
MediaPlayer1: TMediaPlayer;
PaintBox1: TPaintBox;
Button1: TButton;
procedure open1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure PaintBox1Click(Sender: TObject);
private
imgbitmap: Tbitmap;
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;
implementation

{$R *.dfm}

procedure TForm1.open1Click(Sender: TObject);
begin

if opendialog1.Execute then

begin

mediaplayer1.FileName:=opendialog1.FileName;
mediaplayer1.Open;
mediaplayer1.Display:=form1;
mediaplayer1.DisplayRect:=rect(200,0,400,200);
end;

end;


procedure TForm1.Button1Click(Sender: TObject);
begin

imgbitmap.Canvas.CopyRect(rect(0,0,200,200),form1.canvas,rect(200,0,400,200));
paintbox1.Invalidate;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin

imgbitmap:=tbitmap.Create;
imgbitmap.Height:=200;
imgbitmap.Width:=200;
imgbitmap.Canvas.Rectangle(0,0,200,200);
imgbitmap.SaveToFile('img.bmp');
end;


procedure TForm1.FormPaint(Sender: TObject);
begin

canvas.FrameRect(rect(0,0,200,200));
end;


procedure TForm1.PaintBox1Click(Sender: TObject);
begin

paintbox1.Canvas.CopyRect(rect(0,0,200,200),imgbitmap.Canvas,rect(0,0,200,200));
end;


end.



程云的回答最终被接受。
 
话题166731的标题是: 用delphi完成摄像头的图像捕捉(讲讲原理也可) (100分)
分类:多媒体 yaoydong (1999-12-09 20:10:00)
如题,本人近期要完成一个项目,其中有一个功能就是需要捕捉摄像头的图像
各位大虾指点一二

cAkk (1999-12-09 20:24:00)
好像以前有过类似问题....肯定有.

Hexi (1999-12-09 20:27:00)
可以用Avicap32.dll,Windows自带的Dll,在深度历险中可以找到一个控件,
其中带了VFW.Pas文件,包含了所有avicap32.dll的声明,或在VC中找
VFW.H,将其翻译成Pas就可以用了。VC中有一个例子captest就是实现此功能的。(视
频捕捉,需要视霸卡)将扑捉的图象存为AVI文件。


Hexi (1999-12-09 20:30:00)
还提供了回调(callback)功能,在每捕获一帧后可以自己处理数据。

yaoyao (1999-12-09 21:23:00)
有一个控件前两天刚用过,效果很好,
如果要的话让我找找可以把源程序都给你.

天外客 (1999-12-09 21:28:00)
r

yh (1999-12-09 22:36:00)
to yaoyao,能否给我一份找过但没找到。
yhnew@163.net

CJ (1999-12-09 23:00:00)
`

yaoydong (1999-12-10 11:36:00)
yaoyao(都以为是自己的名字了)呵呵,
能否把那个发给我,谢了

yaoydong (1999-12-11 19:04:00)
现在我用的是D5,发现那个AVICAP21因为.DCR的问题装不起来,不知道各位有没有在
D5下装过.

BTW;其实我要完成的功能就是从摄像头取得图像在屏幕显示,然后按下某键把当前图像存下来.各位给给意见吧.

Hexi (1999-12-12 13:24:00)
有一个带源码的控件,你到历险中找找吧。
你可以参考vc中的例子直接调用API.

Hexi (1999-12-12 13:26:00)
我这有源代码,如果要我发给你。

CJ (1999-12-12 14:52:00)
hexi: please mailto:cjcjc@online.sh.cn

yaoydong (1999-12-13 9:10:00)
to Hexi:
把那个控件发过来吧,<a href=&quot;mailto:b964711@njupt.edu.cn&quot;>这里</a>

cAkk (1999-12-13 10:16:00)
我也有一个,不过没测试过:
<h2>Source for Video Capture</h2>
<p>
</b><pre>unit vidcap;

interface

type
capturerec = record
dwRequestMicroSecPerFrame: longint;
fMakeUserHitOKToCapture: wordbool;
wPercentDropForError: word;
fYield: wordbool;
dwIndexSize: longint;
wChunkGranularity: word;
fUsingDOSMemory: wordbool;
wNumVideoRequested: word;
fCaptureAudio: wordbool;
wNumAudioRequested: word;
vKeyAbort: word;
fAbortLeftMouse: wordbool;
fAbortRightMouse: wordbool;
fLimitEnabled: wordbool;
wTimeLimit: word;
fMCIControl: wordbool;
fStepMCIDevice: wordbool;
dwMCIStartTime: longint;
dwMCIStopTime: longint;
fStepCaptureAt2x: wordbool;
wStepCaptureAverageFrames: word;
dwAudioBufferSize: longint;
fDisableWriteCache: wordbool;
AVStreamMaster: word;
end;



procedure InitVariables;
function CreateVideo: integer;
procedure CreateCapWin;
procedure ShowCapWin;
procedure HideCapWin;
procedure KillCapWin;
procedure ShowVideoParamsWindow;
procedure ShowCompressionWindow;
procedure UserMessage(msg: string);
function StreamCallback(wnd: THandle;
vh: longint): wordbool;
export;

var
framespersec,
framecount,
framestopcount: integer;
videofilename: string;
cparams,
captureparams: capturerec;

implementation

{
this prototype needs to be listed to access the AVICAP function
}
function capCreateCaptureWindow(var lpszWindowName;
dwStyle: longint;
x: integer;
y: integer;

nWidth: integer;
nHeight: integer;
anhwnd: THandle;
nID: integer): THandle;
far;
external 'avicap';

procedure InitVariables;
begin

{ This is used by the callback to auto-stop after the given
number of frames have been captured. }

framestopcount := 0;

{ AVICAP will default to creating the file CAPTURE.AVI in the
root directory of the drive the program is called from. This
variable can store a path/name so that you have some better
control over where it gets captured to. }

videofilename := 'c:/mydir/testcap.avi';

{ The frame capture rate is dependant on many conditions. These
are addressed in the article. For now, we'll set it to MAX. }

framespersec := 30;

end;


procedure CreateVideo;
begin

InitVariables;
CreateCapWin;
{ Delete any capture file if it exists }
if(FileExists(videofilename)) then

DeleteFile(videofilename);
{ There are no frames captured yet }
framecount := 0;

{ Tell AVICAP to begin
capturing }
smreturn := SendMessage(hWndC, WM_USER + 62, 0, 0);

KillCapWin;
end;


{
Callback from AVICAP.DLL... every frame that gets captured
generates a function call from AVICAP. In this case we are
using it strictly to count the number of captured frames.
This callback gets initialized by CreateCapWin().
}
function StreamCallback(wnd: THandle;
vh: longint): wordbool;
begin

if(framestopcount > 0) then
begin

inc(framecount);
{ note the frame number }
if(framecount > framestopcount ) then

{ Tell AVICAP to abort the operation. }
SendMessage(hWndC, WM_USER + 69, 0, 0);

end;

{ Reassure AVICAP that all is OK. }
result := wordbool(1);

end;


{
This procedure creates the capture window and initializes
all of the capture parameters.
}

procedure CreateCapWin;
var
capavi: array[0..40] of char;
captit: array[0..40] of char;
smreturn: longint;
apntr: pointer;
asize: integer;
begin

{
STEP 1: INIT THE CAPTURE WINDOW AND GET CONNECTED TO
THE DRIVER
}
strpcopy(capavi, videofilename);
{ captured video file name }
strpcopy(captit, 'capture win');
{ capture window }
(*
SEE THE ARTICLE TEXT ABOUT THE FOLLOWING WINDOW CREATION ROUTINE
*)
hWndC := capCreateCaptureWindow ( captit, WS_CHILD or WS_VISIBLE, 0, 0,
320, 240, main.handle, 0);
ShowWindow(hWndC, SW_SHOW);
{ Tell AVICAP to connect to the Capture driver. }
smreturn := SendMessage(hWndC, WM_USER + 10, 0, 0);


if(smreturn <> 0) then
begin

usermessage( 'Connected' );
{ feedback }
{ tell AVICAP what the name of the file to capture to is }
apntr := addr(capavi);
SendMessage(hWndC, WM_USER + 20, 0, longint(apntr));

{ STEP 2: SET IMAGE PREVIEW UP }
{ Set preview rate at 30 frames per second, in mSec.
1000 mSec/30 frames = 33 mSec. }
SendMessage(hWndC, WM_USER + 52, 33, 0);

{ Now go ahead and preview }
SendMessage(hWndC, WM_USER + 50, 1, 0);


{ STEP 3: INITIALIZE CAPTURE PARAMETERS }
{ First, the capture parameters structure gets initialized
by asking AVICAP to fill it in for us. }
apntr := addr(captureparams);
asize := sizeof(captureparams);
SendMessage(hWndC, WM_USER + 65, asize, longint(apntr));

{ then
start setting up the preferences: }
{ 1 = capture audio, 0 = disable }
captureparams.fCaptureAudio := wordbool(0);


(*
The time limit params are used to force a stop of the
video capture at a specified time, just in case
anything goes wrong. The params here are filled out
to stop capture automatically after 15 seconds just
for the sake of illustration.
*)

{ 1 = enable time limiting, 0 = disable }
captureparams.fLimitEnabled := wordbool(1);

{ In this case, 15 seconds of video, translated to hex }
captureparams.wTimeLimit := word($0E);


{ max error rate = 1%. This is somewhat hardware dependant. }
captureparams.wPercentDropForError := 1;


{ these are the most common frame rates }
if(framespersec = 30) then

captureparams.dwRequestMicroSecPerFrame := 33334 { 30 fps }
else

captureparams.dwRequestMicroSecPerFrame := 41667;
{ 24 fps }

{ 0 = automatic mode, 1 = put up an OK button to initiate }
captureparams.fMakeUserHitOKToCapture := wordbool(0);

{ 1 = abort capture on Left button click, 1 = disable }
captureparams.fAbortLeftMouse := wordbool(0);

{ 1 = abort capture on Right button click, 1 = disable }
captureparams.fAbortRightMouse := wordbool(0);
{ escape key aborts capturing }
captureparams.vKeyAbort := VK_ESCAPE;


(*
These parameters are listed but aren't required for general
purpose video capture. Refer to the Win32 SDK discussion of
AVICAP to see if your intended application will be affected.

captureparams.wChunkGranularity := 0;
captureparams.dwIndexSize := 0;
captureparams.fUsingDOSMemory := byte(0);
{do
n't usedo
S memory }
captureparams.fStepMCIDevice := 0;
captureparams.fMCIControl := 0;
captureparams.fStepCaptureAt2x := 0;
captureparams.fDisableWriteCache := byte(0);
captureparams.wStepCaptureAverageFrames := 3;
*)

{ Now write the capture parameters }
apntr := addr(captureparams);
asize := sizeof(captureparams);
SendMessage(hWndC, WM_USER + 64, asize, longint(apntr));

{ tell AVICAP where to find the framecount callback }
SendMessage(hWndC, WM_USER + 6, 0, longint(addr(StreamCallback)));

end else
begin

usermessage( 'Invalid video driver.');
killcapwin;
{ just to be safe. It *is* windows, after all... }
end;

end;


{ show the capture window (including the live video) }
procedure ShowCapWin;
begin

ShowWindow(hWndC, SW_SHOW);
end;


{ hide the capture window }
procedure HideCapWin;
begin

ShowWindow(hWndC, SW_HIDE);
end;


{ destroy the capture window used by AVICAP }
procedure KillCapWin;
begin

ShowWindow(hWndC, SW_HIDE);
DestroyWindow(hWndC);
end;


{ Show the video format dialog. This is supplied by
the capture driver. All we need todo
is tell
AVICAP to make the proper call to the driver. }
procedure ShowVideoParamsWindow;
begin

ShowCapWin;
SendMessage(hWndC, WM_USER + 41, 0, 0);
{ allow this to happen }
application.processmessages;
HideCapWin;
end;


{ Show the video compression options dialog supplied by the
capture driver. This works like the ShowVideoParamsWindow
procedure. }
procedure ShowCompressionWindow;
begin

ShowCapWin;
SendMessage(hWndC, WM_USER + 46, 0, 0);
{ allow this to happen }
application.processmessages;
HideCapWin;
end;


{ display a message to the user }
procedure UserMessage(msg: string);
begin

{
use for troubleshooting or your own messages...
main.messagelabel.caption := msg;
}
end;


end.

</pre>

Hexi (1999-12-13 10:36:00)
Unit AviCap;


interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, extctrls,
AviCapH,unit1;


type
TAviCap = class(TCustomControl)

private
{ Private Declarations }
RequestMicroSecPerFrame:dword;
MakeUserHitOKToCapture:LongBool;
PercentDropForError:Byte;
Yield:bool;
IndexSize:dword;
ChunkGranularity:dword;
UsingDOSMemory:Bool;
NumVideoRequested:dword;
CaptureAudio:Bool;
NumAudioRequested:Byte;
KeyAbort:Word;
AbortLeftMouse:bool;
AbortRightMouse:bool;
LimitEnabled:bool;
TimeLimit:Byte;
MCIControl:bool;
StepMCIDevice:bool;
MCIStartTime:dword;
MCIStopTime:dword;
StepCaptureAt2x:bool;
StepCaptureAverageFrames:Byte;
AudioBufferSize:dword;
DisableWriteCache:bool;
StreamMaster:Word;
FConnected: boolean;
FDriverDescripton: TStringList;
FAviFileNAme:String;
FOverlay:boolean;
FScale:boolean;
FCaptureParms:TCaptureParms;
dummy:Boolean;
protected
{ Protected Declarations }
procedure Connect(b:Boolean);

procedure SetAviFileName(S:String);
procedure SetOverlay(b:boolean);

procedure SetScale(b:boolean);

procedure Disconnect;

Procedure DlgSource(B:Boolean);

Procedure DlgFormat(B:Boolean);

Procedure DlgCompression(B:Boolean);
Procedure DlgDisplay(B:Boolean);

public
{ Public Declarations }
DC:HDC;
FCapWndHandle: THandle;
constructor Create(AOwner: TComponent);
override;
procedure paint;override;
procedure StartCapture;
procedure Stopcapture;
property cap_DriverDescripton: TStringList read FDriverDescripton;
property cap_WndHandle: THandle read FCapWndHandle;
published
property Canvas;
property cap_Connected: boolean read FConnected write connect;
property cap_DlgVideoCompression: boolean read dummy write DlgCompression;
property cap_DlgVideoSourece: boolean read dummy write DlgSource;
property cap_DlgVideoDisplay: boolean read dummy write DlgDisplay;
property cap_DlgVideoFormat: boolean read dummy write DlgFormat;
property cap_AviFileName:String read FAviFileNAme write SetAviFileNAme;
property cap_Overlay:Boolean read FOverlay write SetOverlay;
property cap_Scale:Boolean read FScale write SetScale;
property cap_OptRequestMicroSecPerFrame:DWORD read RequestMicroSecPerFrame
write RequestMicroSecPerFrame;
property cap_OptMakeUserHitOKToCapture:Bool read MakeUserHitOKToCapture
write MakeUserHitOKToCapture;
property cap_OptPercentDropForError:Byte read PercentDropForError
write PercentDropForError;
property cap_OptYield:Bool read Yield
write Yield;
property cap_OptIndexSize:dword read IndexSize
write IndexSize;
property cap_OptChunkGranularity:dword read ChunkGranularity
write ChunkGranularity;
property cap_OptUsingDOSMemory:Bool read UsingDOSMemory
write UsingDOSMemory;
property cap_OptNumVideoRequested:dword read NumVideoRequested
write NumVideoRequested;
property cap_OptCaptureAudio:LongBool read CaptureAudio
write CaptureAudio;
property cap_OptNumAudioRequested:Byte read NumAudioRequested
write NumAudioRequested;
property cap_OptKeyAbort:Word read KeyAbort
write KeyAbort;
property cap_OptAbortLeftMouse:Bool read AbortLeftMouse
write AbortLeftMouse;
property cap_OptAbortRightMouse:Bool read AbortRightMouse
write AbortRightMouse;
property cap_OptLimitEnabled:Bool read LimitEnabled
write LimitEnabled;
property cap_OptTimeLimit:Byte read TimeLimit
write TimeLimit;
property cap_OptMCIControl:Bool read MCIControl
write MCIControl;
property cap_OptStepMCIDevice:Bool read StepMCIDevice
write StepMCIDevice;
property cap_OptMCIStartTime:dword read MCIStartTime
write MCIStartTime;
property cap_OptMCIStopTime:dword read MCIStopTime
write MCIStopTime;
property cap_OptStepCaptureAt2x:Bool read StepCaptureAt2x
write StepCaptureAt2x;
property cap_OptStepCaptureAverageFrames:Byte read StepCaptureAverageFrames
write StepCaptureAverageFrames;
property cap_OptAudioBufferSize:dword read AudioBufferSize
write AudioBufferSize;
property cap_OptDisableWriteCache:Bool read DisableWriteCache
write DisableWriteCache;
property cap_OptAVStreamMaster:Word read StreamMaster
write StreamMaster;
end;


procedure Register;

implementation
//{$R *.DCR}

constructor TAviCap.Create(AOwner: TComponent);

begin

inherited Create(AOwner);

parent:=AOwner as TWinCOntrol;

FCapWndHandle:=capCreateCaptureWindowA('',WS_VISIBLE+WS_CHILD+WS_BORDER,
0,0,0,0,handle,0);
FAviFileNAMe:='nul';

capCaptureGetSetup (FCapWndHandle,WParam(@FCaptureParms),LParam(SizeOf(TCaptureParms)));
with FCaptureParmsdo

begin

RequestMicroSecPerFrame:=dwRequestMicroSecPerFrame;
MakeUserHitOKToCapture:=fMakeUserHitOKToCapture;
PercentDropForError:=wPercentDropForError;
Yield:=fYield;
IndexSize:=dwIndexSize;
ChunkGranularity:=wChunkGranularity;
UsingDOSMemory:=fUsingDOSMemory;
NumVideoRequested:=wNumVideoRequested;
CaptureAudio:=fCaptureAudio;
NumAudioRequested:=wNumAudioRequested;
KeyAbort:=vKeyAbort;
AbortLeftMouse:=fAbortLeftMouse;
AbortRightMouse:=fAbortRightMouse;
LimitEnabled:=fLimitEnabled;
TimeLimit:=wTimeLimit;
MCIControl:=fMCIControl;
StepMCIDevice:=fStepMCIDevice;
MCIStartTime:=dwMCIStartTime;
MCIStopTime:=dwMCIStopTime;
StepCaptureAt2x:=fStepCaptureAt2x;
StepCaptureAverageFrames:=wStepCaptureAverageFrames;
AudioBufferSize:=dwAudioBufferSize;
DisableWriteCache:=fDisableWriteCache;
StreamMaster:=AVStreamMaster;
end;

FOverlay:=True;
end;


procedure TAviCap.Connect(b:Boolean);

begin

if b then

begin

TextOut(dc,10,10,'Connecting.please wait!',24);
fconnected:=capDriverConnect(FCapWndHandle,0);
SetOverlay(FOverlay);

end
else
disconnect;
end;


procedure TAviCap.Disconnect;
var
B:boolean;
begin

b:=FOverlay;
SetOverlay(False);

capDriverDisconnect(FCapWndHandle);
fconnected:=False;
SetOverlay(b);
end;


procedure TAviCap.Paint;

begin

inherited Paint;
SetWindowPos(FCapWndHandle,HWND_TOP,0,0,width,height,SWP_SHOWWINDOW);
if dc=0 then
dc:=Getdc(FCapWndHandle);
If csDesigning in ComponentState then
TextOut(dc,10,10,PChar(NAme),Length(NAme));
end;


procedure TAviCap.SetAviFileName(S:String);
begin

capFileSetCaptureFile (FCapWndHandle, LParam(PChar(s)));
FAVIFileNAme:=s;
end;


procedure TAviCap.SetOverlay(b:boolean);
begin

capOverlay (FCapWndHandle, WPARAM(b));
FOverlay:=b;
end;


procedure TAviCap.SetScale(b:boolean);
begin

capPreviewScale (FCapWndHandle, WPARAM(b));
FScale:=b;
end;

procedure TAviCAp.StartCapture;

begin

SetOverlay(false);
capCapturesetsetup(FCapWndHandle,WParam(@FCaptureParms),LParam(SizeOf(TCaptureParms)));
capSetCallbackOnFrame(FCapWndHandle,integer(@CallBackFun));
end;


procedure TAviCAp.StopCapture;

begin

capCaptureStop(FCapWndHandle);
end;

Procedure TAviCap.DlgSource(B:Boolean);
begin

capDlgVideoSource (FCapWndHandle);
end;


Procedure TAviCAp.DlgFormat(B:Boolean);

begin

capDlgVideoFormat (FCapWndHandle);
end;


Procedure TAviCap.DlgCompression(B:Boolean);
begin

capDlgVideoCompression (FCapWndHandle);
end;


Procedure TAviCap.DlgDisplay(B:Boolean);
begin

capDlgVideoDisplay (FCapWndHandle);
end;


procedure Register;

begin

RegisterComponents('Sample', [TAviCap]);
end;


end.






{
****************************************************************************
* *
* Translated from avicap.h *
* *
* Main include file. *
* *
* Microsoft Video for Windows Sample Capture Class *
* *
* *
* C/C++ Run Time Library - Version 8.0 *
* *
* Copyright (c) 1994, 1997 by Borland International *
* All Rights Reserved. *
* *
* *
****************************************************************************
}
unit AviCapH;

interface

uses windows,messages, SysUtils;

// ------------------------------------------------------------------
// Window Messages WM_CAP... which can be sent to an AVICAP window
// ------------------------------------------------------------------

// Defines start of the message range
const
avicap32='avicap32.dll';

WM_CAP_START= WM_USER;

// start of unicode messages
WM_CAP_UNICODE_START= WM_USER+100;

WM_CAP_GET_CAPSTREAMPTR= (WM_CAP_START+ 1);

WM_CAP_SET_CALLBACK_ERROR= (WM_CAP_START+ 2) ;
WM_CAP_SET_CALLBACK_STATUS= (WM_CAP_START+ 3);

WM_CAP_SET_CALLBACK_YIELD= (WM_CAP_START+ 4);
WM_CAP_SET_CALLBACK_FRAME= (WM_CAP_START+ 5);
WM_CAP_SET_CALLBACK_VIDEOSTREAM= (WM_CAP_START+ 6);
WM_CAP_SET_CALLBACK_WAVESTREAM= (WM_CAP_START+ 7);
WM_CAP_GET_USER_DATA =(WM_CAP_START+ 8);
WM_CAP_SET_USER_DATA =(WM_CAP_START+ 9) ;

WM_CAP_DRIVER_CONNECT =(WM_CAP_START+ 10);
WM_CAP_DRIVER_DISCONNECT =(WM_CAP_START+ 11);

WM_CAP_DRIVER_GET_NAME =(WM_CAP_START+ 12);
WM_CAP_DRIVER_GET_VERSION =(WM_CAP_START+ 13);

WM_CAP_DRIVER_GET_CAPS =(WM_CAP_START+ 14);

WM_CAP_FILE_SET_CAPTURE_FILE =(WM_CAP_START+ 20);
WM_CAP_FILE_GET_CAPTURE_FILE =(WM_CAP_START+ 21);
WM_CAP_FILE_SAVEAS =(WM_CAP_START+ 23);
WM_CAP_FILE_SAVEDIB =(WM_CAP_START+ 25);

// out of order to save on ifdefs
WM_CAP_FILE_ALLOCATE =(WM_CAP_START+ 22);
WM_CAP_FILE_SET_INFOCHUNK =(WM_CAP_START+ 24);

WM_CAP_EDIT_COPY =(WM_CAP_START+ 30);

WM_CAP_SET_AUDIOFORMAT =(WM_CAP_START+ 35);
WM_CAP_GET_AUDIOFORMAT =(WM_CAP_START+ 36);

WM_CAP_DLG_VIDEOFORMAT =(WM_CAP_START+ 41);
WM_CAP_DLG_VIDEOSOURCE =(WM_CAP_START+ 42);
WM_CAP_DLG_VIDEODISPLAY =(WM_CAP_START+ 43);
WM_CAP_GET_VIDEOFORMAT =(WM_CAP_START+ 44);
WM_CAP_SET_VIDEOFORMAT =(WM_CAP_START+ 45);
WM_CAP_DLG_VIDEOCOMPRESSION =(WM_CAP_START+ 46);

WM_CAP_SET_PREVIEW =(WM_CAP_START+ 50);
WM_CAP_SET_OVERLAY =(WM_CAP_START+ 51);
WM_CAP_SET_PREVIEWRATE =(WM_CAP_START+ 52);
WM_CAP_SET_SCALE =(WM_CAP_START+ 53);
WM_CAP_GET_STATUS =(WM_CAP_START+ 54);
WM_CAP_SET_SCROLL =(WM_CAP_START+ 55);

WM_CAP_GRAB_FRAME =(WM_CAP_START+ 60);
WM_CAP_GRAB_FRAME_NOSTOP =(WM_CAP_START+ 61);

WM_CAP_SEQUENCE =(WM_CAP_START+ 62);
WM_CAP_SEQUENCE_NOFILE =(WM_CAP_START+ 63);
WM_CAP_SET_SEQUENCE_SETUP =(WM_CAP_START+ 64);
WM_CAP_GET_SEQUENCE_SETUP =(WM_CAP_START+ 65);

WM_CAP_SET_MCI_DEVICE =(WM_CAP_START+ 66);
WM_CAP_GET_MCI_DEVICE =(WM_CAP_START+ 67);

WM_CAP_STOP =(WM_CAP_START+ 68);
WM_CAP_ABORT =(WM_CAP_START+ 69);

WM_CAP_SINGLE_FRAME_OPEN =(WM_CAP_START+ 70);
WM_CAP_SINGLE_FRAME_CLOSE =(WM_CAP_START+ 71);
WM_CAP_SINGLE_FRAME =(WM_CAP_START+ 72);

WM_CAP_PAL_OPEN =(WM_CAP_START+ 80);
WM_CAP_PAL_SAVE =(WM_CAP_START+ 81);

WM_CAP_PAL_PASTE =(WM_CAP_START+ 82);
WM_CAP_PAL_AUTOCREATE =(WM_CAP_START+ 83);
WM_CAP_PAL_MANUALCREATE =(WM_CAP_START+ 84);

// Following added post VFW 1.1
WM_CAP_SET_CALLBACK_CAPCONTROL =(WM_CAP_START+ 85);

WM_CAP_END =WM_CAP_SET_CALLBACK_CAPCONTROL;


function capCreateCaptureWindowA (
lpszWindowName:PChar;
dwStyle:DWORD;
x,y,nWidth,nHeight:Integer;
hwndParent:HWnd;nID:Integer):hwnd;stdcall;
external avicap32;

function capGetDriverDescriptionA (
wDriverIndex:UINT;
lpszName:PChar;cbName:Integer;
lpszVer:PChar;cbVer:Integer):Boolean;stdcall;
external avicap32;

procedure capSetCallbackOnError(hCapWnd:hwnd;
fpProc:Lparam);
procedure capSetCallbackOnStatus(hCapWnd:hwnd;
fpProc:LParam);
procedure capSetCallbackOnYield(hCapWnd:hwnd;
fpProc:LParam);
procedure capSetCallbackOnFrame(hCapWnd:hwnd;
fpProc:LParam);
procedure capSetCallbackOnVideoStream(hCapWnd:hwnd;
fpProc:LParam);
procedure capSetCallbackOnWaveStream(hCapWnd:hwnd;
fpProc:LParam);
procedure capSetCallbackOnCapControl(hCapWnd:hwnd;
fpProc:LParam);
procedure capSetUserData(hCapWnd:hwnd;lUser:LParam);
procedure capGetUserData(hCapWnd:hwnd);
function capDriverConnect(hCapWnd:hwnd;
i:wParam):Boolean;
procedure capDriverDisconnect(hCapWnd:hwnd);
procedure capDriverGetName(hCapWnd:hwnd;
szName:wParam;
wSize:LParam);
procedure capDriverGetVersion(hCapWnd:hwnd;
szVer:wParam;
wSize:LParam);
procedure capDriverGetCaps(hCapWnd:hwnd;
s:wParam;
wSize:LParam);
procedure capFileSetCaptureFile(hCapWnd:hwnd;
szName :LPARAM);
procedure capFileGetCaptureFile(hCapWnd:hwnd;
szName :wPARAM;
wSize :lPARAM);
procedure capFileAlloc(hCapWnd:hwnd;
dwSize :LPARAM);
procedure capFileSaveAs(hCapWnd:hwnd;
szName :LPARAM);
procedure capFileSetInfoChunk(hCapWnd:hwnd;
lpInfoChunk :LPARAM);
procedure capFileSaveDIB(hCapWnd:hwnd;
szName :LPARAM);
procedure capEditCopy(hCapWnd:hwnd);
procedure capSetAudioFormat(hCapWnd:hwnd;
s :WPARAM;
wSize :LPARAM);
procedure capGetAudioFormat(hCapWnd:hwnd;
s :WPARAM;
wSize :LPARAM);
procedure capGetAudioFormatSize(hCapWnd:hwnd);
procedure capDlgVideoFormat(hCapWnd:hwnd);

procedure capDlgVideoSource(hCapWnd:hwnd);
procedure capDlgVideoDisplay(hCapWnd:hwnd);
procedure capDlgVideoCompression(hCapWnd:hwnd);
procedure capGetVideoFormat(hCapWnd:hwnd;
s:WPARAM;
wSize:LPARAM);
procedure capGetVideoFormatSize(hCapWnd:hwnd);
procedure capSetVideoFormat(hCapWnd:hwnd;
s:WPARAM;
wSize:LPARAM);
procedure capPreview(hCapWnd:hwnd;
f :WPARAM);
procedure capPreviewRate(hCapWnd:hwnd;
wMS :WPARAM);
procedure capOverlay(hCapWnd:hwnd;
f :WPARAM);
procedure capPreviewScale(hCapWnd:hwnd;
f :WPARAM);
procedure capGetStatus(hCapWnd:hwnd;
s:WPARAM;
wSize:LPARAM);
procedure capSetScrollPos(hCapWnd:hwnd;
lpP :LPARAM);
procedure capGrabFrame(hCapWnd:hwnd);
procedure capGrabFrameNoStop(hCapWnd:hwnd);
procedure capCaptureSequence(hCapWnd:hwnd);
procedure capCaptureSequenceNoFile(hCapWnd:hwnd);
procedure capCaptureStop(hCapWnd:hwnd);
procedure capCaptureAbort(hCapWnd:hwnd);
procedure capCaptureSingleFrameOpen(hCapWnd:hwnd);
procedure capCaptureSingleFrameClose(hCapWnd:hwnd);
procedure capCaptureSingleFrame(hCapWnd:hwnd);
procedure capCaptureGetSetup(hCapWnd:hwnd;
s:WPARAM;
wSize:LPARAM);
procedure capCaptureSetSetup(hCapWnd:hwnd;
s:WPARAM;
wSize:LPARAM);
procedure capSetMCIDeviceName(hCapWnd:hwnd;
szName:LPARAM);
procedure capGetMCIDeviceName(hCapWnd:hwnd;
szName:LPARAM;
wSize:WPARAM);
procedure capPaletteOpen(hCapWnd:hwnd;
szName:LPARAM);
procedure capPaletteSave(hCapWnd:hwnd;
szName:LPARAM);
procedure capPalettePaste(hCapWnd:hwnd);
procedure capPaletteAuto(hCapWnd:hwnd;
iFrames:WPARAM;
iColors :LPARAM);
procedure capPaletteManual(hCapWnd:hwnd;
fGrab :WPARAM;
iColors :LPARAM);


// ------------------------------------------------------------------
// Structures
// ------------------------------------------------------------------

type
TCapDriverCaps =packed Record
wDeviceIndex:UINT;
// Driver index in system.ini
fHasOverlay:BOOL;
// Can device overlay?
fHasDlgVideoSource:BOOL;
// Has Video source dlg?
fHasDlgVideoFormat:BOOL;
// Has Format dlg?
fHasDlgVideoDisplay:BOOL;
// Has External out dlg?
fCaptureInitialized:BOOL;
// Driver ready to capture?
fDriverSuppliesPalettes:BOOL;
// Can driver make palettes?

// following always NULL on Win32.
hVideoIn:THANDLE;
// Driver In channel
hVideoOut:THANDLE;
// Driver Out channel
hVideoExtIn:THANDLE;
// Driver Ext In channel
hVideoExtOut:THANDLE;
// Driver Ext Out channel
end;


type
TCapStatus = packed record
uiImageWidth:UINT ;
// Width of the image
uiImageHeight:UINT ;
// Height of the image
fLiveWindow:BOOL ;
// Now Previewing video?
fOverlayWindow:BOOL ;
// Now Overlaying video?
fScale:BOOL ;
// Scale image to client?
ptScroll:TPOINT ;
// Scroll position
fUsingDefaultPalette:BOOL ;
// Using default driver palette?
fAudioHardware:BOOL ;
// Audio hardware present?
fCapFileExists:BOOL ;
//do
es capture file exist?
dwCurrentVideoFrame:DWORD ;
// # of video frames cap'td
dwCurrentVideoFramesDropped:DWORD ;// # of video frames dropped
dwCurrentWaveSamples:DWORD ;
// # of wave samples cap'td
dwCurrentTimeElapsedMS:DWORD ;
// Elapsed capture duration
hPalCurrent:HPALETTE ;
// Current palette in use
fCapturingNow:BOOL ;
// Capture in progress?
dwReturn:DWORD ;
// Error value after any operation
wNumVideoAllocated:UINT ;
// Actual number of video buffers
wNumAudioAllocated:UINT ;
// Actual number of audio buffers
end;


type
// video data block header
LPByte=PByteArray;
Videohdr=packed record
lpData:LPBYTE;
//pointer to locked data buffer
dwBufferLength:DWORD;
//Length of data buffer
dwBytesUsed:DWORD ;
// Bytes actually used
dwTimeCaptured:DWORD ;
// Milliseconds from start of stream
dwUser:DWORD ;
//for client's use
dwFlags:DWORD ;
//assorted flags (see defines)
dwReserved:array[0..3] of DWORD;
// reserved for driver
end;

LPVideoHdr=^VideoHdr;

TCaptureParms = packed Record
dwRequestMicroSecPerFrame:DWORD ;
// Requested capture rate
fMakeUserHitOKToCapture:BOOL ;
// Show &quot;Hit OK to cap&quot;
dlg?
wPercentDropForError:UINT ;
// Give error msg if > (10%)
fYield:BOOL ;
// Capture via background task?
dwIndexSize:DWORD ;
// Max index size in frames (32K)
wChunkGranularity:UINT ;
// Junk chunk granularity (2K)
fUsingDOSMemory:BOOL ;
// Usedo
S buffers?
wNumVideoRequested:UINT ;
// # video buffers, If 0, autocalc
fCaptureAudio:BOOL ;
// Capture audio?
wNumAudioRequested:UINT ;
// # audio buffers, If 0, autocalc
vKeyAbort:UINT ;
// Virtual key causing abort
fAbortLeftMouse:BOOL ;
// Abort on left mouse?
fAbortRightMouse:BOOL ;
// Abort on right mouse?
fLimitEnabled:BOOL ;
// Use wTimeLimit?
wTimeLimit:UINT ;
// Seconds to capture
fMCIControl:BOOL ;
// Use MCI video source?
fStepMCIDevice:BOOL ;
// Step MCI device?
dwMCIStartTime:DWORD ;
// Time to start in MS
dwMCIStopTime:DWORD ;
// Time to stop in MS
fStepCaptureAt2x:BOOL ;
// Perform spatial averaging 2x
wStepCaptureAverageFrames:UINT ;
// Temporal average n Frames
dwAudioBufferSize:DWORD ;
// Size of audio bufs (0 = default)
fDisableWriteCache:BOOL ;
// Attempt to disable write cache
AVStreamMaster:DWORD;


end;


type
TByteRec = record
Lo, Hi: Byte;
end;


TWordRec = record
Low, High: TByteRec;
end;


Type
FOURCC=TWordRec;

function mmioFOURCC(const c0,c1,c2,c3:Char):FOURCC;

type
TCapInfoChunk = packed record
fccInfoID:FOURCC ;
// Chunk ID, &quot;ICOP&quot;
for copyright
lpData:Pointer ;
// pointer to data
cbData:LONGINT ;
// size of lpData
end;


// ------------------------------------------------------------------
// CapControlCallback states
// ------------------------------------------------------------------
const
CONTROLCALLBACK_PREROLL = 1;
//* Waiting to start capture */
CONTROLCALLBACK_CAPTURING= 2;
//* Now capturing */

// ------------------------------------------------------------------
// New Information chunk IDs
// ------------------------------------------------------------------

// DIGITIZATION_TIME = mmioFOURCC ('I','D','I','T');
// infotypeSMPTE_TIME mmioFOURCC ('I','S','M','P')

// ------------------------------------------------------------------
// String IDs from status and error callbacks
// ------------------------------------------------------------------
{
IDS_CAP_begin
300 /* &quot;Capture Start&quot;
*/
IDS_CAP_END 301 /* &quot;Capture End&quot;
*/

IDS_CAP_INFO 401 /* &quot;%s&quot;
*/
IDS_CAP_OUTOFMEM 402 /* &quot;Out of memory&quot;
*/
IDS_CAP_FILEEXISTS 403 /* &quot;File '%s' exists -- overwrite it?&quot;
*/
IDS_CAP_ERRORPALOPEN 404 /* &quot;Error opening palette '%s'&quot;
*/
IDS_CAP_ERRORPALSAVE 405 /* &quot;Error saving palette '%s'&quot;
*/
IDS_CAP_ERRORDIBSAVE 406 /* &quot;Error saving frame '%s'&quot;
*/
IDS_CAP_DEFAVIEXT 407 /* &quot;avi&quot;
*/
IDS_CAP_DEFPALEXT 408 /* &quot;pal&quot;
*/
IDS_CAP_CANTOPEN 409 /* &quot;Cannot open '%s'&quot;
*/
IDS_CAP_SEQ_MSGSTART 410 /* &quot;Select OK to start capture/nof video sequence/nto %s.&quot;
*/
IDS_CAP_SEQ_MSGSTOP 411 /* &quot;Hit ESCAPE or click to end capture&quot;
*/

IDS_CAP_VIDEDITERR 412 /* &quot;An error occurred while trying to run VidEdit.&quot;
*/
IDS_CAP_READONLYFILE 413 /* &quot;The file '%s' is a read-only file.&quot;
*/
IDS_CAP_WRITEERROR 414 /* &quot;Unable to write to file '%s'./nDisk may be full.&quot;
*/
IDS_CAP_NODISKSPACE 415 /* &quot;There is no space to create a capture file on the specified device.&quot;
*/
IDS_CAP_SETFILESIZE 416 /* &quot;Set File Size&quot;
*/
IDS_CAP_SAVEASPERCENT 417 /* &quot;SaveAs: %2ld%% Hit Escape to abort.&quot;
*/

IDS_CAP_DRIVER_ERROR 418 /* Driver specific error message */

IDS_CAP_WAVE_OPEN_ERROR 419 /* &quot;Error: Cannot open the wave input device./nCheck sample size, frequency, and channels.&quot;
*/
IDS_CAP_WAVE_ALLOC_ERROR 420 /* &quot;Error: Out of memory for wave buffers.&quot;
*/
IDS_CAP_WAVE_PREPARE_ERROR 421 /* &quot;Error: Cannot prepare wave buffers.&quot;
*/
IDS_CAP_WAVE_ADD_ERROR 422 /* &quot;Error: Cannot add wave buffers.&quot;
*/
IDS_CAP_WAVE_SIZE_ERROR 423 /* &quot;Error: Bad wave size.&quot;
*/

IDS_CAP_VIDEO_OPEN_ERROR 424 /* &quot;Error: Cannot open the video input device.&quot;
*/
IDS_CAP_VIDEO_ALLOC_ERROR 425 /* &quot;Error: Out of memory for video buffers.&quot;
*/
IDS_CAP_VIDEO_PREPARE_ERROR 426 /* &quot;Error: Cannot prepare video buffers.&quot;
*/
IDS_CAP_VIDEO_ADD_ERROR 427 /* &quot;Error: Cannot add video buffers.&quot;
*/
IDS_CAP_VIDEO_SIZE_ERROR 428 /* &quot;Error: Bad video size.&quot;
*/

IDS_CAP_FILE_OPEN_ERROR 429 /* &quot;Error: Cannot open capture file.&quot;
*/
IDS_CAP_FILE_WRITE_ERROR 430 /* &quot;Error: Cannot write to capture file. Disk may be full.&quot;
*/
IDS_CAP_RECORDING_ERROR 431 /* &quot;Error: Cannot write to capture file. Data rate too high or disk full.&quot;
*/
IDS_CAP_RECORDING_ERROR2 432 /* &quot;Error while recording&quot;
*/
IDS_CAP_AVI_INIT_ERROR 433 /* &quot;Error: Unable to initialize for capture.&quot;
*/
IDS_CAP_NO_FRAME_CAP_ERROR 434 /* &quot;Warning: No frames captured./nConfirm that vertical sync interrupts/nare configured and enabled.&quot;
*/
IDS_CAP_NO_PALETTE_WARN 435 /* &quot;Warning: Using default palette.&quot;
*/
IDS_CAP_MCI_CONTROL_ERROR 436 /* &quot;Error: Unable to access MCI device.&quot;
*/
IDS_CAP_MCI_CANT_STEP_ERROR 437 /* &quot;Error: Unable to step MCI device.&quot;
*/
IDS_CAP_NO_AUDIO_CAP_ERROR 438 /* &quot;Error: No audio data captured./nCheck audio card settings.&quot;
*/
IDS_CAP_AVI_DRAWDIB_ERROR 439 /* &quot;Error: Unable to draw this data format.&quot;
*/
IDS_CAP_COMPRESSOR_ERROR 440 /* &quot;Error: Unable to initialize compressor.&quot;
*/
IDS_CAP_AUDIO_DROP_ERROR 441 /* &quot;Error: Audio data was lost during capture, reduce capture rate.&quot;
*/

/* status string IDs */
IDS_CAP_STAT_LIVE_MODE 500 /* &quot;Live window&quot;
*/
IDS_CAP_STAT_OVERLAY_MODE 501 /* &quot;Overlay window&quot;
*/
IDS_CAP_STAT_CAP_INIT 502 /* &quot;Setting up for capture - Please wait&quot;
*/
IDS_CAP_STAT_CAP_FINI 503 /* &quot;Finished capture, now writing frame %ld&quot;
*/
IDS_CAP_STAT_PALETTE_BUILD 504 /* &quot;Building palette map&quot;
*/
IDS_CAP_STAT_OPTPAL_BUILD 505 /* &quot;Computing optimal palette&quot;
*/
IDS_CAP_STAT_I_FRAMES 506 /* &quot;%d frames&quot;
*/
IDS_CAP_STAT_L_FRAMES 507 /* &quot;%ld frames&quot;
*/
IDS_CAP_STAT_CAP_L_FRAMES 508 /* &quot;Captured %ld frames&quot;
*/
IDS_CAP_STAT_CAP_AUDIO 509 /* &quot;Capturing audio&quot;
*/
IDS_CAP_STAT_VIDEOCURRENT 510 /* &quot;Captured %ld frames (%ld dropped);
//%d.%03d sec.&quot;
*/
IDS_CAP_STAT_VIDEOAUDIO 511 /* &quot;Captured %d.%03d sec. %ld frames (%ld dropped);
//(%d.%03d fps). %ld audio bytes (%d,%03d sps)&quot;
*/
IDS_CAP_STAT_VIDEOONLY 512 /* &quot;Captured %d.%03d sec. %ld frames (%ld dropped);
//(%d.%03d fps)&quot;
*/
IDS_CAP_STAT_FRAMESDROPPED 513 /* &quot;Dropped %ld of %ld frames (%d.%02d%%);
//during capture.&quot;
*/
}

implementation

function mmioFOURCC(const c0,c1,c2,c3:Char):FOURCC;
begin

result.High.Hi:=Byte(c0);
result.High.Lo:=Byte(c1);
result.Low.Hi:=Byte(c2);
result.Low.Lo:=Byte(c3);
end;


procedure capSetCallbackOnError(hCapWnd:hwnd;
fpProc:Lparam);
begin

SendMessage(hCapWnd, WM_CAP_SET_CALLBACK_ERROR, 0, fpProc)
end;


procedure capSetCallbackOnStatus(hCapWnd:hwnd;
fpProc:LParam);
begin

SendMessage(hCapWnd, WM_CAP_SET_CALLBACK_Status, 0, fpProc)
end;


procedure capSetCallbackOnYield(hCapWnd:hwnd;
fpProc:LParam);
begin

SendMessage(hCapWnd, WM_CAP_SET_CALLBACK_YIELD, 0, fpProc)
end;


procedure capSetCallbackOnFrame(hCapWnd:hwnd;
fpProc:LParam);
begin

SendMessage(hCapWnd, WM_CAP_SET_CALLBACK_FRAME, 0, fpProc)
end;


procedure capSetCallbackOnVideoStream(hCapWnd:hwnd;
fpProc:LParam);
begin

SendMessage(hCapWnd, WM_CAP_SET_CALLBACK_VideoSTREAM, 0, fpProc)
end;


procedure capSetCallbackOnWaveStream(hCapWnd:hwnd;
fpProc:LParam);
begin

SendMessage(hCapWnd, WM_CAP_SET_CALLBACK_WAVESTREAM , 0, fpProc)
end;


procedure capSetCallbackOnCapControl(hCapWnd:hwnd;
fpProc:LParam);
begin

SendMessage(hCapWnd, WM_CAP_SET_CALLBACK_CapControl , 0, fpProc)
end;


procedure capGetUserData(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_GET_USER_DATA , 0, 0)
end;


procedure capSetUserData(hCapWnd:hwnd;lUser:LParam);
begin

SendMessage(hCapWnd, WM_CAP_SET_USER_DATA , 0, lUser)
end;


function capDriverConnect(hCapWnd:hwnd;
i:wParam):Boolean;
begin

result:=SendMessage(hCapWnd, WM_CAP_DRIVER_CONNECT ,i , 0)<>0;
end;


procedure capDriverDisconnect(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_DRIVER_DISCONNECT ,0 , 0)
end;


procedure capDriverGetName(hCapWnd:hwnd;
szName:wParam;
wSize:LParam);
begin

SendMessage(hCapWnd, WM_CAP_DRIVER_Get_Name ,szName , wSize)
end;


procedure capDriverGetVersion(hCapWnd:hwnd;
szVer:wParam;
wSize:LParam);
begin

SendMessage(hCapWnd, WM_CAP_DRIVER_Get_VERSION ,szVer , wSize)
end;


procedure capDriverGetCaps(hCapWnd:hwnd;
s:wParam;
wSize:LParam);
begin

SendMessage(hCapWnd, WM_CAP_DRIVER_Get_CAPS ,s , wSize)
end;


procedure capFileSetCaptureFile(hCapWnd:hwnd;
szName :LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_FILE_SET_CAPTURE_FILE ,0 , szName)
end;


procedure capFileGetCaptureFile(hCapWnd:hwnd;
szName :wPARAM;
wSize :lPARAM);
begin

SendMessage(hCapWnd, WM_CAP_FILE_GET_CAPTURE_FILE , szName,wSize)
end;


procedure capFileAlloc(hCapWnd:hwnd;
dwSize :LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_FILE_ALLOCATE , 0,dwSize)
end;


procedure capFileSaveAs(hCapWnd:hwnd;
szName :LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_FILE_SAVEAS , 0,szName)
end;


procedure capFileSetInfoChunk(hCapWnd:hwnd;
lpInfoChunk :LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_FILE_SET_INFOCHUNK , 0,lpInfoChunk)
end;


procedure capFileSaveDIB(hCapWnd:hwnd;
szName :LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_FILE_SAVEDIB , 0,szName)
end;


procedure capEditCopy(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_EDIT_COPY , 0,0)
end;


procedure capSetAudioFormat(hCapWnd:hwnd;
s :WPARAM;
wSize :LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_SET_AUDIOFORMAT , s,wSize)
end;


procedure capGetAudioFormat(hCapWnd:hwnd;
s :WPARAM;
wSize :LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_GET_AUDIOFORMAT , s,wSize)
end;


procedure capGetAudioFormatSize(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_GET_AUDIOFORMAT , 0,0)
end;


procedure capDlgVideoFormat(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_DLG_VIDEOFORMAT , 0,0)
end;


procedure capDlgVideoSource(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_DLG_VIDEOSOURCE , 0,0)
end;


procedure capDlgVideoDisplay(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_DLG_VIDEODISPLAY , 0,0)
end;


procedure capDlgVideoCompression(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_DLG_VIDEOCOMPRESSION , 0,0)
end;


procedure capGetVideoFormat(hCapWnd:hwnd;
s:WPARAM;
wSize:LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_GET_VIDEOFORMAT , s,wSize)
end;


procedure capGetVideoFormatSize(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_GET_VIDEOFORMAT , 0,0)
end;


procedure capSetVideoFormat(hCapWnd:hwnd;
s:WPARAM;
wSize:LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_GET_VIDEOFORMAT , 0,0)
end;


procedure capPreview(hCapWnd:hwnd;
f :WPARAM);
begin

SendMessage(hCapWnd, WM_CAP_SET_PREVIEW , f,0)
end;


procedure capPreviewRate(hCapWnd:hwnd;
wMS :WPARAM);
begin

SendMessage(hCapWnd, WM_CAP_SET_PREVIEWRATE , wMS,0)
end;


procedure capOverlay(hCapWnd:hwnd;
f :WPARAM);
begin

SendMessage(hCapWnd, WM_CAP_SET_OVERLAY , f,0)
end;


procedure capPreviewScale(hCapWnd:hwnd;
f :WPARAM);
begin

SendMessage(hCapWnd, WM_CAP_SET_SCALE , f,0)
end;


procedure capGetStatus(hCapWnd:hwnd;
s:WPARAM;
wSize:LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_GET_STATUS , s,wSize)
end;


procedure capSetScrollPos(hCapWnd:hwnd;
lpP :LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_SET_SCROLL , 0,lpP)
end;


procedure capGrabFrame(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_GRAB_FRAME , 0,0)
end;


procedure capGrabFrameNoStop(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_GRAB_FRAME_NOSTOP , 0,0)
end;


procedure capCaptureSequence(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_SEQUENCE , 0,0)
end;


procedure capCaptureSequenceNoFile(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_SEQUENCE_NOFILE , 0,0)
end;


procedure capCaptureStop(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_Stop , 0,0)
end;


procedure capCaptureAbort(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_ABORT , 0,0)
end;


procedure capCaptureSingleFrameOpen(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_SINGLE_FRAME_OPEN , 0,0)
end;


procedure capCaptureSingleFrameClose(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_SINGLE_FRAME_CLOSE , 0,0)
end;


procedure capCaptureSingleFrame(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_SINGLE_FRAME , 0,0)
end;


procedure capCaptureGetSetup(hCapWnd:hwnd;
s:WPARAM;
wSize:LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_GET_SEQUENCE_SETUP , s,wSize)
end;


procedure capCaptureSetSetup(hCapWnd:hwnd;
s:WPARAM;
wSize:LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_SET_SEQUENCE_SETUP , s,wSize)
end;


procedure capSetMCIDeviceName(hCapWnd:hwnd;
szName:LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_SET_MCI_DEVICE , 0,szName)
end;


procedure capGetMCIDeviceName(hCapWnd:hwnd;
szName:LPARAM;
wSize:WPARAM);
begin

SendMessage(hCapWnd, WM_CAP_GET_MCI_DEVICE , wSize,szName)
end;


procedure capPaletteOpen(hCapWnd:hwnd;
szName:LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_PAL_OPEN , 0,szName)
end;


procedure capPaletteSave(hCapWnd:hwnd;
szName:LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_PAL_SAVE , 0,szName)
end;


procedure capPalettePaste(hCapWnd:hwnd);
begin

SendMessage(hCapWnd, WM_CAP_PAL_PASTE , 0,0)
end;


procedure capPaletteAuto(hCapWnd:hwnd;
iFrames:WPARAM;
iColors :LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_PAL_AUTOCREATE , iFrames,iColors)
end;


procedure capPaletteManual(hCapWnd:hwnd;
fGrab :WPARAM;
iColors :LPARAM);
begin

SendMessage(hCapWnd, WM_CAP_PAL_MANUALCREATE , fGrab,iColors)
end;


end.



Hexi (1999-12-13 10:43:00)
unit Unit1;
{该单元是用来截取捕获图象数据
进行处理——输出坐标。}

interface
uses
sysUtils,Avicaph,graphics,windows;
const
SWidth=319;
SHeight=239;
type
ColorArr=packed array[0..SHeight,0..SWidth] of Byte;
var
x,y:integer;
buf:ColorArr;

procedure CallBackFun(h:HWND;lpv:LPVideoHdr);stdcall;
procedure stopdrawing;
implementation
uses
wly;
procedure CallBackFun(h:HWND;lpv:LPVideoHdr);
const
gray=20;
//基准象素点颜色值
var
i,j:integer;
a,b,ax,ay,bx,by:integer;
dc:hdc;
begin
//取坐标
move(lpv^.lpdata^,buf,lpv^.dwbytesused);//将捕获数据放到缓冲区中
a:=0;b:=0;ax:=0;bx:=0;ay:=0;by:=0;
dc:=getdc(Form1.Panel1.handle);
for i:=0 to SHeightdo

begin

for j:=0 to SWidth do

begin

if buf[i,j]>gray then

begin

inc(a);ax:=ax+j;ay:=ay+i;
Windows.setpixel(dc,j,i,clWhite);
end
else

begin

inc(b);bx:=bx+j;by:=by+i;
Windows.setpixel(dc,j,i,clBlack);
end;

end;

end;

if (a=0)or(b=0) then
exit
else

if a<b then

begin

x:=ax div a;y:=SHeight-ay div a;
end
else

begin

x:=bx div b;y:=SHeight-by div b;
end;

end;

procedure stopdrawing;//恢复窗口
var
dcc:HDC;
i,j:integer;
begin

dcc:=getdc(Form1.Panel1.handle);
for i:=0 to SHeightdo

for j:=0 to SWidthdo

Windows.setpixel(dcc,j,SHeight-i,clwhite);
end;

end.





www (1999-12-13 10:44:00)
到深度历险down一个利用 Microsoft Video for Windows 提供的 AVICAP32.DLL
撷取 AVI 档画面的构件

yzhu (1999-12-13 20:24:00)
to yaoyao, 我也要一份, thank you!
<A HREF=&quot;mailto:yzhu@126.com&quot;>yzhu@126.com</A>


yaoydong (1999-12-14 10:55:00)
首先感谢各位大虾这么热心的为我解答.
to cakk:
感谢为我提供了一个框架
to hexi:
您贴的第一个就是avicap21吧,第二个没贴完,请全部贴完好吗

谢谢大家

Hexi (1999-12-14 11:00:00)
你查看源文件就可看到了。

sunstone (2000-01-10 0:51:00)
to hexi:
您能给我mail一分avicap21的原码吗? 我现在急用!!! 谢谢
sunstone@263.net

sunstone (2000-01-10 1:26:00)
to hexi:
忘了还要avicap32.dll接口函数说明(vfw.pas)文档
谢谢!
sunstone@263.net

Dick (2000-01-10 8:13:00)
yaoyao, Henxi, Cakk诸位大侠,小弟正在作视频捕捉方面的开发,
请将几位的宝贵冬冬发到这里:
kundeng@163.net
感激涕零叩首10000000000000次!:-)

yaoydong (2000-01-10 10:22:00)
问题已经解决,谢谢各位

Dbjam (2001-01-29 16:53:00)
留一份给我好吗。
dbjam@netease.com

Ironhero (2002-01-29 16:06:00)
上面各位大侠,在捕获帧后,怎么压缩这些数据,再提供一些思路吧!

tuday (2002-03-11 20:52:00)
gz


cAkk-20,CJ-10,Dick-10,Hexi-40,sunstone-10,yaoyao-10,的回答最终被接受。
 
话题1744757的标题是: 请高手指点如何用directshow把实时采集图像压缩为mpeg-1文件?(采集卡不带压缩功能) (100分)
分类:多媒体 oldfly (2003-04-07 12:00:00)
请高手们给点思路嘛!
最好是给点源代码,先谢了!

snappy (2003-04-08 18:49:00)
要想存成MPEG文件必须用相关的软件进行转换,用纯软件实时采集MEPG文件是不可能的,
它的压缩速度太慢了,软件跟本就跟不上。

oldfly (2003-04-10 13:53:00)
用directshow中的Filter好象能实现,但我不知怎么做!有高手来指点指点吗?

ww1234ww (2003-04-10 16:23:00)
up

coolsoft (2003-04-10 17:25:00)
为何不压缩为MPEG4呢?
divx可以用呀!

oldfly (2003-04-10 17:43:00)
to coolsoft:
能给我压缩为MPEG4,divx的源代码吗?
最好是dspack2.1实例videocap中实现!
能解决我把我还有的所有分都给你,先谢了!



PHPMySQL (2003-04-11 16:57:00)
where todo
wnload dspack2.1? 3x

my QQ: 2225256

coolsoft (2003-04-11 23:57:00)
oldfly:
其实用divx或者其它的一些xvid压缩很简单!
首先要得到video compressor codec
你可以通过video compressor 来取得其过滤器实例
加入avi mux过滤器,加入file write过滤器
然后再加入到filtergraph中来,
1.你可以用renderstream来智能连接
2.或者connect(pin1,pin2)来人工建立连接
OK,run!你可以得到压缩的AVI文件!


oldfly (2003-04-12 16:29:00)
to coolsoft:
video compressor codec有好多啊,请问压成avi用哪一个要好些,请给点源代码嘛!





wjames (2003-04-12 16:36:00)
到WWW.palyicq.com上去,有好多啊

coolsoft (2003-04-13 22:21:00)
oldfly:
用divx吧!

oldfly (2003-04-14 15:48:00)
to coolsoft:
能给我准确定位divx的方法吗?
就象定位crossbar用
var SysDev:TSysDevEnum;

SysDev:=TSysDevEnum.Create(AM_KSCATEGORY_CROSSBAR);
SysDev.SelectIndexCategory(0);

得到crossbarfilter一样!

我用 SysDev:= TSysDevEnum.Create(CLSID_VideoCompressorCategory);
得到的驱动太多,我都乱不清楚要用哪一个才行!请教了!



coolsoft (2003-04-14 17:57:00)
sysdev:=tsysdevenum.create(clsid_videocompressorcategory);
得到sysdev之后,可以采用遍历的方法来取得
先加一个filter,命名为mycompress,并指定其filtergraph为窗体中的filtergraph控件.
var
filter_compress:ibasefilter;
for i:=0 to sysdev.countfilters-1do

begin

if pos(sysdev.filters(i).friendlyname,'divx')>0 then

begin

mycompress.moniker:=sysdev.getmoniker(i);
break
end;

end;

mycompress.queryinterface(ibasefilter,filter_compress);
然后再按一般的建立filtergraph的方法来建立。
剩下不用我多说了吧!



oldfly (2003-04-14 18:31:00)
我列举出来的compressor中好象没有含divx名的驱动!请问要用divx还需要装什么?
我已经安装了directx8.1了!

coolsoft (2003-04-15 9:42:00)
你可以在网上下载,用google或者百度搜索一下!
它是一个免费的编解码器!


oldfly (2003-04-16 14:06:00)
to coolsoft:
问题解决了!谢谢了!
想再问2个问题:
1、如我想在安装包中含进divx,要如何办?(不想用divx的那个安装程序)
2、我想在程序中把采集的视频存到光盘上,有什么好用的刻录控件
或程序吗?(只刻录数据文件到光盘)

coolsoft (2003-04-16 14:21:00)
1.将divx的dll包含 进你的安装程,并注册!
2.你可以搜索下刻录的相关控件,这类控件挺多的!


coolsoft (2003-04-16 18:24:00)
记得给分呀!:)!

oldfly (2003-04-17 16:10:00)
呵呵,给分了!
想再请教CDWriterXP的操作,我装上了,但不知怎么用,能给我点源代码吗?


coolsoft的回答最终被接受。
 
谢谢weiliu,结贴了
 
多人接受答案了。
 
后退
顶部