110,538
社区成员
发帖
与我相关
我的任务
分享
在ClassShowVideo这个类中,我还多了一个CapturePara的结构体,用于设定捕捉视频时的参数
[StructLayout(LayoutKind.Sequential)]
public struct CAPTUREPARAMS
{
public int dwRequestMicroSecPerFrame; // Requested capture rate
public bool fMakeUserHitOKToCapture; // Show "Hit OK to cap" dlg?
public uint wPercentDropForError; // Give error msg if > (10%)
public bool fYield; // Capture via background task?
public int dwIndexSize; // Max index size in frames (32K)
public uint wChunkGranularity; // Junk chunk granularity (2K)
public bool fUsingDOSMemory; // Use DOS buffers?
public uint wNumVideoRequested; // # video buffers, If 0, autocalc
public bool fCaptureAudio; // Capture audio?
public uint wNumAudioRequested; // # audio buffers, If 0, autocalc
public uint vKeyAbort; // Virtual key causing abort
public bool fAbortLeftMouse; // Abort on left mouse?
public bool fAbortRightMouse; // Abort on right mouse?
public bool fLimitEnabled; // Use wTimeLimit?
public uint wTimeLimit; // Seconds to capture
public bool fMCIControl; // Use MCI video source?
public bool fStepMCIDevice; // Step MCI device?
public int dwMCIStartTime; // Time to start in MS
public int dwMCIStopTime; // Time to stop in MS
public bool fStepCaptureAt2x; // Perform spatial averaging 2x
public uint wStepCaptureAverageFrames; // Temporal average n Frames
public int dwAudioBufferSize; // Size of audio bufs (0 = default)
public bool fDisableWriteCache; // Attempt to disable write cache
public uint AVStreamMaster; // Which stream controls length?
}
public void StartWebCam()
{
byte[] lpszName = new byte[100];
byte[] lpszVer = new byte[100];
ClassShowVideo.capGetDriverDescriptionA(0, lpszName, 100, lpszVer, 100);
this.lwndC = ClassShowVideo.capCreateCaptureWindowA(lpszName, showVideo.WS_VISIBLE + showVideo.WS_CHILD, 0, 0, mWidth, mHeight, mControlPtr, 0);
//showVideo.CAPTUREPARAMS CaptureParams = new showVideo.CAPTUREPARAMS();
//this.lwndC = showVideo.capCreateCaptureWindowA(lpszName, showVideo.WS_DISALBED + showVideo.WS_CHILD + showVideo.WS_MINIMIZE, 0, 0, mWidth, mHeight, mControlPtr, 0);
ClassShowVideo.CAPTUREPARAMS CaptureParams = new ClassShowVideo.CAPTUREPARAMS();
if (this.capDriverConnect(this.lwndC, 0))
{
this.cappreviewrate(this.lwndC, 100);
ClassShowVideo.SendMessage(this.lwndC, showVideo.WM_CAP_GET_SEQUENCE_SETUP, Marshal.SizeOf(CaptureParams), ref CaptureParams);
CaptureParams.fAbortLeftMouse = false;
CaptureParams.fAbortRightMouse = false;
CaptureParams.fCaptureAudio = false;
CaptureParams.fYield = true;
//CaptureParams.vKeyAbort = 0;
CaptureParams.dwRequestMicroSecPerFrame = 1000000 / 10;
ClassShowVideo.SendMessage(this.lwndC, ClassShowVideo.WM_CAP_SET_SEQUENCE_SETUP, Marshal.SizeOf(CaptureParams), ref CaptureParams);
this.capPreview(this.lwndC, true);
ClassShowVideo.bitmapinfo bitmapinfo = new ClassShowVideo.bitmapinfo();
bitmapinfo.bmiHeader.biSize = ClassShowVideo.SizeOf(bitmapinfo.bmiHeader);
bitmapinfo.bmiHeader.biWidth = mWidth;
bitmapinfo.bmiHeader.biHeight = mHeight;
bitmapinfo.bmiHeader.biPlanes = 1;
bitmapinfo.bmiHeader.biBitCount = 24;
this.capsetvideoformat(this.lwndC, ref bitmapinfo, ClassShowVideo.SizeOf(bitmapinfo));
//CompressDialog();
this.mFrameEventHandler = new ClassShowVideo.FrameEventHandler(framecallback);
this.capSetCallbackOnFrame(this.lwndC, this.mFrameEventHandler);
ClassShowVideo.SetWindowPos(this.lwndC, 0, 0, 0, mWidth, mHeight, 6);
//showVideo.SetWindowPos(this.lwndC, 0, 0, 0, mWidth, mHeight, 0x80);
}
else
{
throw new Exception("No camera device is detected, please check the camera connection.");
}
}
//录像
private void GetVideo(IntPtr lwnd, string path)
{
IntPtr hVideo = Marshal.StringToHGlobalAnsi(path);
showVideo.SendMessage(lwnd, showVideo.WM_CAP_FILE_SET_CAPTURE_FILEA, 0, hVideo.ToInt32());
showVideo.SendMessage(lwnd, showVideo.WM_CAP_SEQUENCE, 0, 0);
}
//停止录像
private void StopGetVideo(IntPtr lwnd)
{
showVideo.SendMessage(lwnd, showVideo.WM_CAP_STOP, 0, 0);
}