Using http://www.as3apex.com/uncategorized/flash-10s-bitmapdatahistogram-is-really-slow/and http://books.google.com/books?id=xm9COWxqfIkC&pg=PT233&dq=histogram+flash+actionscript&client=safari for guidence.
Today's code
import flash.display.Bitmap;
import flash.display.BitmapData;
var video:Video = new Video();
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = {};
ns.client.onMetaData = ns_onMetaData;
ns.client.onCuePoint = ns_onCuePoint;
ns.play("640x480.flv");
video.attachNetStream(ns);
function ns_onMetaData(item:Object):void {
trace("metaData");
// Resize video instance.
video.width = item.width;
video.height = item.height;
// Center video instance on Stage.
video.x = (stage.stageWidth - video.width) / 2;
video.y = (stage.stageHeight - video.height) / 2;
}
function ns_onCuePoint(item:Object):void {
trace("cuePoint");
trace(item.name + "\t" + item.time);
}
//var snapshot : BitmapData;
//snapshot = new BitmapData(myVideo.width,myVideo.height);
//function takeSnapshot()
//{
// snapshot.draw(myVideo);
//}
//call takeSnapshot every 100ms (0.1s)
var now : BitmapData;
var before: BitmapData;
now = new BitmapData(video.width,video.height);
//setInterval(this,"takeSnapshot",100);
//setInterval(this,"takeSnapshot",100);
function takeSnapshot()
{
now.draw(video);
// 1. capture 'now' 2. Do something 3. copy now to before
before=now.clone();
var histogram(hRect:Rectangle=null):Vector.> = BitmapData.histogram;
var oldC = before.histogram();
var newC = now.histogram();
if (oldC != newC) {
trace('Activity... in region');
}
}
//function histogram(hRect:Rectangle = null):Vector
No comments:
Post a Comment