.net 从一系列图像创建视频流 (AVI)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1870103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 13:38:18  来源:igfitidea点击:

Create a Video Stream (AVI) from a Series of Images

.netvb.netvideo-streamingjpegavi

提问by Josh Stodola

There is an IP web camera that I wrote a .NET class for sometime ago. It's basically a Timer implementation that pings a snapshot CGI script from the camera every five seconds. The camera itself is very rudamentary; it does not have any sort of API for me to work with, the only thing I can do programmatically (remotely) is invoke this script. The script returns a 640x480 JPEG image. Simple.

有一个 IP 网络摄像头,我前段时间写了一个 .NET 类。它基本上是一个 Timer 实现,它每五秒从相机 ping 一个快照 CGI 脚本。相机本身非常简陋。它没有任何类型的 API 供我使用,我唯一能以编程方式(远程)做的事情就是调用这个脚本。该脚本返回 640x480 JPEG 图像。简单的。

Now what I need to be able to do is take a days worth of these images, and create a "time lapse" AVI video stream out of it that will eventually be embedded into a web page. How can I do this with VB.NET?

现在我需要能够做的是用几天的时间来获取这些图像,然后从中创建一个“时间流逝”的 AVI 视频流,最终将其嵌入到网页中。我怎样才能用 VB.NET 做到这一点?

回答by Simon P Stevens

.net doesn't directly support video formats. Your best option would be to use a 3rd party tool to generate the .avi.

.net 不直接支持视频格式。您最好的选择是使用第 3 方工具生成 .avi。

ffmpeg is one option. You could access it directly via a command line like this:

ffmpeg 是一种选择。您可以通过这样的命令行直接访问它:

ffmpeg -f image2 -i img%d.jpg /output/a.mpg

You would need to name your images img1.jpg, img2.jpg etc. For more details see the ffmpeg faq. You should also find details in the faq for how to output different video formats.

您需要将图像命名为 img1.jpg、img2.jpg 等。有关更多详细信息,请参阅ffmpeg 常见问题解答。您还应该在常见问题解答中找到有关如何输出不同视频格式的详细信息。

You can start a process from vb using Process.Start(). Something like this:

您可以使用Process.Start()从 vb 启动进程。像这样的东西:

Process.Start("ffmpeg.exe", "-f image2 -i img%d.jpg /output/a.mpg")

You could also take a look at ffmpeg-sharpor Tao.FFmpeg, they are .net wrappers for the ffmpeg libraries. I haven't tried either personally, but it looks like it might help you out.

您还可以查看ffmpeg-sharpTao.FFmpeg,它们是 ffmpeg 库的 .net 包装器。我个人还没有尝试过,但看起来它可能会帮助你。

Another alternative would be to take a look at MEncoder, which has similar functionality. You should be able to look up a similar command line for this tool.

另一种选择是查看具有类似功能的MEncoder。您应该能够为该工具查找类似的命令行。

[Related SO question: 271003]

[相关SO问题:271003]

回答by Pekka

FFMpeg has windows binaries and is very popular.

FFMpeg 有 windows 二进制文件,非常受欢迎。

Making movies from image files using ffmpeg/mencoder

使用 ffmpeg/mencoder 从图像文件制作电影

You'll have to check whether the available output formats suit you.

您必须检查可用的输出格式是否适合您。

回答by Crowe T. Robot

This is a C# wrapper by someone at Codeproject:

这是 Codeproject 中某人的 C# 包装器:

http://www.codeproject.com/KB/audio-video/avifilewrapper.aspx

http://www.codeproject.com/KB/audio-video/avifilewrapper.aspx

That wrapper should provide you with what you need.

该包装器应该为您提供所需的东西。

回答by Jermismo

There are several command-line tools that can take a series of images and output an AVI file. I would suggest you call one of them from your app.

有几种命令行工具可以拍摄一系列图像并输出 AVI 文件。我建议您从您的应用程序中调用其中之一。

I would provide links to suggestions, but it has been years since I've used one.

我会提供一些建议的链接,但我已经用了好几年了。

Edit: apparently you can do this using ffmpeg: http://ffmpeg.org/ffmpeg-doc.html

编辑:显然你可以使用 ffmpeg 做到这一点:http: //ffmpeg.org/ffmpeg-doc.html

For creating a video from many images:

ffmpeg -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi

The syntax foo-%03d.jpeg specifies to use a decimal number composed of three digits padded with zeroes to express the sequence number. It is the same syntax supported by the C printf function, but only formats accepting a normal integer are suitable.

从多个图像创建视频:

ffmpeg -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi

语法 foo-%03d.jpeg 指定使用由三个数字填充零组成的十进制数来表示序列号。它与 C printf 函数支持的语法相同,但只有接受普通整数的格式才是合适的。