Video Capture and play
2008-02-26 17:56
1906 查看
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
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
相关文章推荐
- DirectShow play and capture
- DE2 framebuffer and video capture interface for SOPC (altera9.1)
- Still and Video Media Capture
- 学习笔记- AVFoundation Programming Guide - Still and Video Media Capture
- DE2 framebuffer and video capture interface for SOPC (altera11.0)
- Video Game Spaces: Image, Play, and Structure in 3D Worlds
- AVFoundation Programming Guide(官方文档翻译5)Still and Video Media Capture - 静态视频媒体捕获。
- xpe image 中如何显示 non-Plug and Play drivers
- javscript custom object's bubble and capture
- H264 video RTP payload and SDP
- 关于VMUSBArbService跟plug and play
- unity, particle play once and destroy
- Flash, Google, VP8, and the future of internet video
- Play Modules Morphia 1.2.9a 之 Aggregation and Group aggregation
- 10673 - Play with Floor and Ceil
- Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural
- image and video processing听课笔记(二)
- Rip DVD to most video and audio formats
- Conan and Agasa play a Card Game
- State of the "Art": A Taxonomy of Artistic Stylization Techniques for Images and Video(二)