gpt4 book ai didi

c# - 使用 FFMPEG 进程从 rtsp 获取所有帧

转载 作者:行者123 更新时间:2023-12-04 23:03:48 27 4
gpt4 key购买 nike

运行使用 FFMPEG 读取 RTSP 流的命令的过程,我需要捕获每一帧以将其显示在图片框中;我在 void OnOutputDataReceived(object sender, DataReceivedEventArgs e) 中接收数据,但是一旦我将 e.data 转换为 byte[] 并生成位图,应用程序就会崩溃。

我的代码:

private void Form1_Load_1(object sender, EventArgs e)
{
Process proc = new Process();
proc.StartInfo.FileName = "ffmpeg";
proc.StartInfo.Arguments = "-i rtsp://user:foscam@50.197.211.181:9826/videoMain -an -vcodec mjpeg -s 640x480 -threads 1 -aspect 16:9 -q:v 2 -updatefirst 1 -b:v 64k -f -";
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.OutputDataReceived += OnOutputDataReceived;
if (!proc.Start())
{
Console.WriteLine("Error starting");
return;
}
proc.BeginOutputReadLine();
StreamReader reader = proc.StandardError;
string line;
while ((line = reader.ReadLine()) != null)
{
Console.WriteLine(line);
}
proc.Close();
}

void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
{
byte[] bytes = new byte[e.Data.Length * sizeof(char)];
System.Buffer.BlockCopy(e.Data.ToCharArray(), 0, bytes, 0, bytes.Length);
Bitmap bmp;
using (var ms = new MemoryStream(bytes))
{
// CRASH SITE

bmp = new Bitmap(ms);
}
pictureBox1.Image = bmp;
}

Bytes

Crash

最佳答案

如果您想处理来自相机的图像文件,使用 FFMPEG 并不是最好的方法,因为您在设备和 .NET 代码之间添加了一个独立的层。

您需要使用专门为此而构建的 AFORGE.NET。我为 FOSCAM 相机制作了两个应用程序(一个 Windows 桌面应用程序和一个 WinPhone 7x),AFORGE 是他们的最佳选择。不幸的是,我没有代码了,但尝试使用 AFORGE 代替坚持 FFMPEG(我猜 AFORGE 有用于导出到 FFMPEG 的示例)。

看这里:
http://www.aforgenet.com/framework/

关于c# - 使用 FFMPEG 进程从 rtsp 获取所有帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33048758/

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