如何将 RGBA 值流编码为视频?
更具体地说: 我有一个 32 位无符号 RGBA 像素序列 - 例如,从左像素开始每行 640 个整数,从顶行开始每帧 480 行,重复 n 帧。有没有一种简单的方法可以将其提供给 ffmpeg(或其他编码器),而无需先将其编码为通用图像格式?
我假设 ffmpeg 是我在这种情况下使用的最佳工具,但我愿意接受建议(输出视频格式并不重要)。
我知道如果我知道正确的关键字,文档会启发我...以防万一我问错了问题,这就是我在最高级别上尝试做的事情:
我有一些 Actionscript 代码可以在其上进行绘制和动画显示树,我已将其包装在逐帧绘制 BitmapData 的 AIR 应用程序中。 AIR 已被证明在直接编码此输出方面效率极低 - 我所管理的最好的是每秒几帧,并且我需要渲染至少 15 fps,最好更像 100 fps,当我向其提供 PNG 图像(AIR 可能需要 1 秒以上的时间来编码一张 640x480 png...令人震惊)。我可以将原始字节数据以渲染的速度发送到编码器或磁盘,而不是在 AIR 内进行编码。
如果您想知道为什么我使用 Actionscript 来渲染动画或者为什么必须快速对其进行编码,请不要这样做。可以说,帧是在执行时计算的(例如,不作为动画存储在 .swf 文件中),我有大量的视频要创建,而且时间有限,并且使用除无法使用 Actionscript 来生成帧。
More specifically:
I have a sequence of 32 bit unsigned RGBA integers for pixels- e.g. 640 integers per row starting at the left pixel, 480 rows per frame starting at the top row, repeat for n frames. Is there an easy way to feed this to ffmpeg (or some other encoder) without first encoding it to a common image format?
I'm assuming ffmpeg is the best tool for me to use in this case, but I'm open to suggestions (the output video format doesn't matter too much).
I know the documentation would enlighten me if I just knew the right keywords... In case I'm asking the wrong question, here's what I'm trying to do at the highest level:
I have some Actionscript code that draws and animates on the display tree, and I've wrapped it in an AIR application that draws BitmapData frame-by-frame. AIR has proved to be woefully inefficient at directly encoding this output- the best I've managed is a few frames per second, and I need to render at least 15 fps, preferably more like 100 fps, which I get out of ffmpeg when I feed it PNG images (AIR can take 1+ seconds to encode one 640x480 png... appalling). Instead of encoding inside AIR I can send the raw byte data out to an encoder or to disk as fast as it's rendered.
If you're wondering why I'm using Actionscript to render an animation or why it has to be encoded quickly, don't. Suffice it to say, the frames are computed at execution time (not stored as an animation in a .swf file, for example), I have a very large amount of video to create and limited time to do so, and using something other than Actionscript to produce the frames is not an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出的解决方案是使用 x264 而不是 ffmpeg。
出于测试目的,我将帧保存为文件:00.bin、01.bin、.. nn.bin,包含 640x480x4 ARGB 像素值。我用来验证该方法是否可行的命令是以下可怕的 hack:
丑陋的 perl 代码片段中有一个交换四字节字节顺序的 hack,因为 x265 只能采用 BGRA 而我的测试文件包含 ARGB。
简而言之,
The solution I've come up with is to use x264 instead of ffmpeg.
For testing purposes, I saved frames as files: 00.bin, 01.bin, .. nn.bin, containing 640x480x4 ARGB pixel values. The command I used to verify that the approach is feasible is the following horrible hack:
The ugly perl snippet in there is a hack to swap four-byte endian order, since x265 can only take BGRA and my test files contained ARGB.
In a nutshell,