简体   繁体   English

有没有更快的方法使用python和ffmpeg从像素数组生成视频?

[英]Is there a faster way to generate video from pixel arrays using python and ffmpeg?

I've found a few sources which use python and ffmpeg to generate video from pixel arrays by passing the -f rawvideo flag 1 2 . 我发现了一些使用python和ffmpeg通过传递-f rawvideo标志1 2从像素数组生成视频的源。 However, this is very slow for high-definition video since each individual pixel must be piped into ffmpeg. 然而,这对于高清视频来说非常慢,因为每个像素必须通过管道传输到ffmpeg。

In fact this is provably wasteful, as I've found that 2.5Gb of pixel arrays generates about 80Kb of video. 事实上,这可能是浪费,因为我发现2.5Gb的像素阵列产生大约80Kb的视频。 I've also chanced upon some examples where javascript can render high quality animations in near-real time 1 , which makes me even more suspicious that I'm doing something wrong. 我也偶然发现了一些例子,其中javascript可以近乎实时地呈现高质量的动画1 ,这让我更加怀疑我做错了什么。

Is there a way to do this more efficiently, perhaps by piping the differences between pixel arrays into ffmpeg rather than the pixels themselves? 有没有办法更有效地做到这一点,也许是通过将像素数组之间的差异管理到ffmpeg而不是像素本身?

(edit) This is the line I'm using. (编辑) 是我正在使用的线。 Most executions take the else path that follows. 大多数执行采用随后的else路径。

Raw, uncompressed video requires a lot of memory, that is why it should be compressed as early as possible. 原始的,未压缩的视频需要大量内存,这就是为什么它应该尽早压缩。 But the earliest time in your case is when it has reached ffmpeg - you don't want to develop a video encoder. 但在你的情况下,最早的时间是它达到ffmpeg - 你不想开发视频编码器。 Piping in essence is the handover of memory buffers between processes, so there is not be much overhead if this is done right (eg. handing over complete frames instead of small buffers). 管道本质上是进程之间的内存缓冲区的切换,因此如果这样做是正确的(例如,移交完整帧而不是小缓冲区),则没有太多开销。

Rendering an animation is a different task than video compression, so there is no point in comparison. 渲染动画与视频压缩是一项不同的任务,因此没有必要进行比较。

What video compression parameters do you use? 您使用什么视频压缩参数? Show us the complete ffmpeg command line. 向我们展示完整的ffmpeg命令行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM