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.