日期:2014-05-19  浏览次数:20919 次

如何在做一个网络摄像头程序
如何得到视频流,并保存!

------解决方案--------------------
C#捕捉视频头(源码)

using System;
using System.Runtime.InteropServices;

namespace Wuyin.ShoesManager
{
/// <summary>
/// VedioCapture 的摘要说明。
/// </summary>
public class VedioCapture
{
private int hCaptureM;
private bool isUnLoad = false;
public VedioCapture()
{
}
[DllImport( "avicap32.dll ")]
private static extern int capCreateCaptureWindow( string strWindowName, int dwStyle, int x, int y ,int width, int height , int hwdParent, int nID );
[DllImport( "user32.dll ")]
private static extern int SendMessage( int hwnd , int wMsg, int wParam , int lParam );
[DllImport( "user32.dll ")]
private static extern int SendMessage( int hwnd , int wMsg, int wParam , string lParam );
[DllImport( "Kernel32.dll ")]
private static extern bool CloseHandle( int hObject );
public bool Initialize( System.Windows.Forms.Control aContainer , int intWidth, int intHeight )
{
hCaptureM = capCreateCaptureWindow( " ", 0x40000000 | 0x10000000, 0,0,intWidth,intHeight,aContainer.Handle.ToInt32() ,1 );
if( hCaptureM == 0 ) return false;

int ret = SendMessage( hCaptureM , 1034, 0,0 );
if( ret == 0 )
{
CloseHandle(hCaptureM);
return false;
}
//WM_CAP_SET_PREVIEW
ret = SendMessage( hCaptureM, 1074, 1, 0 );
if( ret == 0 )
{
this.UnLoad();
return false;
}
//WM_CAP_SET_SCALE
ret = SendMessage( hCaptureM, 1077, 1, 0 );
if( ret == 0 )
{
this.UnLoad();
return false;
}
//WM_CAP_SET_PREVIEWRATE
ret = SendMessage( hCaptureM, 1076, 66, 0 );
if( ret == 0 )
{
this.UnLoad();
return false;
}
return true;
}

public void SingleFrameBegin()
{
//
int ret = SendMessage( hCaptureM, 1094 , 0,