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 quick start video capture digitizes a video stream and audio stream, then stored 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 AVI File format, audio video buffer management, low-rise audio video driving access, etc., Avicap provides a flexible interface for the application, you can use the following lines to add video 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 add video capture to the program: hwndc = capcreatecaptureWindow ("My Own Capture Window", WS_CHILD | WS_VISIBLE , 0, 0, 160, 120, hwndparent, NID); CapdriverConnect (HWNDC, 0); CapCapturequence (HWNDC); This capture window is created when you create an Avicap class capture window and connect it to a video driver You 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 to the capture.avi file until one of the following The event occurs: the user presses the ESC key or a mouse button. Your application termination or exception interrupt capture operation disk is full in an application, you can send a WM_CAP_STOP message to terminate the capture data (or use Capcapturestop Macro), you It is also possible to seize the WM_CAP_ABORT message (or using the CapCaptureabort macro) to terminate. II. Basic capture settings Basic capture settings include: Setting the capture speed (how many frames capture per second), whether to capture the audio, capture buffer, allowed maximum loss How many frames, whether DOS memory is used, and which key or the mouse in the keyboard is used to terminate the capture, etc. 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.
For example: 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 change the current setting by setting this variable, the unit is a number of frames per millisecond, you can send a WM_CAP_SET_SEQUENCE_SETUP message (or use the CapCapturetSetup macro), the value of dwrequestmicrosecPerFrame is 66667, equivalent to 15 frames per second. 2. Setting Termination Capture You can allow the user to press a key or a key button or the left and right keys of the mouse 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, before termination The captured 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 FabortleFTMouse and Fabortrightmouse members. . You can set the new button or button combination, or the left and right keys, when you modify the 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 be specified before the button Using the RegisterhotKey function, the value of the mouse default is that FabortleFTMouse and FabortRightmouse are True.3. The captured time limits the flimitenabled in the CaptureParams structure indicating whether there is a time limit. 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) should be sent to update the CaptureParams structure. Three. About the capture window must create a capture window before capture, you need to use this window 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, this handle is used after sending a message. You can create one or more capture windows in a program. , Then connect different capture settings for each window. 2. Connect a capture window to the capture device You can dynamically connect or disclose a capture window, you can send a WM_CAP_DRIVER_CONNECT message to connect a capture window or associated with a capture device. When connecting, you Various messages can be sent to the capture device through the capture window. If multiple capture devices are installed in your system, you can use the wparam parameter when sending a WM_CAP_DRIVER_CONNECT message, this parameter is registered in the System.ini file [Drivers] One item in the list, 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 equipment And drive, 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 parent window interacts with the sub-window Some of the system-level messages that WM_PALETTECHANGED and WM_QUERYNEWPALETTTTE can only be sent to the top-level window or Overlapped window. If a capture window is a sub-window, you must transfer 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 keep the size of the capture window consistent with the size of the video stream, and at any time Inform the parent window of the change in size. 4. The status of the capture window You can send a WM_CAP_GET_STATUS message (or CapGetStatus macro) to get the status of the current capture window, get a copy of a CapStatus structure, 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 may change (for example, after displaying the video format of the capture device). Change the size of the capture window does not affect the actual The size of the captured video stream, the format dialog of the video capture device captures the size of the frequency stream. IV. Video capture driver and audio drive 1. Video capture driver performance: You can get the hardware performance of the currently connected video-driven by sending a WM_CAP_DRIVER_GET_CAPS message (or CAPDRIVERGETCAPS macro). The resulting information 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., these dialogs are defined in the video capture drive. The video capture drive is used to control the selection video source, this The dialog lists all video sources of this video capture card connection (typical, for example: SVHS and synthetic inputs), and provides changing tones, contrast, saturation. If video driver supports this dialog, you can display and update it using WM_CAP_DLG_VIDEOSOURCE message (or macro capDlgVideoSource) size and definition of accuracy .Video Format dialog video frame, the compressed video capture card is provided. If the card supports it, or can send a message WM_CAP_DLG_VIDEOFORMAT message (capDlgVideoFormat macro) .Video Display dialog control This control does not affect video digital data during video capture, but they may affect digital signals. For example, if the capture device supports Overlay, it may allow for changing hue and saturation, key colors or overlay. Queue. If the card is supported, you can send a WM_CAP_DLG_VIDEODISPLAY message (or use the CapdlgvideoDisplay macro). Video Compression dialog controls compression quality, send message WM_CAP_DLG_VIDEOCOMPRESSION (or CapdlgvideoCompression Macro) .3. Preview and Overlay Mode: A video capture driver has two working modes for entering video streams: preview mode and overlay mode, if a capture driver can perform two methods, the user can select a .preview mode to capture hardware from capture hardware The data is sent to the system memory and use the graphics 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 reaches of the focus, speed up the display speed, this mode to CPU time for three preview message control operations:. WM_CAP_SET_PREIVEW message (capPreview macro) enables or disables the preview mode WM_CAP_SET_PREVIEWRATE (capPreviewRate macro) provided when the frame display speed .WM_CAP_SET_SCALE (capPreviewScale macro) in the preview mode, enable or disable video preview Scaling. 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. The Overlay mode is a hardware function. It will send the data into the capture buffer. Do not occupy the CPU resources. You can send a message WM_CAP_SET_OVERLAY (or Capoverlay Mob) to enable or terminate the Overlay mode to the capture window, allow the Overlay mode to automatically disable the preview mode. You can also send a WM_CAP_SET_SCROLL message in the Preview mode or Overlay mode (or CapsetScrollPos Macro) To set the client area reel position 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 these tasks: Specifying frame number Specify how much video buffer allows or disables the audio capture time interval Specify whether to use MCI settings during capture (VCR or videodisc) to terminate the specified stream keyboard or mouse specify the type of video averaging applied during capture obtained:. WM_CAP_GET_SEQUENCE_SETUP message (or capCaptureGetSetup macro) provided: WM_CAP_SET_SEQUENCE_SETUP message (or macro capCaptureSetSetup) 6. Audio format You can get the format or size format of the current capture 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. Creating a Creating a Capture Window hWndc = capcreatecaptureWindow ((lpstr) "My Capture Window", // WINDOW NAME IF POP-UPWS_CHILD | WS_VISIBLE, // WINDOW Style0, 0, 160, 120, / Window Position and Dimensions (HWND) HWNDPARENT, (INT) NID / * Child ID * /); 2. Connected to Captive Drive (Connecting To A Capture Driver) The following example is a capture window that drives MsVideo driver to HWNDC. , Then call 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. Enumeral all installed Capture Drivers, using the CapGetDriverDescription function to get the name of the installed capture driver and version: 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. Get capture driver Obtaining The Capabilities of a Capture Driver Send WM_CAP_DRIVER_GET_CAPS messages to get the performance of the drive, and save it into a CapdriverCaps structure. Whenever the program connects a new capture to a capture window, you should update the CapdriverCaps structure. the program illustrates how capDriverGetCaps macros to obtain capture driver performance: 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 to obtain the state capture window (Obtaining the status of a capture window) the following examples make use of the capture window function SetWindowPos consistent with the size of the incoming video stream, The basic information of the video stream is to use the CapGetStatus macro, saved in the CapStatus structure. CapStatus CapStatus; CapgetStatus (HWNDC, & CapStatus, Sizeof (Capstatus));
SetWindowPos (hWndC, NULL, 0, 0, CapStatus.uiImageWidth, CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE);. 6 displays a dialog box to set the video features (Displaying Dialog Boxes to Set Video Characteristics) Each video capture cards generally provide three Different dialogs are used to control video capture and digitization. The following example shows how to display these dialogs, before displaying these dialogs, using the CapDriveRGetCaps macro to check the CapdriverCaps structure to detect whether the card has these dialogs: 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. Get and set the length of the Obtaining and Setting The Video Format BitmapInfo structure that adapts to both standards and compressed data formats, all programs must always ask this structure to be found to get the current Before the video format is allocated. The following example is to use the CapGetVideoFormatSize macro to get the 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 then free the allocated memory may be used capSetVideoFormat macro program (or WM_CAP_SET_VIDEOFORMAT message) Send a BitMapInfo header structure to the capture window, because the video format is the details of the device, your program should check the return value to determine if this format is accepted. 8. Previewing Video Next Example Using CAPPREVIEWRATE Macro to set each 66 For milliseconds, use the Cappreview macro to place it in the capture window .cappreviewrate (HWNDC, 66); // Rate, in MilliseCondscappreview (hwndc, true); // Starts Preview // PreviewCappReView (hwnd, false); / . / disables preview9 video set to overlay mode (Enabling video overlay) the following example: capDriverGetCaps macro determines this capture whether the card overlay function, if you use a macro to set it CAPDRIVERCAPS CapDrvCaps; capDriverGetCaps (hWndC, & CapDrvCaps, sizeof (CAPDRIVERCAPS ));
If (Capdrvcaps.fhasoverLay) CapoverLay (HWNDC, TRUE); 10. Name Capture File (Naming The Capture File) Next: Using CapFileSetCaptureFile Macro to specify the preparation file name: mycap.avi, CAPFileAlloc macro pretken its size is 5m.
char szCaptureFile [] = "MYCAP.AVI"; capFileSetCaptureFile (hWndC, szCaptureFile); capFileAlloc (hWndC, (1024L * 1024L * 5));. 11 Audio Capture Format (Formatting Audio Capture) The following example uses to set the audio capSetAudioFormat format: 11kHz, PCM 8 bits stereo AVEFORMATEX wfex; wfex.wFormatTag = WAVE_FORMAT_PCM; wfex.nChannels = 2; // Use stereowfex.nSamplesPerSec = 11025; wfex.nAvgBytesPerSec = 22050; wfex.nBlockAlign = 2; wfex.wBitsPerSample = 8; wfex.cbSize = 0; capSetAudioFormat (hWndC, & wfex, sizeof (WAVEFORMATEX));. 12 to change the video capture settings (changing a video capture setting) the following example uses capCaptureGetSetup capCaptureSetSetup and Hong in the captured frames from the default 15 frames per second into 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) The following example uses the CapCaptureSequence macro to start capturing videos and using CapFilesaves macro to copy the captured data to the newfile.avi file. Char sznewname [] = "newfile.avi" ; // set up the capTure Operation.capcaptures EquernCe (HWNDC); // Capture.capfilesaves (HWNDC, SZNEWNAME); 14. Add an Information CHUNK If you need to add your additional information in your program captured, you can Create a message block and insert them into the capture file, 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 one 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 to an application one program can register a capture window The callback function is notified in these cases.
Status Change Error Hays Video Framework and Audio Buffer Benefits Benefits Applications Creating a capture window and registering status, error, video stream, and frame callback function in the message processing, also includes a description .case WM_CREATE termination callback function: {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) "Capture Window", 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 DriverBreak; } 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 create a callback status (Creating a status callback function) the following example is to create a simple state callback, the callback function registered using 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 Creating An Error Callback Function, the following example is to create a simple error parallel function, register this callback function using CapsetCallbackOnError macro: // errorback 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 creates a frame callback (creating a frame callback function) using the registered callback function macros capSetCallbackOnFrame: // FrameCallbackProc: frame callback function // hWnd: capture window handle // lpVHdr: Pointer to Struct Co ntaining 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} 6. Change the four standard dialogs into a function call form system provides four standard dialogs: Audioformat, VideoFormat, VideSource, Video Compression, but sometimes programs want to control them through the function, rather than using the single dialog box provided by the system. At this time, you should use the function called: The Audioformat dialog can be implemented by using CapsetAudioFormat, and the WaveFormatex structure is used.