简体   繁体   English

在ActionScript 3中将摄像机输入另存为GIF

[英]Save camera input as GIF in ActionScript 3

I want to create an animated gif about 15 seconds long directly from the camera's input. 我想直接从相机的输入创建一个大约15秒长的动画gif。

At the moment I've done this by taking images every few milliseconds and I plan on processing these images server-side using something like ffmpeg to create a final gif. 目前,我每隔几毫秒拍摄一次图像,因此我计划使用ffmpeg之类的东西在服务器端处理这些图像,以创建最终的gif。

Is there a way to have flash do the whole thing? 有没有办法让闪光灯完成整个任务?

There's a gif library to do this. 有一个gif库可以做到这一点。 I'm not terribly sure how it works, but looking at the API it seems as though it's something like: 我不太确定它是如何工作的,但是看一下API似乎就像这样:

var encoder:GIFEncoder = new GIFEncoder();

encoder.start();
encoder.addFrame(bitmapData); // for each frame
encoder.finish();

https://github.com/audreyt/as3gif https://github.com/audreyt/as3gif

Update 更新

I was able to encode to gif using the following function, which takes an Array of BitmapData and returns a ByteArray. 我可以使用以下函数将其编码为gif,该函数接受一个BitmapData数组并返回一个ByteArray。

public function encode(frames:Array):ByteArray
{
    var encoder:GIFEncoder = new GIFEncoder();

    encoder.start();

    for (var i:int = 0; i < frames.length; i++)
    {
        encoder.addFrame(frames[i]);
    }

    encoder.finish();

    return encoder.stream;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM