C# VideoAPI

using System;
using System.Runtime.InteropServices;

public class VideoAPI //视频API类
{

    // 视频API调用

    [DllImport("avicap32.dll")]
    public static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);

    [DllImport("avicap32.dll")]
    public static extern bool capGetDriverDescriptionA(short wDriver, byte[] lpszName, int cbName, byte[] lpszVer, int cbVer);

    [DllImport("User32.dll")]
    public static extern bool SendMessage(IntPtr hWnd, int wMsg, bool wParam, int lParam);

    [DllImport("User32.dll")]
    public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, int lParam);

    // 常量

    public const int WM_USER = 0x400;

    public const int WS_CHILD = 0x40000000;

    public const int WS_VISIBLE = 0x10000000;

    public const int SWP_NOMOVE = 0x2;

    public const int SWP_NOZORDER = 0x4;

    public const int WM_CAP_DRIVER_CONNECT = WM_USER + 10;

    public const int WM_CAP_DRIVER_DISCONNECT = WM_USER + 11;

    public const int WM_CAP_SET_CALLBACK_FRAME = WM_USER + 5;

    public const int WM_CAP_SET_PREVIEW = WM_USER + 50;

    public const int WM_CAP_SET_PREVIEWRATE = WM_USER + 52;

    public const int WM_CAP_SET_VIDEOFORMAT = WM_USER + 45;

    public const int WM_CAP_START = WM_USER;

    public const int WM_CAP_SAVEDIB = WM_CAP_START + 25;

}

public class cVideo //视频类
{
    private IntPtr lwndC; //保存无符号句柄

    private IntPtr mControlPtr; //保存管理指示器

    private int mWidth;

    private int mHeight;

    public cVideo(IntPtr handle, int width, int height)
    {
        mControlPtr = handle; //显示视频控件的句柄
        mWidth = width; //视频宽度
        mHeight = height; //视频高度
    }

    /// <summary>
    /// 打开视频设备
    /// </summary>
    public void StartWebCam()
    {
        byte[] lpszName = new byte[100];
        byte[] lpszVer = new byte[100];
        VideoAPI.capGetDriverDescriptionA(0, lpszName, 100, lpszVer, 100);
        this.lwndC = VideoAPI.capCreateCaptureWindowA(lpszName, VideoAPI.WS_CHILD | VideoAPI.WS_VISIBLE, 0, 0, mWidth, mHeight, mControlPtr, 0);

        if (VideoAPI.SendMessage(lwndC, VideoAPI.WM_CAP_DRIVER_CONNECT, 0, 0))
        {
            VideoAPI.SendMessage(lwndC, VideoAPI.WM_CAP_SET_PREVIEWRATE, 100, 0);
            VideoAPI.SendMessage(lwndC, VideoAPI.WM_CAP_SET_PREVIEW, true, 0);
        }
    }

    /// <summary>
    /// 关闭视频设备
    /// </summary>
    public void CloseWebcam()
    {
        VideoAPI.SendMessage(lwndC, VideoAPI.WM_CAP_DRIVER_DISCONNECT, 0, 0);
    }

    /// <summary>
    /// 拍照
    /// </summary>
    /// <param name="path">要保存bmp文件的路径</param>
    public void GrabImage(IntPtr hWndC, string path)
    {
        IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
        VideoAPI.SendMessage(lwndC, VideoAPI.WM_CAP_SAVEDIB, 0, hBmp.ToInt32());
    }
}
时间: 2024-11-05 04:07:22

C# VideoAPI的相关文章

C#写的一个视频转换解码器

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Drawing; 6 using System.Runtime.InteropServices; 7 using System.Threading; 8 using System.Windows.Forms; 9 using System.IO; 10 11 namespace B

基于腾讯云点播的视频上传和转码功能

在之前的文章中提到过腾讯云储存上传大文件的各种不方便,比如不能转码(要转码得先把mp4文件从云存储上下载下来,然后通过服务器执行ffmpeg操作,最后再把切割的ts文件上传到腾讯云,过程复杂且容易出错),不能获取实时的上传进度等等,所以就发现腾讯云点播这项技术.相对来说通过云点播既能实现上传进度的获取,而且还能上传完成后自动转码,比如自动把mp4转换为m3u8格式的清单文件来进行分片加载,这样子既能大大加快加载速度,还能保护视频链接的url,所以就记录一下这种技术的使用原理. 云点播视频上传Js

C#实例.net_经典例子400个

一共470多例winform 界面特效的源码. 窗体与界面设计... 9 实例001  带历史信息的菜单    10 实例002  菜单动态合并    12 实例003  像开始菜单一样漂亮的菜单... 14 实例004  任务栏托盘菜单    15 实例005  可以拉伸的菜单界面    16 实例006  菜级联菜单    18 1.2  工具栏设计... 19 实例007  带带背景的工具栏    19 实例008  带浮动工具栏    20 实例009  在带下拉菜单的工具栏... 21

C#打开摄像头抓取照片然后退出

其实就是摄像头在后台抓个图,可以用于监控1. [代码][C#]代码using System;using System.Collections.Generic;using System.Text;using System.Diagnostics; namespace MyVideoService{    class Program    {                static void Main(string[] args)        {            cVideo video

手动上下eureka上面服务

手动下eureka curl -X PUT http://eureka.xxx.xxx.com/eureka/apps/VIDEO-API/111.111.111.111:test-api:0000/status?value=OUT_OF_SERVICE 手动上eurekacurl -X DELETE http://eureka.xxx.xxx.com/eureka/apps/VIDEO-API/111.111.111.111:test-api:0000/status?value=UP 原文地址

uniapp 初始化项目

const baseUrl = 'http://10.92.1.17:6601/videoapi/'; //const baseUrl = '/videoapi/'; //对于 GET 方法,会将数据转换为 query string.例如 { name: 'name', age: 18 } 转换后的结果是 name=name&age=18. //对于 POST 方法且 header['content-type'] 为 application/json 的数据,会进行 JSON 序列化. //对于