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;
            }
  • 相关阅读:
    poj1904 King's Quest
    ACM竞赛须掌握的知识 以及 2个版本的POJ推荐 @ NKOJ discuss 转载的
    poj1466
    C++23中设计模式的factory模式
    poj3667 hotel
    poj1505 Copying Books
    在linux系统中安装VSCode(Visual Studio Code)
    Spring_的jar详细说明
    java开发问题总结4Maven使用问题汇总
    线程同步之信号量(sem_init,sem_post,sem_wait)
  • 原文地址:https://www.cnblogs.com/dint/p/8422690.html
Copyright © 2011-2022 走看看