Video Capture and play

Capture video in machine A -> transfer the data on internet  -> play the data on machine B
This article will cover follow point:
  • Capture video on windows system( Video For Windows API)
  • Capture video related callback function
  •  Play the captured data
 
Basic routine of capture video and send it on internet
 
1. Create the capture window:
hWndC = capCreateCaptureWindow (
  "My Own Capture Window",  // the name used for the capture window
WS_CHILD | WS_VISIBLE , 
0, 0, 160, 120,                        // window size and position
hwndParent,  // Note: the hwndParent MUST NOT NULL, and the parent window should be visable.
nID
);
 The hWndC will show as a child window in the parent widow, this child window will show the video.
 
2. Get the video drive
you can call the function several times until it returned FALSE to retrieve all the video drives installed on your system. This function call is optional.
 
BOOL VFWAPI capGetDriverDescription(
 WORD wDriverIndex, // Index of the capture driver. The index can range from 0 through 9 
 LPSTR lpszName,         // capture driver name    
 INT cbName,               // Length of lpszName , in bytes,      
 LPSTR lpszVer,            // description of the capture driver   
 INT cbVer                   // Length of lpszVer, in bytes         
);
 
3. connect to the specific driver
wDriverIndex can be one of the value you get above, or you can just use 0 to indicate using the 1st driver, so the calling of the function above is optional.
 
capDriverConnect (hWndC, wDriverIndex);
 
4. Setup the CAPTUREPARMS
optional, you may not setup
 
CAPTUREPARMS captrurePrams;
BOOL capCaptureGetSetup(hWndC, &captrurePrams, sizeof(CAPTUREPARMS) );
 
captrurePrams.fCaptureAudio = FALSE;
captrurePrams.fYield = TURE;
BOOL capCaptureSetSetup(hWndC, &captrurePrams, sizeof(CAPTUREPARMS) );
 
5. Setup the video format
optional, you may not setup
 
DWORD capGetVideoFormat(
 hwnd,          
 psVideoFormat, 
 wSize          
);
 
BOOL capSetVideoFormat(
 hwnd,          
 psVideoFormat, 
 wSize          
);
 
6. Don’t save a AVI file on local disk
only send the data out from internet
 
BOOL capCaptureSequenceNoFile(
 hwnd 
);
 
7. Set the Callback On VideoStream
This function called when a video buffer is filled.
 
BOOL capSetCallbackOnVideoStream(
 hwnd, 
 fpProc
);
 
The call back function:
 
LRESULT CALLBACK capVideoStreamCallback(
 HWND hWnd,        
 LPVIDEOHDR lpVHdr 
);
 
The data is stored in LPVIDEOHDR.
 
A example of this callback:
LRESULT CALLBACK capVideoStreamCallback(HWND hWnd, LPVIDEOHDR lpVHdr )
{
     // pseudocode:
    Codec.encode(lpVHdr-> lpData, lpVHdr ->dwBytesUsed, encodedData) ;
    Send( encodedData);
}
 
8. start capture
capCaptureSequence (hWndC);
PS: capPreview(hWndC,true) can be set before start capture.
 
9. stop the capture
BOOL capCaptureStop(
 hwnd 
);
 
10 Disconnect from the driver
BOOL capDriverDisconnect(hWndC);
 
 
 
Basic routine of play the video data from the sending above
1. Init DIB for drawing
HDRAWDIB hdrawdib = ::DrawDibOpen(VOID);
 
2.Changes parameters of a DrawDib DC or initializes a new DrawDib DC.
BOOL DrawDibBegin(
 HDRAWDIB hdd,           //Handle to a DrawDib DC
 HDC hdc,                //Handle to a DC for drawing. This parameter is optional
 int dxDest,              
 int dyDest,              
 LPBITMAPINFOHEADER lpbi, 
 int dxSrc,                
 int dySrc,               
 UINT wFlags              
);
 
