Content book
1. Video capture quick start 2
Second. Basic capture settings 3
1. Set capture speed: 3
2. Set the termination capture 4
3. Captured time limit 4
3. About capture window 4
1. Create an Avicap capture window 5
2. Connect a capture window to the capture device 5
3. The interaction of the parent window and the sub-window 5
4. Capture of the window 6
IV. Video capture drive and audio driver 6
1. Video capture driver performance: 6
2. Video dialog: 6
3. Preview and Overlay Mode: 7
4. Video format 7
5. Video capture setting 7
6. Voice Format 8
Fives. Use video capture 8
1. Create a Creating A Capture Window 8
2. Connect to the capture drive (Connecting to a Capture Driver) 9
3. Enume all installed capture drivers (Enumerating Installed Capture Drivers) 9
4. Get the performance of capture drive (Obtaining the Capabilities of a Capture Driver 9
5. Get the status of the capture window (Obtaining the Status of a Capture Window) 10
6. Display dialog box Set Video Features (Displaying Dialog Boxes To Set Video Characteristics) 10
7. Get and set up the video format (Obtaining and setting the video format) 11
8. Previewing video (Previewing Video) 12
9. Set the video to Overlay mode 12 (ENABLING Video Overlay) 12
10. Name Capture File (Naming The Capture File) 12
11. Formatting Audio Capture 12
12. Change video capture settings (Changing a video capture setting) 13
13. Capturing Data 13
14. Add an Information Block (Adding An Information Chunk) 14
15. Add a callback function (Add Callback Functions to An Application) 14
16. Create a status callback function (CREATING A STATUS CALLBACK FUNCTION) 16
17. Create a buffer return function (CREANG AN Error Callback Function) 17
18. Create a frame callback function (Creating a frame callback function) 18
six. Change four standard dialogs into function call form 18
Audioformat dialog 19
VideoFormat dialog 19
Videosource dialog 20
Video Compression dialog 20
Forehead
Video capture refers to capturing audio and video information by a dedicated video capture card, and then processes them, and then processes the software compression, and these data can be saved, played back, and transmits various operations such as operations.
Windows specializes in Video for Windows to support video processing, and the provided interface can be supported by most video capture cards, and has a variety of video compression drive options (of course video compression can be developed), capture card support camera, Variety inputs such as TV.
I. Video capture is getting started
Video capture digitizes a video stream and audio stream, then stores on a hard disk or other storage medium. A Avicap View handle describes the details of the audio and video streams, which makes your application from the AVI file format, audio video buffer Management, low-level audio video driving access, etc., Avicap provides a flexible interface for the application, you can use the following lines to add your program to your program:
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);
A macro is actually using SendMessage, but only provides a more readable code, the following example is to use the macro method to capture the video to join the program:
HWNDC = CapcreateCaptureWindow ("My Own Capture Window,
WS_CHILD | WS_Visible, 0, 0, 160, 120, hwndparent, NID);
CapdriverConnect (hwndc, 0);
Capcapturesequence (HWNDC);
When you create an Avicap class capture window and connect it to a video driver, this capture window can start capturing data, your program can simply send the WM_CAP_SEQUENCE message (or use the CapCaptureSequence macro) to start capture.
If it is the default setting, WM_CAP_SEQUENCE will start capturing video audio streams to the Capture.avi file until an event below occurs:
Users pressed the ESC key or a mouse button
Your application terminates or abnormally interrupts capture operations
Disk is full
In an application, you can send a WM_CAP_STOP message to terminate the capture data (or use the CapCapturestop macro), you can also send a WM_CAP_ABORT message (or use the CapCaptureAbort macro) to terminate.
II. Basic capture settings
Basic capture settings include: setting the capture speed (how many frames are captured per second), whether to capture audio, capture buffer, allowing maximum loss, how to use DOS memory, and which key of the keyboard or which key to terminate capture and many more. These basic settings can be described using the CaptureParams structure, you can use the CapCapturegetSetup macro to get the current setting, then change the member variable of this structure, and then use the CapCaptureTsetUP macro to set up new settings.
E.g:
1. Set capture speed:
Capture speed refers to capturing the number of frames captured per second, you can send a WM_CAP_GET_SEQUENCE_SETUP message (or use the CapCapturegetSetup macro) to get the current capture speed, the current capture speed is saved in the DWRequestMICROSECPERFRAME member variable of the CaptureParams structure, you can set it This variable changes the current settings, the unit is a number of frames per millisecond, you can send a WM_CAP_SET_SEQUENCE_SETUP message (or using the CapCapturetSetup macro), DWRequestMICROSECPERFRAME's value is 6666, equivalent to 15 frames per second.
2. Set the termination capture
You can allow the user to press a key or a key button or a key button to terminate a capture task. If it is a real-time capture, the captured file will be discarded; if it is a single-step capture, it is captured before termination The content will be saved. You can get the current settings by sending a WM_CAP_GETQUENCE_SETUP message (or using the CapCapturegetSetup Macro), the current button settings are saved in the Vkeyabort member of CaptureParams, and the current mouse settings are saved in the FabortleFTMouse and FabortrightMouse. You can Set the new button or button combination, or the left and right keys, when you modify CaptureParams, you should send the WM_CAP_SET_SEQUENCE_SETUP message to update (or use the CapCapturetSetup macro). The default button is VK_EScape. You must use the registerhotKey function before specifying the button. The value of the mouse default is FabortleFTMouse and FabortrightMouse to True.
3. Captured time limit
The flimitenabled in the CaptureParams structure indicates whether there is a time limit, and the wtimelimit indicates the maximum duration, the unit is second.
Get the value of flimitenabled and wtimelimit can send a WM_CAP_GET_SEQUENCE_SETUP message (or use the CAPCATUREGETSETUP macro), when these member variables are set, the message WM_CAP_SET_SEQUENCE_SETUP message (or CapCapturetSetup macro) is sent to update the CaptureParams structure.
III. About capture windows
Creating a capture window must be created before capture, and this window needs to be used during the send message or using the macro.
1. Create an Avicap capture window
You can use the CapCreateCaptureWindow function to create an Avicap capture window, which will return a handle that will be used when the message is sent later.
You can create one or more capture windows in a program, then connect each window to different capture settings.
2. Connect a capture window to the capture device
You can dynamically connect or disclose or disclose a capture device before you can send a WM_CAP_DRIVER_CONNECT message to connect a capture window or associated with a capture device. When you connect, you can capture the device by capturing the window Send a variety of messages.
If you have multiple capture devices in your system, you can use the wparam parameter when sending a WM_CAP_DRIVER_CONNECT message, which is used, this parameter is one of the lists registered in the [Drivers] section of the System.ini file. 0 is the first.
You can use the CapGetDriverDescription function to get the name and version of the installed capture device so your program can list all installed capture devices and drivers so that users can choose one of them to connect to your capture window.
You can send a WM_CAP_DRIVER_GET_NAME message (or CAPDRIVERGETNAME macro) to get the name of the capture device connected to the capture window, get the version sends a WM_CAP_DRIVER_GET_VERSION message (or CapdrivergeTVersion Macro)
You can send a WM_CAP_DRIVER_DISCONNECT message (or CAPDRIVERDISCONNECT macro) to disconnect.
3. The interaction of the parent window and the sub-window
Some system-level messages like WM_Palettechanged and WM_QueryneWPalette can only be sent to the top-level window or Overlapped window. If a capture window is a sub-window, you must transfer it through the parent window.
Similarly, if the size of the parent window changes, it needs to notify the capture window. Conversely, if the size of the capture window changes, the capture window needs to send a message to the parent window, a simple method is to always maintain the size of the window. The size of the video stream is consistent and the size of the change will be notified the parent window at any time.
4. Capture the state of the window
You can send a WM_CAP_GET_STATUS message (or CapGetStatus macro) to get the status of the current capture window, which is a copy of a CapStatus structure, which contains the size of the picture, the current location of the reel, whether it is set. Because Capstatus information is dynamic Your program should be refreshed as long as the size or format of the captured video stream should be changed (for example, after displaying the video format of the capture device).
Changing the size of the capture window does not affect the size of the actual captured video stream, the format dialog of the video capture device captures the size of the frequency flow.
IV. Video capture driver and audio drive
1. Video capture driver performance:
You can get the hardware performance of the currently connected video-driven hardware performance by sending a WM_CAP_DRIVER_GET_CAPS message (or CAPDRIVERGETCAPS macro). The information obtained is saved in the CapdriverCaps structure.
2. Video dialog:
Each video driver provides four dialogs to control video capture and digitization, define compressed quality, etc., which are defined in the video capture drive.
The Video Source dialog is used to control all video sources for this video capture card connection (typical, for example: SVHS and synthetic input), and provides changing tones, contrast, saturation. If video driver Support this dialog box, you can display and update it, use the WM_CAP_DLG_VIDEOSOURCE message (or CAPDLGVIDEOSOURCE Macro).
The Video Format dialog defines the size and accuracy of the video frame and the compression setting of the video capture card. If the card is supported, you can send a message WM_CAP_DLG_VIDEOFORMAT message or (CAPDLGVIDEOFORMAT Macro).
Video Display dialog controls the display on the display during video capture, which does not affect video digital data, but they may affect the form of performance of digital signals, for example, if the capture device supports Overlay, it may allow for changing tone and saturation , Key color or overlay queue. If the card is supported, you can send a WM_CAP_DLG_VIDEODISPLAY message (or use the Capdlgvideodisplay macro).
The Video Compression dialog controls the compressed quality, if the card is supported, send a message WM_CAP_DLG_VIDEOCOMPRESSION (or CapdlgvideoCompression Macro).
3. Preview and Overlay Mode:
A video capture drive has two working modes for the input video stream: Preview mode and OverLay mode, if a capture drive can perform two methods, the user can select one.
The Preview Mode is sent to the data memory from the captured hardware and use the graphic device interface (GDI) to display the digitized frame in the capture window. The application can slow down the display speed when the parent window will lose the focus, when the focus is obtained Speed up the display speed, this mode should take up a lot of CPU time.
There are three messages control preview operations:
WM_CAP_SET_PREIVEW message (CAPPREVIEW Macro) Allowed or disabled PREVIEW mode
WM_CAP_SET_PREVIEWRATE (CAPPREVIEWRATE Mob) Set the speed when the frame is displayed in the Preview mode.
WM_CAP_SET_SCALE (CAPPREVIEWSCALE Macro) Allows or disables the Zoom ratio of Preview video.
When Preview and Scaling use, the captured video frame will automatically zoom according to the size of the capture window, allowing the Preview mode to automatically turn off the Overlay mode.
Overlay mode is a hardware function that feeds the data to the capture buffer so that the CPU resource is not occupied. You can send a message WM_CAP_SET_OVERLAY (or Capoverlay Mob) to enable or terminate the Overlay mode to the capture window, allowing the Overlay mode to automatically disable the Preview mode.
You can also send a WM_CAP_SET_SCROLL message (or CapsetscrollPos Macro) in the Preview Mode or Overlay mode to set the client zone reel of the video frame.
4. Video format
You can get the size of the structure or structure of the video format by sending a WM_CAP_GET_VIDEOFORMAT message (or CapGetVideoFormat, and CapGetVideoFormatSize Macro). You can set the video format by sending a CAP_SET_VIDEOFORMAT message (or CapSetVideoFormat Macro) .5. Video capture settings
The CaptureParms structure contains control parameters for video capture flow, you can do the following tasks:
Specified number
Specify how much video buffer
Allow or prohibit audio capture
Specifies the time interval of capture
Specifies whether to use MCI settings (VCR or VIDEODISC) during capture
Specifies the keyboard or mouse of the termination stream
Specify The Type of Video Averaging Applied During Capture.
Get: WM_CAP_GET_SEQUENCE_SETUP message (or CapCapturegetSetup Macro)
Setting: WM_CAP_SET_SEQUENCE_SETUP message (or CapCaptureetSetup Macro)
6. Audio format
You can get the format or size format current captured audio data by sending a WM_CAP_GET_AUDIOFORMAT message (or CapGetaudioformat Macro). The default sound format is: mono, 8-bit, 11kHz PCM. When you use WM_CAP_GET_AUDIOFORMAT, always use the WaveFormatex structure.
Set the Send Message WM_CAP_SET_AUDIOFORMAT message (or CapsetAudioformat Macro), you can transfer WaveFormat, WaveFormatex, PCMWAVEFORMAT structure pointers.
Fives. Use video capture
1. Create a capture window (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. Connect to the capture drive (Connecting to a Capture Driver)
The following example is to connect the MSVideo driver to the handle of the HWNDC, and then call the CapdriverDisconnect macro to disconnect.
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. Enume all installed capture drives (Enumerating Installed Capture Drivers)
The following example uses the CapGetDriverDescription function to get the name and version of the installed capture driver:
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 the let the user select a driver to use.
}
}
4. Get the performance of capture-driven (Obtaining the capabilities of a capture driver)
Sending a WM_CAP_DRIVER_GET_CAPS message can be captured, and saves a CapdriverCaps structure. Whenever the program connects a new capture to a capture window, you should update the CapDriverCaps structure. The following program illustrates how to use CapdrivergetCaps Macro Capture of the driver:
Capdrivercaps Capdrvcaps;
SendMessage (hWndc, WM_CAP_DRIVER_GET_CAPS,
Sizeof (CapdriverCaps), (LONG) & CAPDRVCAPS
// OR, Use The Macro to Retrieve The Driver Capabilities.
// CapdrivergetCaps (HWNDC, & CAPDRVCAPS, SIZEOF (CAPDRIVERCAPS));
5. Get the status of the capture window (Obtaining The Status of a Capture Window)
The following example uses the setWindowPos function to keep the capture window with the video stream size, and the basic information of the video stream is used in the CapStatus structure using the CapGetStatus macro.
Capstatus capStatus;
CapgetStatus (HWNDC, & CapStatus, Sizeof (Capstatus));
SetwindowPos (HWNDC, NULL, 0, 0, Capstatus.uiImageWidth,
Capstatus.uiimageHeight, SWP_NOZORDER | SWP_NOMOVE;
6. Display dialog box Set Video Features (Displaying Dialog Boxes To Set Video Characteristics)
Each video capture card typically provides three different dialogs for controlling video capture and digital processing. The following example shows how to display these dialogs, using CapdriveRgetCaps macro to check the CapdriverCaps structure before displaying these dialogs. Testing the card has a display of these dialogs:
Capdrivercaps Capdrvcaps;
CapdrivergeTcaps (HWNDC, & CAPDRVCAPS, SIZEOF (CAPDRIVERCAPS);
// Video Source Dialog Box.
Capdrivercaps.fhasdlgvideSource
CapdlgvideSource (HWNDC);
// Video format Dialog Box.
IF (Capdrivercaps.FhasdlgVideoFormat)
{
CapdlgVideoFormat (HWNDC);
// Are the 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. Get and set up the video format (Obtaining and setting the video format)
The length of the BitmapInfo structure is adapted to both standards and compressed data formats. All programs must always ask this structure to allocate memory before getting the current video format. The following example is to use CapGetVideoFormatSize macro to get buffer size And call the CapGetVideoFormat macro to get the current video format.
LPbitmapInfo lpbi;
DWORD DWSIZE;
DWSIZE = CapGetVideoFormatSize (HWNDC);
LPBI = GlobalAllocptr (GHND, DWSIZE);
CapGetVideoFormat (HWNDC, LPBI, DWSIZE);
// Access the video format and the free the allocated memory.
The program can send a BitMapInfo header structure to the capture window using the CapSetVideoFormat macro (or WM_CAP_SET_VIDEOFORMAT message) because the video format is the details of the device, and your program should check the return value to determine if this format is accepted.
8. Previewing Video
The following example uses the CAPPREVIEWRATE macro to set up a frame every 66 milliseconds and use the CappreView macro to place it in the capture window.
CAPPREVIEWRATE (HWNDC, 66); // Rate, in MilliseConds
CAPPREVIEW (HWNDC, TRUE); // Starts Preview
// preview
CAPPREVIEW (HWND, FALSE); // Disables Preview
9. Set the video to overlay mode (Enabling video overlay)
The following example: CAPDRIVERGETCAPS macro determines if this capture card has an overlay function, if you use macro to set it
Capdrivercaps Capdrvcaps;
CapdrivergeTcaps (HWNDC, & CAPDRVCAPS, SIZEOF (CAPDRIVERCAPS);
IF (Capdrvcaps.Fhasoverlay)
CapoverLay (hwndc, true);
10. Naming Capture File (Naming the Capture File)
The following example: Use the CapFileSetCaptureFile macro to specify the preparation file name: Mycap.avi, the CapFileAlloc macro pretken its size 5m.
Char szcapturefile [] = "mycap.avi";
CapFileSetcaptureFile (HWNDC, SZCAPTureFile);
CapfileAlloc (HWNDC, (1024L * 1024L * 5);
11. Formatting Audio Capture
The following example uses CapsetAudioformat to set the audio format: 11kHz, PCM 8-bit, stereo
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. Change Video Capture Settings (Changing a Video Capture Setting)
The following example uses the CapCapturegetSetUp and CapCapturetSetup macro to change the number of captured frames from the default 15 frames 10 frames per second.
CaptureParms CaptureParms;
Float framespersec = 10.0;
CapcapturegetSetup (HWNDC, & CaptureParms, Sizeof (CaptureParms);
CaptureParms.dwrequestmicrosecPerFrame = (DWORD) (1.0E6 / framespersec);
CapcaptureetSetup (HWNDC, & CaptureParms, Sizeof (CaptureParms);
13. Capturing Data
The following example uses the CapCaptureSequence macro to start capturing videos and using CapFileSaves macro to copy captured data to the newfile.avi file.
Char sznewname [] = "newfile.avi";
// set up the capture operation.
Capcapturesequence (HWNDC);
// Capture.
CapFilesaves (HWNDC, SZNEWNAME);
14. Add an Information block (Adding An Information Chunk)
If you need to add your additional information in the audio and video data captured by your program, you can create a message block and insert them into the capture file, and the information block can contain some typical information, such as copyright information, video source , External location information, etc. The following example uses the CapFileSetInfochunk macro to insert an information block, which contains a SMPTE time code.
// this Example Assumes the Application Controls
// The Video Source for PREROLL AND POSTROLL.
CapInfochunk CIC;
//.
//.
//.
CIC.FCCINFOID = INFOTYPESMPTE_TIME;
CIC.LPDATA = "00: 20: 30: 12";
Cic.cbdata = strlen (cic.lpdata) 1;
CapfilesetInfochunk (HWNDC, & CIC);
15. Add a callback function (Add Callback functions to an application)
A program can register a callback function for the capture window to notify the program in these cases.
Status change
Error occurrence
Video frames and audio buffers become available
Program application receives during capture of the video stream
The following example creates a capture window and registering status, error, video stream, and frame callback function in the message processing parallel, including a description of the termination callback function.
Case WM_CREATE:
{
Char Achdevicename [80]
Char AchdeviceVersion [100]
Char Achbuffler [100]
Word WDRIVERCOUNT = 0
Word WINDEX
Word Werror
Hmenu Hmenu
// Create a Capture Window Using The CapcreateCaptureWindow Macro.
GHWNDCAP = CapcreateCaptureWindow ((lpstr) "Capture Window",
WS_CHILD | WS_VISIBLE, 0, 0, 160, 120, (HWND) hWnd, (int) 0); // register the error callback function using
// 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. - STREAM CALLBACK FUNCTION
// CapsetCallbackonvideStream Macro.
CapsetCallbackOnvideStream (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 osther
// Callback functions.
CapsetCallbackOnframe (HWNDC, NULL);
Break;
}
16. Create a status callback function (CREATING A STATUS CALLBACK FUNCTION)
The following example is to create a simple status callback function, register this callback function using the CapsetCallbackOnStatus macro.
// 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, "Status #% D:% S", NID, LPSTATUSTEXT);
SetwindowText (GHWndmain, (LPSTR) Gachbuffer;
Return (LRESULT) TRUE;
}
17. Create a buffetback function (Creating An Error Callback Function)
The following example is to create a simple error parallel function, register this callback function to use CapsetCallbackONERROR Macro:
// 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, "Error #% D", NERRID);
Messagebox (hwnd, lPerrortext, Gachbuffer,
MB_OK | MB_ICONEXCLAMATION;
Return (LRESULT) TRUE;
}
18. Create a frame callback function (CREANG A FRAME CALLBACK FUNCTION)
This callback function is registered using CapsetCallbackonframe Macro:
// 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, "Preview Frame #% LD", GDWFramenum );
SetwindowText (GHWndmain, (LPSTR) Gachbuffer;
Return (LRESULT) TRUE
}
six. Change four standard dialogs into function call form
The system provides four standard dialogs: Audioformat, Video Compression, but sometimes programs want to control them through the function, rather than using the single dialog box provided by the system, at which time the function call should be used:
Audioformat dialog
It can be implemented by using CapsetAudioFormat, and this time you want to use the WAVEFORMATEX structure.
For example: change to PCM format, stereo, 16 channels, 12.05kHz, then:
Waveformatex audioformat;
/ / Determine the width
ACMMETRICS (NULL, ACM_METRIC_MAX_SIZE_FORMAT, & DWSIZE);
DWSIZE = Max (dwsize, capGetaudioformatsize (m_hwcapcapturing);
// Setting parameters
Audioformat.wformattag = Wave_FORMAT_PCM;
Audioformat.nchannels = 2;
Audioformat.nsamplespespec = 120500;
Audioformat.wbitsPersample = 16;
Audioformat.nblockAlign = nbitspersample * nchannels / 8; audioformat.navgbytespesec =
Audioformat.nblockAlign * nsamplespespec;
// Update
Capsetaudioformat (GhcapWnd, & Audioformat, dwsize);
VideoFormat dialog
You can be implemented by using CapSetVideoFormat. At this point you want to use the BitmapInfoHeader structure.
For example: Set the picture size is RGB24, size is 230x160
BitmapInfoheader Bi;
DWORD DWSIZE, DW;
bi.bisize = sizeof (bitmapinfohead);
bi.biwidth = 320; // work
bi.biheight = 160; // work
Bi.Biplanes = 1;
Bi.biBitcount = 24;
Bi.Bicompression = BI_RGB;
Bi.bisizeImage = 0;
bi.bixpelspermeter = 176;
Bi.biypelspermeter = 144;
Bi.bi.biRused = 0;
Bi.Biclrimportant = 0;
Dwsize = bi.bisize (bi.biBitcount> 8 || bi.biclrused)? (bi.bi.biBitry): (2 ^ bi.bibitcount * sizeof (paletteentry)));
DW = CapsetVideoFormat (M_HWCapcapturing, & Bi, DWSIZE);
VideSource dialog
There is no ready-made method, but there is a dynamic link library in the CD provided by the video capture card to be implemented.
Video Compression dialog
You can unite with functions such as iCOPEN, ICIINFO, get a list of video compressed drives in the current system, and you can select one of the MSDNs to demonstrate this user, the program name: icwalk.
-------------------------------------------------- ------------------------------
Develop video capture programs with Delphi
East China University School 2000 Graduate Class 342 Mailbox (344000) Yang Rui
-------------------------------------------------- ------------------------------
Video capture technology is applied in many software (such as video conferencing, video calls, etc.) development. Microsoft provides software developers with a VFW (Video for Windows) SDK specifically used for video capture. The VFW SDK provides a standard interface to implement video capture in the Windows system, which greatly reduces the development difficulty of programs. Since only VFW SDK has only VC and VB, no Delphi version, you need to declare each function and variable in DLL in Delphi (you can refer to the function declaration of VC in MSDN). This section 3 details how to use VFW to develop video capture programs in Delphi.
Introduction to VFW
VFW is a package that Microsoft introduced on digital video in 1992, which enables applications to get digital video clips from traditional analog video sources through digital devices. A key idea of VFW is that there is no need for a dedicated hardware when it is present, in order to solve the problem of large number of digital video data, the data needs to be compressed. It introduces a file standard called AVI, which does not specify how to capture, compress and play with video, and specify how video and audio are stored on the hard disk, and alternately store video frames and related to the AVI file. Match audio data. VFW allows programmers to capture, play and edit video clips by sending messages or setting properties. In the Windows 9x system, when the user installs the VFW, the installer automatically installs the components required to configure the video, such as device drivers, video compression programs, and the like.
VFW is mainly composed of the following six modules:
● Avicap.dll: Contains functions that perform video capture, which gives the I / O process and video of the AVI file, and the audio device driver provides an advanced interface;
● MSVideo.dll: Contains a special DrawDib function to handle video operations on the screen;
● mciavi.drv: including the driver of the MCI command interpreter for the VFW;
● Avifile.dll: Contains a higher command provided by the standard multimedia I / O (MMIO) function, uses to access the .avi file;
● Compression Manager (ICM): Video Compression / Umbrace Code Codulator (CODEC) for Managing;
● Audio compression manager ACM: Provides services similar to ICM for waveform audio.
Development steps
Avicap window supports real-time video stream capture and single frame capture and provides control over the video source. Although MCI also provides digital video services (such as the video of the video that is displayed .avi files), the overlay command set is provided for the video superposition, but these commands are based primarily on file-based operations, they cannot meet real-time The video cache is required to take the data, and the command set provided by MCI is unable to capture the video stream for the PC that does not have a video superimposed capture card. The Avicap window class has a certain advantage in capturing the video, it can directly access the video buffer, do not need to generate an intermediate file, very powerful, and high efficiency. Moreover, it can capture digital video into a file.
1. Create a "capture window"
You must create a "capture window" before performing video capture, and perform all capture and setting operations based on it. "Capture Window" is created with the "CapCreateCaptureWindow" function of the Avicap window, and its window style is generally WS_CHILD and WS_VISIBLE.
Capture window is similar to standard controls (such as buttons, list boxes, etc.) and has the following features:
● Cat video streams and audio streams into an AVI file;
● Connect or disconnect with video and audio input devices;
● Real-time display of the input video stream in Overlay or Preview mode;
● When captured, you can specify the file name used and copy the contents of the capture file to another.
● Set the capture rate;
● Display dialog box for control video sources, video formats, video compression;
● Create, save, or load palette;
● Copy the image and related palette to the clipboard;
● Save the captured single frame image as files in DIB format.
2. Association capture window and driver
One capture window separately defined is unable to work, it must be associated with a device, so that the video signal can be obtained. With function CAPDriverConnect enables a capture window to associate with a device driver.
3. Set the properties of the video device
The sampling frequency, interrupt sampling buttons, state behavior, and the like can be controlled by setting the various member variables of the TcaptureParms structure variable. After setting the TcaptureParms structure variable, you can use the function CapCaptureetSetUp to make the settings take effect. You can also use CAPPREVIEWSCALE, CAPPREVIEWRATE to set the proportion and speed of the preview, or you can directly use the default value of the device.
4. Open preview
Use the function Capoverlay to choose whether to use the superimposed mode preview, which takes up the system resources, and the video display speed is fast. Then start the preview function with the CappreView, then you can see images from the camera on the screen.
A basic video capture program can be created through steps above. However, if you want to process the video data that has been captured from the device, you should use the capture window callback function to obtain video data or in a stream, such as one frame, and the like.
Instance programming
The role of each function will be described as an example with a frame one frame, one frame, captures the Delphi program of video data, as an example, and the development process.
The function of the program is to be visible to the video on the screen, and image data of each frame can be obtained.
Create a new project and include Avicap32.pa to Uses.
Place a TPANEL control on Form1, set NAME to "GCAPVideoarea", which is used to display video. Place two TBUTTON controls, a name is "OpenVideo", another name is "closevideo".
Define global variables:
VAR
/ / Define the capture window handle
GHCAPWND: THCAPWND: THCAPWND:
/ / You can get the structural variable of the video data pointer, used in the callback function
Videostr: LPVIDEOHDR;
// Table for setting the structure variable of the device attribute
Capparms: TcaptureParms;
Write the following code in the Click event of Name "OpenVideo" TButton:
Procedure TFORM1.OpenvideoClick (Sender: TOBJECT);
Begin
// Use the TPANEL control to create a capture window
GHCAPWND: = CapcreateCaptureWindow
(PCHAR ('KruWosoft'), // Capture the name of the window
WS_CHILD or WS_VISIBLE, / / Window Style
0, // x coordinate
0, // y coordinate
gcapvideoarea.width, // Window Wide
gcapvideoarea.height, // High window
gcapvideoarea.handle, // Window handle
0); // is usually 0
{In order to capture the video frame, start a capture frame callback function videostreamcallback. Use the following functions when capturing a video stream or the current device status:
// Capture a video stream
CapsetCallbackonvideStream;
// Get a device error
CapsetCallbackONERROR;
// Get a device status
CapsetCallbackOnStatus
}
/ / Define a frame capture callback function
CapsetCallbackonframe (GhcapWnd, Longint (@VideStreamCallback);
// Associate a capture window with a device driver, the second parameter is a serial number, when a plurality of visual drivers are installed in the system, their values are 0 to total numbers.
CapdriverConnect (GHCAPWND, 0);
/ / Set the structural variable of the device properties
CAPPARMS.DWREQUESTMICROSECPERFRAME: = 40000;
Capparms.flimitenabled: = false;
Capparms.fcaptureaudio: = false; // no audiocapparms.fmCicontrol: = false
Capparms.Fyield: = true;
Capparms.vkeyabort: = vk_escape;
Capparms.fabortleftmouse: = false;
Capparms.faBorTrightMouse: = false;
/ / Make the settings
CapcaptureetSetup (GhcapWnd, Longint (@capparms), sizeof (tcaptureparms));
/ / Set the proportion of preview
CAPPREVIEWSCALE (GHCAPWND, 1);
/ / Set the frame frequency at the preview
CAPPREVIEWRATE (GHCAPWND, 66);
// If you want to capture a video stream, you should use a function to specify that you do not generate a file. Otherwise, AVI file will be automatically generated.
Capcapturequencing; GhcapWnd;
/ / Specify whether to use a superimposed mode, use it to 1, otherwise 0
Capoverlay (GHCAPWND, 1);
// Open preview
CAPPREVIEW (GHCAPWND, 1);
END;
Write the following code in the Click event of Name "Closevideo" TButton:
Procedure TFORM1.CLOSEVIDEOCLICK (Sender: TOBJECT);
Begin
// Stop capture
Capcaptureabort (GHCAPWND);
// Disconnect the capture window with the drive
Capdriverdisconnect (GHCAPWND);
END;
Define capture frame callback function:
Function framecallback (hwnd: hwnd; lpvhdr: longint): longint; stdcall;
VAR
DataPoint: ^ Byte;
Diblen, RectWidth, RectHeight: Integer;
Begin
/ / Convert the pointer obtained from the callback function
VideoTr: = lpvideohdr (LPVHDR);
// Get the returned data size
DIBLEN: = videostr ^ .dwbufferLength;
GetMem (DataPoint, 64000);
/ / In one memory, pay attention to DataPoint to allocate space
CopyMemory (DataPoint, Videostr ^ .lpdata, Diblen);
// Some other processing
......
END;
Flexible use of the callback function of the Avicap window class can meet a variety of different needs, but pay attention to the format of the video data captured from the video card and the parameters of the video card. Moreover, some video cards can support multiple formats and images long width by setting, so pay attention to the parameters of the video card used when the image is restored.
-------------------------------------------------- ------------------------------
Video capture, AviumNit Unit1;
Interface
Useswindows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, stdctrls
typeTForm1 = class (TForm) Panel1: TPanel; OpenVideo: TButton; CloseVideo: TButton; GrabFrame: TButton; SaveBMP: TButton; StartAVI: TButton; StopAVI: TButton; SaveDialog1: TSaveDialog; procedure FormCreate (Sender: TObject); procedure OpenVideoClick (Sender : TObject); procedure CloseVideoClick (Sender: TObject); procedure GrabFrameClick (Sender: TObject); procedure SaveBMPClick (Sender: TObject); procedure StartAVIClick (Sender: TObject); procedure StopAVIClick (Sender: TObject); private {Private declarations} hWndC : Thandle; Capturingavi: Bool; Public {public Declarations} END; VARFORM1: TFORM1
IMPLEMENTATION
{$ R * .dfm}
const WM_CAP_START = WM_USER; const WM_CAP_STOP = WM_CAP_START 68; const WM_CAP_DRIVER_CONNECT = WM_CAP_START 10; const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START 11; const WM_CAP_SAVEDIB = WM_CAP_START 25; const WM_CAP_GRAB_FRAME = WM_CAP_START 60; const WM_CAP_SEQUENCE = WM_CAP_START 62; const WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START 20;
function capCreateCaptureWindowA (lpszWindowName: PCHAR; dwStyle: longint; x: integer; y: integer; nWidth: integer; nHeight: integer; ParentWin: HWND; nId: integer): HWND; STDCALL EXTERNAL 'AVICAP32.DLL';
Procedure tform1.form; begincapturingavi: = false; hwndc: = 0; savedialog1.Options: = [offideReadOnly, OFNOCHANGER, OFPATHMUSTEXIST] end;
procedure TForm1.OpenVideoClick (Sender: TObject); beginhWndC: = capCreateCaptureWindowA ( 'My Own Capture Window', WS_CHILD or WS_VISIBLE, Panel1.Left, Panel1.Top, Panel1.Width, Panel1.Height, Form1.Handle, 0); if HWNDC <> 0 ThensendMessage (HWNDC, WM_CAP_DRIVER_CONNECT, 0, 0); END;
procedure TForm1.CloseVideoClick (Sender: TObject); beginif hWndC <> 0 then beginSendMessage (hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0); hWndC: = 0; end; end; procedure TForm1.GrabFrameClick (Sender: TObject); beginif hWndC <> 0 THENSENDMESSAGE (HWNDC, WM_CAP_GRAB_FRAME, 0, 0); END;
procedure TForm1.SaveBMPClick (Sender: TObject); beginif hWndC <> 0 then beginSaveDialog1.DefaultExt: = 'bmp'; SaveDialog1.Filter: = 'Bitmap files (* .bmp) | * .bmp'; if SaveDialog1.Execute thenSendMessage ( HWNDC, WM_CAP_SAVEDIB, 0, Longint (Pchar (Savedialog1.FileName));
procedure TForm1.StartAVIClick (Sender: TObject); beginif hWndC <> 0 then beginSaveDialog1.DefaultExt: = 'avi'; SaveDialog1.Filter: = 'AVI files (* .avi) | * .avi'; if SaveDialog1.Execute then beginCapturingAVI : = True; SendMessage (HWNDC, WM_CAP_FILE_SET_CAPTURE_FILEA, 0, LONGINT (Pchar (Savedialog1.FileName)); SendMessage (HWNDC, WM_CAP_SEQUENCE, 0, 0); END; END;
Procedure TForm1.stopaviclick (Sender: TOBJECT); Beginif HWNDC <> 0 THEN BEGINSENDMESSAGE (HWNDC, WM_CAP_STOP, 0, 0); Capturingavi: = FALSE; END;
End.