AIR-将位图数据传输到FFmpeg视频 [英] AIR - Transfer Bitmap data to FFmpeg video

查看:103
本文介绍了AIR-将位图数据传输到FFmpeg视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我遇到了类似的问题:将RGB转换为YUV ,+ ffmpeg

Hey I'm running into a similar problem as: Converting RGB to YUV, + ffmpeg

从AIR,我发现编码太长,无法以合理的速率渲染帧-因此我从<$ c中导出了argb ByteArray $ c> bitmap.getPixels(rect)直接复制到文件。

From AIR, I figured the encoding was too long to render frames at a reasonable rate - so I exported the argb ByteArray from bitmap.getPixels(rect) directly to a file.

对于30秒的Flash动画,我想导出1500到1500个 .argb 文件的帧。

So for a 30sec flash animation, I'd export let's say 1500 frames to 1500 .argb files.

此方法效果很好。我能够使用ffmpeg cmd渲染高清视频:

This method works great. I was able to render HD video using the ffmpeg cmd:

ffmpeg -f image2 -pix_fmt argb -vcodec rawvideo -s 640x380 -i frame_%d.argb -r 24 -qscale 1.1 -s 640x380 -i ./music.mp3 -shortest render-high.mpg

到目前为止一切顺利!但是,在这两个过程之间,我们需要存储约3gb的数据。

So far so good! However, inbetween the two processes we need to store those ~3gb of data.

然后,我尝试将所有argb附加到一个文件中,并让ffmpeg使用它,但是没有从中得到任何好处...还尝试弄乱tcp / udp但卡住了...

I then tried to append all the argb to one single file and have ffmpeg consume it, but didn't get anything good out of it... Also tried messing tcp/udp but getting stuck...

有人知道简化该过程的方法吗?

Does anyone know of a way to streamline that process and hopefully pipe both Air and ffmpeg together?

推荐答案

您需要使用以下参数启动ffmpeg NativeProcess:

You need to start a ffmpeg NativeProcess with arguments like these:

ffmpeg -f rawvideo -pix_fmt argb -s 640x480 -r 24 -i - -c libx264 -b:v 1024k video.mp4

在这里,您需要指定输入帧大小(-s)帧速率(-r)和视频输出比特率(- b:v)并输出文件名。这些参数的顺序也很重要。

Here you need to specify input frame size (-s) frame rate (-r) and output bitrate for video (-b:v) and output filename. Also the order of these arguments matters.

然后,您只需将字节数组从 bitmap.getPixels(rect)传递到带有 _process.standardInput.writeBytes(data,0,data.bytesAvailable); 的此nativeProcess的standardInput。

Then you just pipe byte arrays from bitmap.getPixels(rect) to standardInput of this nativeProcess with _process.standardInput.writeBytes(data, 0, data.bytesAvailable); frame by frame.

有时会发生IOErrorEvent.STANDARD_INPUT_IO_ERROR-这意味着ffmpeg无法跟上您的数据,并且帧将被丢弃。除了降低帧大小,帧速率或比特率外,您无能为力-您可能希望对帧进行某种排队,但是高分辨率的未压缩图像非常大,因此您只能存储数十个它们存储在内存中,并且由于IO速度较慢而无法将它们存储在磁盘上。而且只有在处理高清视频编码时才会出现此问题。

Occasionally an IOErrorEvent.STANDARD_INPUT_IO_ERROR will occur - this means that ffmpeg can't keep up with your data and frames will be dropped. Apart from lowering frame size, frame rate or bitrate there is nothing you can do about it - you may want to have some kind of queue for your frames, but high resolution uncompressed images are very large so you will be able to store just tens of them in memory and you won't be able to store them on disk because of slow IO speeds. And this problem only occurs when dealing with HD video encoding.

调用 _process.closeInput(); 没有更多的帧要发送,等待ffmpeg进程退出,代码为0。

Call _process.closeInput(); when you have no more frames to send and wait for ffmpeg process to exit with code 0.

这篇关于AIR-将位图数据传输到FFmpeg视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