In Windows, a complete set of video capture functions is provided. To do a video capture software, first create a collection window hcapwnd = capcreatecaptureWindow ((lpstr) "Capture Window", WS_CHILD | WS_VISIBLE, 15, 129, VideoW, VideoH, M_HWND , (int) 0);
The size of the acquisition window is generally related to the camera, then specifies the callback function, this function is used to receive the data acquisition,
FARPROC fpVideoCallback = MakeProcInstance ((FARPROC) VideoCallbackProc, m_hInstance); capSetCallbackOnVideoStream (hCapWnd, fpVideoCallback); if MessageBox ( "Error Not found video card!!") (CapDriverConnect (hCapWnd, 0)!);
Set the video format. ZeroMemory (& m_biInput, sizeof (BITMAPINFO)); m_biInput.bmiHeader.biSize = sizeof (BITMAPINFO); m_biInput.bmiHeader.biWidth = VideoW; m_biInput.bmiHeader.biHeight = VideoH; m_biInput.bmiHeader.biPlanes = 1; m_biInput.bmiHeader.biBitCount = 24; m_biInput.bmiHeader.biCompression = BI_RGB; m_biInput.bmiHeader.biSizeImage = VideoW * VideoH * m_biInput.bmiHeader.biBitCount / 8; m_biInput.bmiHeader.biXPelsPerMeter = 0; m_biInput.bmiHeader.biYPelsPerMeter = 0; m_biInput.bmiHeader.biClrUsed = 0; m_biinput.bmiheader.biClrimportant = 0; capsetVideoFormat (hcapwnd, & m_biinput, sizeof (m_biinput);
Set other parameters, such as frame rates, etc. CAPTUREPARMS CapParam; capCaptureGetSetup (hCapWnd, & CapParam, sizeof (CapParam)); CapParam.fAbortLeftMouse = FALSE; CapParam.fAbortRightMouse = FALSE; CapParam.fYield = TRUE; CapParam.dwRequestMicroSecPerFrame = 1000000/25; // 25 FPS capCaptureSetSetup (hCapWnd, & CapParam Sizeof (capparam); CapoverLay (HcapWnd, True);
Start video capture Time1 = gettickcount (); capcapturequencenofile (hcapwnd);
Stop video capture CapCapturestop (hcapwnd);
Video capture callback function
LRESULT FAR PASCAL VIDEOCALLBACKPROC (HWND HWND, LPVIDEOHDR LPVHDR) {// LPVHDR is a frame of image of data char S [120]; WSPrintf (s, "% ld", frameno ); setdlgitemtext (hmainwnd, idc_capframe, s); if (fpcode) {Memcpy (Encodesrc, LPVHDR-> LPDATA, LPVHDR-> dwbytesused); // MP4 Compressed INT Length = Encencode (EncodeSrc, EncodeDest); // Write AVI File FWRITE (& Length, Sizeof (int), 1, fpcode fwrite (EncodeDest, Length, 1, FPCode);
Time2 = gettickcount (); Word DTime = Word (Time2-Time1); FWRITE (& DTIME, SIZEOF (Word), 1, fpcode); Time1 = gettickcount ();}
Return (LRESULT) TRUE;}
This is a framework for realizing video collections. If you have a specific code, you only write it yourself because the MP4 compression algorithm is now prohibited from exporting. In Windows, it does not contain the algorithm in Windows. This algorithm has only 800 bytes per frame. If Press 15 frames per second to handle, and transmitted on the Internet should be implemented. If the H263 protocol is used, the amount of data will be smaller, but the image sharpness will fall a lot.