0

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.

PHCM
  • 1
  • 2
  • Hmmm, NDI is what I would use. In any case, can you elaborate on what you're using? Are you really using Flash with ActionScript? Or something else? – Brad Mar 17 '22 at 21:20
  • I have an AIR app running graphics. 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. – PHCM Mar 18 '22 at 03:40
  • Are you saying that doing `AS3-->FFmpeg-->NDI` is a slow process or you're just saying that AS3's draw itself is slow? Also maybe telling us how you transfer from AS3 to FFmpeg or what command for FFmpeg to send to the NDI? I mean how does RGB pixel data from AS3 end up in NDI, your settings for that process could be what is slow. – VC.One Mar 19 '22 at 11:29
  • I edited my question attaching the code. @VC.One please – PHCM Mar 20 '22 at 04:23

0 Answers0