如何将AS3动画导出到OBS、vMix等直播软件?

发布于 2025-01-14 18:14:29 字数 2246 浏览 5 评论 0原文

您知道有什么库可以将 AS3 动画导出到 OBS、vMix 等流媒体软件吗?

我不想使用“色度键”技术,因为它有局限性。我想将“真正的透明度”动画从 AS3 导出到流媒体软件。

我还尝试在 BitmapData 中使用 draw() 将每一帧从 AS3 渲染到 NDI 输出,但速度非常慢。该应用程序使用 AS3 中的 draw() 将舞台上的图形作为 BitmapData 渲染到 FFMPEG,FFMPEG 会将其提供给 NDI 输出。

我认为做AS3-->FFmpeg-->NDI是一个缓慢的过程。我想找到另一个更好的解决方案。 OBS截屏速度快,但缺乏透明度。 这是我从 AS3 传输到 FFmpeg 的代码(FFmpeg 将传输到 NDI 输出):

import flash.desktop.*;

import flash.filesystem.File;

import flash.display.Bitmap;

var NP_StartupInfo:NativeProcessStartupInfo;

var process:NativeProcess=new NativeProcess();

do_NativeProcess_FFMPEG();

function do_NativeProcess_FFMPEG () : void

{

    NP_StartupInfo = new NativeProcessStartupInfo();    

    var Args_FFMPEG:Vector.<String> = new Vector.<String>();

    Args_FFMPEG.push("-f",  "rawvideo");

    Args_FFMPEG.push("-pix_fmt",    "argb");

    Args_FFMPEG.push("-s",  "1920x1080");

    Args_FFMPEG.push("-r",  "30");

    Args_FFMPEG.push("-i", "-");

    Args_FFMPEG.push("-f", "libndi_newtek");

    Args_FFMPEG.push("-pix_fmt","rgba","OPreview");

    NP_StartupInfo.executable = File.applicationDirectory.resolvePath("ffmpeg.exe");

    NP_StartupInfo.arguments = Args_FFMPEG;

    process = new NativeProcess();

    process.start( NP_StartupInfo );

    write_STDIn_Data();

}

function write_STDIn_Data () : void

{

    stage.addEventListener(Event.ENTER_FRAME, update);

}

function update(e:Event) : void

{

    makeVideoFrame();

}

var snapShot_BMD:BitmapData= new BitmapData(1920, 1080, true, 0x00000000);

var frame_BMP:Bitmap = new Bitmap();

var ba_Pixels:ByteArray = new ByteArray();

var sendingBA:ByteArray = new ByteArray();

function makeVideoFrame() : void

{

    snapShot_BMD.drawWithQuality(stage, null, null, null, null, false, StageQuality.MEDIUM);

    frame_BMP.bitmapData = snapShot_BMD;

    ba_Pixels = frame_BMP.bitmapData.getPixels( frame_BMP.bitmapData.rect);

    sendingBA = new ByteArray();

    sendingBA.writeBytes(ba_Pixels);

    process.standardInput.writeBytes(sendingBA); 

    snapShot_BMD= new BitmapData(1920, 1080, true, 0x00000000);

    frame_BMP = new Bitmap();

    ba_Pixels.clear();

}

对于 10fps 动画,该过程没问题。但对于20-30fps来说,速度太慢并且没有实时输出。

Do you know any library to export AS3 animations to streaming softwares like OBS, vMix, etc?

I don't want to use the "chroma key" technique because it has limitations. I want to export the "real transparency" animations from AS3 to the streaming software.

I also tried to use draw() in BitmapData to render every frame from AS3 to NDI output, but it is very slow. The app use draw() in AS3 to render the graphic on the stage as BitmapData to FFMPEG, and FFMPEG will give it to NDI output.

I think that doing AS3-->FFmpeg-->NDI is a slow process. I want to find another better solution. OBS screen capturing has the good speed, but it doesn't have transparency.
Here is my code for transfer from AS3 to FFmpeg (and FFmpeg will transfer to NDI output):

import flash.desktop.*;

import flash.filesystem.File;

import flash.display.Bitmap;

var NP_StartupInfo:NativeProcessStartupInfo;

var process:NativeProcess=new NativeProcess();

do_NativeProcess_FFMPEG();

function do_NativeProcess_FFMPEG () : void

{

    NP_StartupInfo = new NativeProcessStartupInfo();    

    var Args_FFMPEG:Vector.<String> = new Vector.<String>();

    Args_FFMPEG.push("-f",  "rawvideo");

    Args_FFMPEG.push("-pix_fmt",    "argb");

    Args_FFMPEG.push("-s",  "1920x1080");

    Args_FFMPEG.push("-r",  "30");

    Args_FFMPEG.push("-i", "-");

    Args_FFMPEG.push("-f", "libndi_newtek");

    Args_FFMPEG.push("-pix_fmt","rgba","OPreview");

    NP_StartupInfo.executable = File.applicationDirectory.resolvePath("ffmpeg.exe");

    NP_StartupInfo.arguments = Args_FFMPEG;

    process = new NativeProcess();

    process.start( NP_StartupInfo );

    write_STDIn_Data();

}

function write_STDIn_Data () : void

{

    stage.addEventListener(Event.ENTER_FRAME, update);

}

function update(e:Event) : void

{

    makeVideoFrame();

}

var snapShot_BMD:BitmapData= new BitmapData(1920, 1080, true, 0x00000000);

var frame_BMP:Bitmap = new Bitmap();

var ba_Pixels:ByteArray = new ByteArray();

var sendingBA:ByteArray = new ByteArray();

function makeVideoFrame() : void

{

    snapShot_BMD.drawWithQuality(stage, null, null, null, null, false, StageQuality.MEDIUM);

    frame_BMP.bitmapData = snapShot_BMD;

    ba_Pixels = frame_BMP.bitmapData.getPixels( frame_BMP.bitmapData.rect);

    sendingBA = new ByteArray();

    sendingBA.writeBytes(ba_Pixels);

    process.standardInput.writeBytes(sendingBA); 

    snapShot_BMD= new BitmapData(1920, 1080, true, 0x00000000);

    frame_BMP = new Bitmap();

    ba_Pixels.clear();

}

For 10fps animations, the process is ok. But for 20-30fps, it so slow and does not have real-time output.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文