首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用c# Accord .Net录制网络摄像头的视频和音频

使用c# Accord .Net录制网络摄像头的视频和音频
EN

Stack Overflow用户
提问于 2017-11-15 18:52:26
回答 1查看 3.1K关注 0票数 2

我正在尝试完成一件简单的事情:使用Accord .net框架将视频和音频(从网络摄像头)录制成avi文件。它看起来比看起来更复杂:)

到目前为止,我使用这个帧处理程序很好地处理了视频帧:

代码语言:javascript
运行
复制
void videoDevice_NewFrame(object sender, Accord.Video.NewFrameEventArgs eventArgs)
        {

            System.Drawing.Image imgforms = (Bitmap)eventArgs.Frame.Clone();
            BitmapImage bi = new BitmapImage();
            bi.BeginInit();

            MemoryStream ms = new MemoryStream();
            imgforms.Save(ms, ImageFormat.Bmp);
            ms.Seek(0, SeekOrigin.Begin);

            bi.StreamSource = ms;
            bi.EndInit();

            //Using the freeze function to avoid cross thread operations 
            bi.Freeze();

            //Calling the UI thread using the Dispatcher to update the 'Image' WPF control         
            Dispatcher.BeginInvoke(new ThreadStart(delegate
            {
                pbox.Source = bi; /*pbox is the name of the 'Image' WPF control*/
            }));

            if (_recording)
            {
                long currentTick = DateTime.Now.Ticks;
                StartTick = StartTick ?? currentTick;
                var frameOffset = new TimeSpan(currentTick - StartTick.Value);

                double elapsedTimeInSeconds = stopwatch.ElapsedTicks / (double)Stopwatch.Frequency;
                double timeBetweenFramesInSeconds = 1.0 / 25;
                if (elapsedTimeInSeconds >= timeBetweenFramesInSeconds)
                {
                    stopwatch.Restart();
                    try
                    {
                        _writer.WriteVideoFrame(eventArgs.Frame, frameOffset);
                    }catch(Exception ex)
                    {

                    }

                    //Here come WriteAudioFrame(Signal signal) ?
                }

            }

        }

并且音频数据被存储在音频新帧事件处理器中的存储器流/ WaveEncoder中:

代码语言:javascript
运行
复制
audio_stream = new MemoryStream();           
audio_encoder = new WaveEncoder(audio_stream);

void audioDevice_NewFrame(object sender, Accord.Audio.NewFrameEventArgs eventArgs)
        {

            audio_encoder.Encode(eventArgs.Signal);

        }

所以现在,我不知道如何转换音频内存流(或WaveEncoder ?)在上一个3.8.2版本的.Net预发行版中,@cesarsouza编写的新方法所需的信号对象:

代码语言:javascript
运行
复制
_writer.WriteAudioFrame(Signal signal)

以及如何同步视频和音频。我怀疑我们需要根据采样率获得相同数量的音频和视频帧。

你知道怎么做的例子吗?

非常感谢

EN

回答 1

Stack Overflow用户

发布于 2018-08-14 01:52:58

您可以使用WaveDecoder

代码语言:javascript
运行
复制
WaveDecoder decoder = new WaveDecoder();
Signal s = decoder.Decode();
_writer.WriteAudioFrame(s);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47305500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档