Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Creating a buffered netstream object to capture perfect webcam video from flash
// This file is a super-simple example of capturing a webcam up to a flash media server
// You can use RED5 1.0, Wowza, or FMS for this example - there are demo recording apps
// (oflaDemo for red5, vod for Wowza) included with each. Note: red5 .9xx reportedly
// does not like the buffered upstream sending we're doing here.
// All of the existing examples I could find simply had you "stop" the netstream object
// when the user was done recording, which, if you have any client-side buffer at all completely
// borks the recorded FLV. This example uses a 60 second client-side buffer, which
// allows you to capture high-quality webcam videos even if the upstream bandwidth
// isn't perfect or consistent. Once the user is done, the buffer continues sending up
// the data, and as long as you didn't overflow the client-side buffer, the video should
// be perfect.
// create basic netConnection object
var nc:NetConnection = new NetConnection();
// connect to the flash media server (FMS, RED5, WOWZA)
nc.connect(YOUR_FMS_HOST);
// create the netStream object and pass the netConnection object in the constructor
var ns:NetStream = new NetStream(nc);
// get references to the camera and mic
var cam:Camera = Camera.get();
var mic:Microphone = Microphone.get();
// setup some simple settings with the cam and mic for quality
setupCameraMic();
function playClicked():Void
{
ns.setBufferTime(60);
ns.attachVideo(cam);
ns.attachAudio(mic);
}
function stopClicked():Void
{
// pause the netStream object
ns.pause();
//detach video
ns.attachVideo(null);
ns.attachAudio(null);
//also detach video from our monitor, in our case an object called videoContainer
videoContainer.attachVideo(null);
//spin up a thread to check the buffer every 500ms and close it once empty
flushinterval = setInterval(flusher, 500);
}
function flusher():Void{
//This gets called by the setInterval above every 500ms until the interval is
//cleared below, when the buffer is empty
if((ns.bufferLength == 0)){
//great, the buffer is empty, close it up and stop this interval
clearInterval(flushinterval);
ns.close();
//You can now tell the user their recording is complete
}else{
trace("still flushing: " + ns.bufferLength)
//You'll probably want to show some message to the user here that
//their recording is uploading/completing
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.