C# 如何从 5000 个 PNG 文件创建电影?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1147115/
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
How to create a movie from 5000 PNG files?
提问by Wim ten Brink
Well, simple situation. I've created about 5000 frames as PNG files which I want to display as an animation inside a .NET application. Every image is 1920x1080 in size and the PNG file uses alpha channels for (partial) transparency. And that's going to complicate things a bit, because I would prefer to keep it transparent. (But if that's impossible, I'll just add a background image to every PNG.)
嗯,简单的情况。我已经创建了大约 5000 帧作为 PNG 文件,我想在 .NET 应用程序中将其显示为动画。每个图像的大小为 1920x1080,PNG 文件使用 alpha 通道来实现(部分)透明。这会让事情变得有点复杂,因为我更愿意让它保持透明。(但如果这是不可能的,我只会为每个 PNG 添加一个背景图像。)
Because of the large amount of images, I would need lots of memory. Well, a 1 TB harddisk and a 12 GB Quad-core Intel Xeon system running Vista 64-bits is solving those memory requirements. But unless a tool is created to support 64-bits, it will probably choke after loading perhaps 800 of the 5000 images. So I need a tool that can do this.
由于大量图像,我需要大量内存。好吧,运行 Vista 64 位的 1 TB 硬盘和 12 GB 四核 Intel Xeon 系统正在解决这些内存要求。但是,除非创建一个支持 64 位的工具,否则它可能会在加载 5000 个图像中的 800 个后窒息。所以我需要一个可以做到这一点的工具。
The movie format isn't that important. Neither is compression, as long as the image quality stays high. (And there's a reason why I've used such a huge resolution!) Lossless compression would be preferred, though. My system is fast enough to replay the movie afterwards again so I'm not worried about it's speed. However, image quality is the most important factor here.
电影格式不是那么重要。只要图像质量保持高,压缩也不是。(而且我使用如此大的分辨率是有原因的!)不过,无损压缩将是首选。我的系统足够快,可以在之后再次重播电影,所以我不担心它的速度。然而,图像质量是这里最重要的因素。
So far, I've come up with two options: 1) I find some free tool which can handle this much data. (Free, or very cheap.) 2) I write such a tool myself...
到目前为止,我提出了两个选择:1)我找到了一些可以处理这么多数据的免费工具。(免费,或非常便宜。)2)我自己写了这样一个工具......
Option 1 is a bit out-of-place here. Besides, as a software engineer, my hands are just twitching to write it myself! In C# with preferably no third-party libraries. So my question: - Where to start writing this myself?
选项 1 在这里有点不合适。另外,作为一个软件工程师,我的手都在抽搐着要自己写!在 C# 中最好没有第三方库。所以我的问题: - 从哪里开始自己写这个?
(如果你想知道,这部电影是一部动画,一个年轻女子走在某个城市的街道上,经过几个提到产品特征的标志。在电影结束时,她走向一个更大的标志它显示了产品本身的名称。这是一个长而连续的场景,没有中断。创建起来也很有趣!大约 10 GB 的图像......)
采纳答案by clamp
if you are on windows, you can also look into virtualdub. http://www.virtualdub.org/
如果您在 Windows 上,您还可以查看 virtualdub。 http://www.virtualdub.org/
it can make AVIs from bmps, pngs, etc.
它可以从 bmps、pngs 等制作 AVI。
回答by Falaina
FFMPEG is capable of creating a movie file from a series of image files, this link to their manual shows an example:
FFMPEG 能够从一系列图像文件创建一个电影文件,这个指向他们手册的链接显示了一个例子:
http://ffmpeg.org/ffmpeg-doc.html#SEC5
http://ffmpeg.org/ffmpeg-doc.html#SEC5
As for creating the movie file programaticcaly with no third party libraries... that is going to be a bit more difficult. Many movie formats are tremendously complicated and to create one without an existing library would be pretty painful(unless I misinterpreted your question and you're not actually asking about creating the actual encoder)
至于在没有第三方库的情况下以编程方式创建电影文件……那会有点困难。许多电影格式非常复杂,在没有现有库的情况下创建一种格式会非常痛苦(除非我误解了您的问题并且您实际上并没有询问创建实际的编码器)
If I didn't misinterpret your question, doing a simple implementation of a YUV based movie codec might be doable. HuffYUVis one I'm aware of that might not be too challenging.
如果我没有误解你的问题,做一个基于 YUV 的电影编解码器的简单实现可能是可行的。我知道HuffYUV可能不会太具有挑战性。
回答by rix0rrr
Two things:
两件事情:
- You're notgoing to write a proper video encoder by yourself. Not by a longshot. So your options are either to re-use an existing encoder, or not use an encoder at all.
- No video format will deal with transparency. Either you give all the images a background, or you won't be able to use an existing video format.
- 您不会自己编写合适的视频编码器。不是由一个长镜头。因此,您的选择是重新使用现有编码器,或者根本不使用编码器。
- 没有任何视频格式会处理透明度。要么为所有图像提供背景,要么无法使用现有的视频格式。
There are a couple of solutions that spring to mind:
有几个解决方案浮现在脑海中:
You don't care about size, but you docare about quality. First thing I would ask yourself is: do you really reallynot care about size? Most video formats (especially H.264) will give you excellent quality at a substantially lower file size (think 10x). You will barely be able to tell the difference. Yes, your content is HD, but HD content on TV or Blu-ray is also compressed (using H.264 or VC-1) and it's good enough for everyone else. So I would seriously consider this as an option, as it makes the rest a whole lot easier.
你不在乎大小,但你确实在乎质量。我会问自己的第一件事是:你真的真的不关心大小?大多数视频格式(尤其是 H.264)将以明显较小的文件大小(想想 10 倍)为您提供出色的质量。你几乎无法分辨其中的区别。是的,您的内容是高清的,但电视或蓝光上的高清内容也会被压缩(使用 H.264 或 VC-1),并且对其他人来说已经足够好了。所以我会认真考虑将其作为一种选择,因为它使其余的工作变得更加容易。
If you want, you can always resort to a lossless video format, such as HuffYUV. This will at least give you somecompression, while cutting the size of your video data in half (or more).
如果需要,您可以随时使用无损视频格式,例如HuffYUV。这至少会给你一些压缩,同时将视频数据的大小减少一半(或更多)。
As I said, by using an encoded video format, you lose the transparency. If you want to keep the transparency, and you still don't care about the file size, why not keep the PNGs and display them as a very fast slideshow in your application? If your only problem with this is the memory requirements of loading all PNGs into memory at once... don't do that. Read a couple of frames ahead (a fixed amount or as far as memory allows), and once you've displayed a frame, remove it from memory and read a new frame ahead. That way you get to keep perfect quality and constant memory requirements. The only issue is that your disk and processor will need to be able to keep up with the rate of reading 30 PNGs per second (or whatever your frame rate is).
正如我所说,通过使用编码的视频格式,你会失去透明度。如果您想保持透明度,而您仍然不关心文件大小,为什么不保留 PNG 并将它们显示为您的应用程序中非常快速的幻灯片呢?如果你唯一的问题是一次将所有 PNG 加载到内存中的内存要求......不要这样做。提前读取几帧(固定数量或在内存允许的范围内),一旦显示了一个帧,将其从内存中删除并提前读取一个新帧。这样您就可以保持完美的质量和恒定的内存要求。唯一的问题是您的磁盘和处理器需要能够跟上每秒 30 个 PNG 的读取速度(或任何您的帧速率)。
Additionally, if 5000 separate image files get too unwieldy to handle, you can wrap them all in some custom file format. A ZIP file springs to mind as a simple portable format, or you can roll your own.
此外,如果 5000 个单独的图像文件太笨重而无法处理,您可以将它们全部包装成某种自定义文件格式。ZIP 文件是一种简单的便携式格式,您也可以自己制作。
回答by Serafeim
You can do what you want with mencoder:
你可以用mencoder做你想做的事:
Here's a link from that documentation: Encoding from multiple input image files (JPEG, PNG, TGA, etc.)
这是该文档的链接: Encoding from multiple input image files (JPEG, PNG, TGA, etc.)
About transparency: I don't think that there's a video codec that supports transparenct, so you're out of luck here...
关于透明度:我认为没有支持透明的视频编解码器,所以你在这里不走运......
回答by Nux
Or - if you are on Windows - just use Movie Maker.
或者 - 如果您使用的是 Windows - 只需使用 Movie Maker。
It requires quite a lote of RAM and processing power but is more intuitive then VirtualDub and allows to you to add some simple effects and titles.
它需要相当多的 RAM 和处理能力,但比 VirtualDub 更直观,并允许您添加一些简单的效果和标题。