• DxPackNet 4.保存音视频为本地avi文件


    捕获到了音视频后要保存到本地文件,这是很常见的应用场景,DxPackNet保存视频文件也比较简单

    用 IAviStreamWriter  avi文件写入流即可

    1.初始化相关设备,设定好数据捕获的回调函数

            DxDeviceCollection cameras;
            IDxCameraCapture camCapture;
            IDxMicrophCapture microphone;
            IAviStreamWriter aviWriter;
            private void Form1_Load(object sender, EventArgs e)
            {
                cameras = DxFactory.CreateDxCompent<DxDeviceCollection>(DxDeviceCollection.ENVIRONMENT_CAMERAS);
                camCapture = DxFactory.CreateDxCompent<IDxCameraCapture>(this, panel1);
                camCapture.FrameCb = camerasFrameCb;
                camCapture.Init(cameras[0]);
                microphone = DxFactory.CreateDxCompent<IDxMicrophCapture>(100);
                microphone.AudioCb = auCaptureBufferCB;
            }

    2.创建avi写入流 打开设备

            private void button1_Click(object sender, EventArgs e)
            {
                button1.Enabled = false;
                //创建avi文件写入流 第一个参数为-写入文件路径  第二个参数为-是否支持音频写入,true为音/视频,false为只写视频
                aviWriter = DxFactory.CreateDxCompent<IAviStreamWriter>("c:\avicaptest.avi", true);
                aviWriter.Width = 640;//设置视频宽度
                aviWriter.Height = 480;//设置视频高度
                aviWriter.CompressType = AviVideoCompressType.MicrosoftVideo1; //设置视频压缩格式
                aviWriter.Open();//打开写入流
                microphone.Open();
                microphone.Start();
                camCapture.Run();
            }

    3.在回调中写入音/视频 数据

            private void auCaptureBufferCB(byte[] buffer, int length)
            {
                //写入音频数据 
                aviWriter.WriteWavBuffer(buffer, length);  
            }
            private void camerasFrameCb(byte[] buffer, int size)
            {
                //写入视频数据
                aviWriter.WriteBmpBuffer(buffer, Math.Max(size, 640 * 480 * 3));
            }
            private void button2_Click(object sender, EventArgs e)
            {
                button2.Enabled = false;
                microphone.Stop();
                camCapture.Stop();
                aviWriter.Dispose();//写入完了记得关闭流
                aviWriter = null;
            }
  • 相关阅读:
    sharepoint部署
    继承实体类出现传值时值不能保留
    面试经历
    sharepoint更换数据库链接
    asp.net c# 打开新页面或页面跳转
    sharepoint中配置工作流
    AD添加组织单位
    常用正则表达式
    删除多级非空目录
    C#实现对Word文件读写
  • 原文地址:https://www.cnblogs.com/dint/p/8422690.html
Copyright © 2020-2023  润新知