gpt4 book ai didi

c# - 使用C#Accord .Net从网络摄像头录制视频和音频

转载 作者:行者123 更新时间:2023-12-02 23:34:59 25 4
gpt4 key购买 nike

我正在尝试实现一些简单的功能,例如:使用Accord .net框架将视频和音频(来自网络摄像头)记录在avi文件中。看起来似乎更复杂:)

到目前为止,我可以使用以下帧处理程序很好地处理视频帧:

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中:
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?)转换为Accord .Net的最新预发行版v3.8.2中@cesarsouza编写的新方法所需的Signal对象:
_writer.WriteAudioFrame(Signal signal)

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

你知道怎么做吗?

非常感谢

最佳答案

您可以使用WaveDecoder

WaveDecoder decoder = new WaveDecoder();
Signal s = decoder.Decode();
_writer.WriteAudioFrame(s);

关于c# - 使用C#Accord .Net从网络摄像头录制视频和音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47305500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com