使用flex从视频中获取随机(或第一)帧

时间:2011-12-07 15:28:43

标签: video actionscript flex4 thumbnails

我正在开发一个用于录制视频并将其预览为tilelist的应用程序。是否有任何方法可以捕获视频帧以用作列表中的缩略图?我正在使用Flex 4.5。

3 个答案:

答案 0 :(得分:1)

来自this answer

var frameGrab:BitmapData = new BitmapData(clip.width, clip.height, false, 0);
frameGrab.draw(clip); // the .draw() method will copy the frame from your video.
var frame:Bitmap = new Bitmap(frameGrab);

答案 1 :(得分:0)

我正在寻找的是以下内容:

        private function capture(filename:String):void
        {   
            var bitmapData:BitmapData = new BitmapData(videoDisplay.width, videoDisplay.height);            
            bitmapData.draw(videoDisplay,new Matrix());

            var bitmap : Bitmap = new Bitmap(bitmapData);
            var jpg:JPEGEncoder = new JPEGEncoder();
            var ba:ByteArray = jpg.encode(bitmapData);
            var newImage:File = File.desktopDirectory.resolvePath("foldername/"+filename+".jpg");

            fileStream = new FileStream();
            fileStream.open(newImage, FileMode.UPDATE);
            fileStream.writeBytes(ba);
            fileStream.close();


        }

这是用户点击记录时调用的方法。所以我像拇指一样抓取照片!我希望上面的内容能够帮助其他人寻找类似的东西...... 非常感谢!

答案 2 :(得分:0)

另一种方法: 将事件监听器附加到视频流(即NetStream),如下所示:

var vConnection:NetConnection = new NetConnection();
vConnection.connect(null);
var vStream:NetStream = new NetStream(vConnection);
vStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatusChange);

然后听众看起来像这样:

protected function onNetStatusChange(event:NetStatusEvent):void
{
    switch(event.info.code)
    {
        case "NetStream.Play.Start": 
        {
            vStream.seek(1); // seek to key frame
            break;
        }
        case "NetStream.Video.DimensionChange":
        {
            // after a dimension change we have a loaded frame
            // do whatever you want here, but keep in mind 
            // that the video needs to be on the display list 
            // if you want to draw it   
            break;
        }
        default: break;
    }
}