3. Drawing
BOOL DrawDibDraw(
 HDRAWDIB hdd,            
 HDC hdc,                 
 int xDst,                
 int yDst,                
 int dxDst,               
 int dyDst,                
 LPBITMAPINFOHEADER lpbi, // bmpinfo->bmiHeader
 LPVOID lpBits,            // this is the BMP data ready to draw       
 int xSrc,                
 int ySrc,                
 int dxSrc,               
 int dySrc,                
 UINT wFlags              
);
 
4.End and close DIB
::DrawDibEnd(hdrawdib);
::DrawDibClose(hdrawdib);
 
Later may write detail on codec the data and play the data using H.263
 
Knowledge or APIs not covered in Video For Windows API:
 
Capture Driver Capabilities
Video Dialog Boxes
Preview and Overlay Modes
Streaming Capture from an MCI Device
Working with Palettes
User Data Messages
Using Video Capture
 
Video Capture Reference
Video Capture Functions
Video Capture Structures
Video Capture Messages
Video Capture Macros
 
You can search the keywords above to get more in MSDN
 
PS: you may include the header or lib
Vfw.h
#pragma comment(lib,"vfw32")
#pragma comment(lib,"winmm")
 
Referece
MSDN 2008

 http://www.gentle.it/alvise/AVICAP.TXT

03/09/2008 add:

Elabrate on the struct of CAPTUREPARMS. see the definition from MSDN:

typedef  struct  
    DWORD dwRequestMicroSecPerFrame; 
    BOOL  fMakeUserHitOKToCapture; 
    UINT  wPercentDropForError; 
    BOOL  fYield; 
    DWORD dwIndexSize; 
    UINT  wChunkGranularity; 
    BOOL  fUsingDOSMemory; 
    UINT  wNumVideoRequested; 
    BOOL  fCaptureAudio; 
    UINT  wNumAudioRequested; 
    UINT  vKeyAbort; 
    BOOL  fAbortLeftMouse; 
    BOOL  fAbortRightMouse; 
    BOOL  fLimitEnabled; 
    UINT  wTimeLimit; 
    BOOL  fMCIControl; 
    BOOL  fStepMCIDevice; 
    DWORD dwMCIStartTime; 
    DWORD dwMCIStopTime; 
    BOOL  fStepCaptureAt2x; 
    UINT  wStepCaptureAverageFrames; 
    DWORD dwAudioBufferSize; 
    BOOL  fDisableWriteCache; 
    UINT  AVStreamMaster; 
}
 CAPTUREPARMS; 

dwRequestMicroSecPerFrame

the number of frames that are captured each second of a capture session, The default value of dwRequestMicroSecPerFrame is 66667, which corresponds to 15 frames per second.

fMakeUserHitOKToCapture

 You can provide the user with precise control over when to start a capture session by setting this member to TRUE. AVICap displays a dialog box after allocating all video and audio buffers for a capture session. This lets the user eliminate capture delays because of software initialization. If your application uses a small number of video buffers, this dialog box is probably unnecessary. The default value is FALSE

wPercentDropForError

One way to measure video quality is to limit the number of captured frames dropped during the capture operation. When streaming capture has finished, the quality value is compared with the ratio of dropped frames to totalframes. If the percentage of dropped frames is greater than the value of the wPercentDropForError member of the CAPTUREPARMS structure, AVICap sends an error message to the error callback function if it is installed.

fYield

MSDN on this is detail enough.

dwIndexSize

The default index size is 34,952 entries(allowing 32K frames and a proportional number of audio buffers).
The chunk granularity is a logical block size for an AVI file that is used for writing and retrieving audio and video data chunks. When writing audioand video chunks to disk, AVICap adds filler chunks (RIFF "JUNK" chunks) asnecessary to fill each logical block of data. From MSDN: Maximum number of index entries in an AVI file. Values range from 1800 to 324,000. If set to 0, a default value of 34,952 (32K frames plus a proportional number of audio buffers) is used.Each video frame or buffer of waveform-audio data uses one index entry. The value of this entry establishes a limit for the number of frames or audio buffers that can be captured.

Other pls refer MSDN

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值