关于网页播放远程摄像头视频问题
目前本人正在做一个bs项目,需要在页面上播放远程摄像头拍摄的实时画面(局域网内),对面摄像头就是外面买的很普通的摄像头,请问如何实现,跪求高人指点。谢谢 --------------------编程问答-------------------- 听说要媒体服务器啊,是不是很麻烦啊 --------------------编程问答-------------------- 给你看这个 ,希望对你有帮助 。http://www.cnblogs.com/xidongs/archive/2009/07/14/1523617.html --------------------编程问答-------------------- 通讯。。。 远程。WEBQQ有视频否? --------------------编程问答-------------------- 貌似要找摄像头提供商要接口!~~ 来实现!~~ --------------------编程问答-------------------- Activex控件 --------------------编程问答-------------------- 有没有具体的activeX的解决方法啊,能不能贴一个看看 谢谢啊 --------------------编程问答-------------------- 這個有難度幫頂! --------------------编程问答-------------------- --------------------编程问答--------------------
using System;--------------------编程问答-------------------- 需要Activex支持吧
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
namespace CapAvi
{
/// <summary>
/// 一个控制摄像头的类
/// </summary>
public class CamCap
{
private const int WM_USER = 0x400;
private const int WS_CHILD = 0x40000000;
private const int WS_VISIBLE = 0x10000000;
private const int WM_CAP_START = WM_USER;
private const int WM_CAP_STOP = WM_CAP_START + 68;
private const int WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;
private const int WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;
private const int WM_CAP_SAVEDIB = WM_CAP_START + 25;
private const int WM_CAP_GRAB_FRAME = WM_CAP_START + 60;
private const int WM_CAP_SEQUENCE = WM_CAP_START + 62;
private const int WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;
private const int WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63;
private const int WM_CAP_SET_OVERLAY =WM_CAP_START+ 51;
private const int WM_CAP_SET_PREVIEW =WM_CAP_START+ 50;
private const int WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6;
private const int WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2;
private const int WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3;
private const int WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5;
private const int WM_CAP_SET_SCALE=WM_CAP_START+ 53;
private const int WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52;
private IntPtr hWndC;
private bool bStat = false;
private IntPtr mControlPtr;
private int mWidth;
private int mHeight;
private int mLeft;
private int mTop;
/// <summary>
/// 初始化摄像头
/// </summary>
/// <param name="handle">控件的句柄</param>
/// <param name="left">开始显示的左边距</param>
/// <param name="top">开始显示的上边距</param>
/// <param name="width">要显示的宽度</param>
/// <param name="height">要显示的长度</param>
public CamCap(IntPtr handle, int left, int top, int width,int height)
{
mControlPtr = handle;
mWidth = width;
mHeight = height;
mLeft = left;
mTop = top;
}
[DllImport("avicap32.dll")]
private static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);
[DllImport("avicap32.dll")]
private static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize );
[DllImport("User32.dll")]
private static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, long lParam);
/// <summary>
/// 开始显示图像
/// </summary>
public void Start()
{
if (bStat)
return;
bStat = true;
byte[] lpszName = new byte[100];
hWndC = capCreateCaptureWindowA(lpszName,WS_CHILD|WS_VISIBLE ,mLeft,mTop,mWidth,mHeight,mControlPtr,0);
if (hWndC.ToInt32() != 0)
{
SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);
SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);
SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);
}
return;
}
/// <summary>
/// 停止显示
/// </summary>
public void Stop()
{
SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
bStat = false;
}
/// <summary>
/// 抓图
/// </summary>
/// <param name="path">要保存bmp文件的路径</param>
public void GrabImage(string path)
{
IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
SendMessage(hWndC,WM_CAP_SAVEDIB,0,hBmp.ToInt64());
}
/// <summary>
/// 录像
/// </summary>
/// <param name="path">要保存avi文件的路径</param>
public void Kinescope(string path)
{
IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
SendMessage(hWndC,WM_CAP_FILE_SET_CAPTURE_FILEA,0,hBmp.ToInt64());
SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);
}
/// <summary>
/// 停止录像
/// </summary>
public void StopKinescope()
{
SendMessage(hWndC, WM_CAP_STOP, 0, 0);
}
}
}
单纯的web我想没这么强大
--------------------编程问答-------------------- 我这边也正在做跟你类似的功能,我这边调用的是视频设备商的ActiveX,然后通过服务器端的IP,端口号,用户名和密码,才能调用那边的摄像头,看见视频画面,不过我要做成的是四画面形式。 --------------------编程问答-------------------- 我以前写的一个类 你可以参考参考 远程传输其实就是传图片
--------------------编程问答-------------------- from 窗体调用
public class video
{
//5个传入参数
private IntPtr myHand;
private int myWidth;
private short myHeight;
private int myLeft;
private int myTop;
//调用avicap32.dll
public struct videohdr_tag
{
public byte[] lpData;
public int dwBufferLength;
public int dwBytesUsed;
public int dwTimeCaptured;
public int dwUser;
public int dwFlags;
public int[] dwReserved;
}
[DllImport("avicap32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int capCreateCaptureWindowA([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszWindowName, int dwStyle, int x, int y, int nWidth, short nHeight, int hWndParent, int nID);
[DllImport("avicap32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool capGetDriverDescriptionA(short wDriver, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszName, int cbName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszVer, int cbVer);
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool DestroyWindow(int hndw);
[DllImport("user32", EntryPoint = "SendMessageA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int SendMessage(int hwnd, int wMsg, int wParam, [MarshalAs(UnmanagedType.AsAny)] object lParam);
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
[DllImport("vfw32.dll")]
public static extern string capVideoStreamCallback(int hwnd, videohdr_tag videohdr_tag);
[DllImport("vicap32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool capSetCallbackOnFrame(int hwnd, string s);
//自定义参数:
private int hHwnd;
//构造函数
public video(IntPtr myPtr, int left, int top, int width, short height)
{
myHand = myPtr;
myLeft = left;
myTop = top;
myWidth = width;
myHeight = height;
//
// TODO: 在此处添加构造函数逻辑
//
}
//打开视频:
public void opVideo()
{
int intDevice = 0;
string refDevice = intDevice.ToString();
hHwnd = capCreateCaptureWindowA(ref refDevice, 1342177280, 0, 0, 640, 480, myHand.ToInt32(), 0);
if (SendMessage(hHwnd, 0x40a, intDevice, 0) > 0)
{
SendMessage(this.hHwnd, 0x435, -1, 0);
SendMessage(this.hHwnd, 0x434, 0x42, 0);
SendMessage(this.hHwnd, 0x432, -1, 0);
SetWindowPos(this.hHwnd, 1, 0, 0, myWidth, Convert.ToInt32(myHeight), 6);
}
else
{
DestroyWindow(this.hHwnd);
}
}
//停止视频
public void CloVideo()
{
SendMessage(this.hHwnd, 0x40b, 0, 0);
DestroyWindow(this.hHwnd);
}
//捕获视频
public Image CatchVideo()
{
SendMessage(this.hHwnd, 0x41e, 0, 0);
IDataObject obj1 = Clipboard.GetDataObject();
Image getIma = null;
if (obj1.GetDataPresent(typeof(Bitmap)))
{
Image image1 = (Image)obj1.GetData(typeof(Bitmap));
getIma = image1;
}
return getIma;
}
}
--------------------编程问答-------------------- 哦~发错了 我刚才试了下 用这个就行 from1是测试用的 直接用FROM2就可以
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace 摄像头
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const short WM_CAP = 1024;
const int WM_CAP_DRIVER_CONNECT = WM_CAP + 10;
const int WM_CAP_DRIVER_DISCONNECT = WM_CAP + 11;
const int WM_CAP_EDIT_COPY = WM_CAP + 30;
const int WM_CAP_SET_PREVIEW = WM_CAP + 50;
const int WM_CAP_SET_PREVIEWRATE = WM_CAP + 52;
const int WM_CAP_SET_SCALE = WM_CAP + 53;
const int WS_CHILD = 1073741824;
const int WS_VISIBLE = 268435456;
const short SWP_NOMOVE = 2;
const short SWP_NOSIZE = 1;
const short SWP_NOZORDER = 4;
const short HWND_BOTTOM = 1;
int iDevice = 0;
int hHwnd;
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SendMessageA")]
static extern int SendMessage(int hwnd, int wMsg, int wParam, [MarshalAs(UnmanagedType.AsAny)]
object lParam);
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SetWindowPos")]
static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
[System.Runtime.InteropServices.DllImport("user32")]
static extern bool DestroyWindow(int hndw);
[System.Runtime.InteropServices.DllImport("avicap32.dll")]
static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int x, int y, int nWidth, short nHeight, int hWndParent, int nID);
[System.Runtime.InteropServices.DllImport("avicap32.dll")]
static extern bool capGetDriverDescriptionA(short wDriver, string lpszName, int cbName, string lpszVer, int cbVer);
private void OpenPreviewWindow()
{
int iHeight = 320;
int iWidth = 200;
//
// Open Preview window in picturebox //打开预览窗口的PictureBox
//
hHwnd = capCreateCaptureWindowA(iDevice.ToString(), (WS_VISIBLE | WS_CHILD), 0, 0, 640, 480, picCapture.Handle.ToInt32(), 0);
//
// Connect to device 连接到设备
//
if (SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) == 1)
{
//
// Set the preview scale 设置预览规模
//
SendMessage(hHwnd, WM_CAP_SET_SCALE, 1, 0);
//
// Set the preview rate in milliseconds 以毫秒为单位设置预览率
//
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);
//
// Start previewing the image from the camera 从相机启动预览图像
//
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, 1, 0);
//
// Resize window to fit in picturebox 调整窗口大小以适应在PictureBox中
//
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, iWidth, iHeight, (SWP_NOMOVE | SWP_NOZORDER));
}
else
{
//
// Error connecting to device close window 错误连接到设备关闭窗口
//
DestroyWindow(hHwnd);
}
}
private void ClosePreviewWindow()
{
//
// Disconnect from device 断开设备
//
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0);
//
// close window 关闭窗口
//
DestroyWindow(hHwnd);
}
private void button1_Click(object sender, EventArgs e)
{
iDevice = int.Parse("4");
OpenPreviewWindow();
}
private void button2_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.Show();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
using System;--------------------编程问答-------------------- 1、activeX方式,如果摄像头有相应api的话,采用这种方式,实现很简单。如果是普通摄像头,这中方式比较难实现。牵扯视频压缩、传输等。。。还要考虑性能,很复杂。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using YL;
namespace 摄像头
{
public partial class Form2 : Form
{
video v;
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
SaveFileDialog sa = new SaveFileDialog();
sa.Filter = "保存(*.bmp)|*.bmp";
sa.FilterIndex = 2;
sa.RestoreDirectory = true;
if (DialogResult.OK == sa.ShowDialog())
{
Image im = v.CatchVideo();
Bitmap bit = new Bitmap(im);
bit.Save(sa.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
private void button2_Click(object sender, EventArgs e)
{
v = new video(pictureBox1.Handle, 250, 250, 429, 310);
v.opVideo();
}
private void button3_Click(object sender, EventArgs e)
{
v.CloVideo();
}
}
}
2、fms(媒体服务器)方式,网上这方面的资料比较多。资料 --------------------编程问答-------------------- --------------------编程问答-------------------- 谢谢大家帮忙,可是大家发的多数是 api CS的用法,这个我们的C++ 工程师已经写过dll给我们调用了,可是我这边需要在b/s系统的网页上调用,单纯的api是不行的,我在找一个 网页使用的 activeX 控件 --------------------编程问答-------------------- 问题解决没有呀?
我现在也在恼火这种问题! --------------------编程问答-------------------- 我想用手机远程控制摄像头 但是一直没有思路 怎么实现啊
补充:.NET技术 , ASP.NET