在C#中渲染图像序列以制作视频

时间:2022-10-29 21:19:55

I have a sequence of jpg images that I am capturing and rendering to the screen to create a video.

我有一系列jpg图像,我正在捕捉并渲染到屏幕上以创建视频。

I am decompressing the image from a MemoryStream using a JpegBitmapDecoder and rendering it by setting the Source on an Image control. This seems to work okay, but the processor overhead is pretty high. The images are 1280x720, running at 30fps and I can just barely keep up on my computer ( Dual Core 2.8Ghz). Running at higher resolutions cause me to throw away frames. I would like to try to get the cpu utilization down.

我正在使用JpegBitmapDecoder从MemoryStream解压缩图像,并通过在Image控件上设置Source来渲染它。这似乎工作正常,但处理器开销很高。这些图像是1280x720,运行速度为30fps,我几乎无法跟上我的电脑(双核2.8Ghz)。以更高的分辨率运行会导致我丢掉帧。我想尝试降低cpu利用率。

Most of the time spent spent seems to be in the decoding (simple benchmarks of the decoding alone on my machine put show that I can decode about 40fps). Does anyone know if there is a faster decoder available (DirectX? DirectShow? Something I can offload to the video card?)

花费的大部分时间似乎都在解码中(仅在我的机器上解码的简单基准测试表明我可以解码大约40fps)。有没有人知道是否有更快的解码器可用(DirectX?DirectShow?我可以卸载到视频卡吗?)

As for the rendering, it doesn't seem like the Image control is designed for this type of use (I was actually surprised it worked at all, i just tried it because it was easy to do). Is there another way to render the individual frames that might be faster?

至于渲染,似乎Image控件不是为这种类型的使用而设计的(我实际上对它起作用感到惊讶,我只是尝试了它,因为它很容易做到)。是否有另一种方法来渲染可能更快的单个帧?

1 个解决方案

#1


It sounds like you are both decoding and resizing the jpeg at the same time. The resizing can be expensive too. Try separating decoding and resizing (using the cheapest algorithm available) the jpegs. Use something like FreeImage with "JPEG_FAST" to decompress and "FILTER_BOX" to resize.

听起来你在同时解码和调整jpeg的大小。调整大小也很昂贵。尝试分离解码和调整大小(使用最便宜的算法)jpegs。使用像FreeImage这样的“JPEG_FAST”进行解压缩,使用“FILTER_BOX”来调整大小。

For display, TinyPTC is simple and fast. (a wrapper around DirectDraw) It is C, but it is pretty easy to write a wrapper for and compile to a dll you can reference.

为了显示,TinyPTC简单快捷。 (DirectDraw的包装)它是C,但是编写一个包装器并编译到你可以引用的dll非常容易。

#1


It sounds like you are both decoding and resizing the jpeg at the same time. The resizing can be expensive too. Try separating decoding and resizing (using the cheapest algorithm available) the jpegs. Use something like FreeImage with "JPEG_FAST" to decompress and "FILTER_BOX" to resize.

听起来你在同时解码和调整jpeg的大小。调整大小也很昂贵。尝试分离解码和调整大小(使用最便宜的算法)jpegs。使用像FreeImage这样的“JPEG_FAST”进行解压缩,使用“FILTER_BOX”来调整大小。

For display, TinyPTC is simple and fast. (a wrapper around DirectDraw) It is C, but it is pretty easy to write a wrapper for and compile to a dll you can reference.

为了显示,TinyPTC简单快捷。 (DirectDraw的包装)它是C,但是编写一个包装器并编译到你可以引用的dll非常容易。