zoukankan      html  css  js  c++  java
  • 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;
            }
  • 相关阅读:
    软件/环境的注册码
    js图片延迟加载如何实现
    http状态码
    关于深拷贝(含数组对象)
    javascript继承方式详解
    使用寄生构造函数 创建类
    前端知识点大全【转载】
    统一addEventListener与attachEvent中this指向问题
    sublime text全程指南【转载】
    函数防抖与节流[转载]
  • 原文地址:https://www.cnblogs.com/dint/p/8422690.html
Copyright © 2011-2022 走看看