The first thing that is required for Flash video recording is a media server for streaming; because Flash unlike signed applet can store on local disk, it in fact streams the captured video to media server. There is Adobe Media Server or Flash Communication Server that we can use after procuring or there is Red5; thanks to the open source community. Now with Red5 comes a sample simple video recorder, using which you can simply stream video to the server. If we look at a customized Simple Recorder (it is only the recorder and there is no attached streaming server :) if anyone can help please let me know) we will find that for sole recording purpose there is a video container that shows the video. Initially it shows the currently being captured video and once the recording is stopped it shows the streamed video of the just recorded stream. This events are triggered by the buttons on SWF video. It uses the oflaDemo Red5 Application provided as demo with the server. All streamed videos are stored in {RED5_HOME}/webapps/oflaDemo/streams/.
Now lets look at the code used for this purpose. The first task is to open an stream when we intend to record something.
var nc:NetConnection = new NetConnection();The second thing that we can do is detect and select the capture devices.
// connect to the local media server
// rtmp://{host}:{port}/{Red5_application_context}
// default port is 1935
nc.connect("rtmp://localhost/oflaDemo");
// create the netStream object and pass the netConnection object in the
// constructor
var ns:NetStream = new NetStream(nc);
// get references to the camera and micNow above we selected the default devices but we could Camera.names to get the names of the capture devices and select the one that we want; this is something that YouTube does :). Next we need to configure the video capture stream.
var cam:Camera = Camera.get();
var mic:Microphone = Microphone.get();
// setting dimensions and framerateNext we need to add the device streams to the capture stream.
cam.setMode(320, 240, 30);
// set to minimum of 70% quality
cam.setQuality(0,70);
//Setting sampling rate to 8kHz
mic.setRate(8);
// This FLV is recorded to webapps/oflaDemo/streams/ directoryAfter that we need to add the camera to the container and publish the video.
// attach cam and mic to the NetStream Object
ns.attachVideo(cam);
ns.attachAudio(mic);
// attach the cam to the videoContainer on stage so we can see ourselvesNow once the recording is just clear the video container and the captured stream to the container and specify the stream to play the just recorded video
videoContainer.attachVideo(cam);
// Publish the video and mention record
// lastVideoName is the name of the video and it will be saved as ]
// lastVideoName.flv
ns.publish(lastVideoName, "record");
// attach the netStream object to the video objectHopefully with these steps a video recording and stream playback should be possible.
videoContainer.attachVideo(ns);
// play back the recorded stream
ns.play(lastVideoName);
Just wanted to add that if anyone needs the FLA file just ask me.
ReplyDeleteThank you
Hi where can we download a working sample of this? (thanks)
ReplyDeletehi,
ReplyDeleteCan you tell me you email, as the link you gave above it broker?
thanks
Sure, anyone interested can just send me an email at imran.yousuf@smartitengineering.com and I will send the file in reply.
ReplyDeleteSorry for the inconvenience with the email address, actually I did provide it correctly but Blogger.com messed it up.
ReplyDeleteNeat that webcams can be used with Flash! See some of my experiments & samples on http://www.SillyWebcam.com (no recording here though).
ReplyDeleteThank a lot for this excellently explained recorder.
ReplyDeleteCould you please add a few comments on:
How do I check whether Red5 is alive?
How do I check whether a cam is present or not ?
@Karl-Heinz
ReplyDeleteIf you want to check from the client side I would say that nc.connect would fail if its down and thus it would go ahead showing the video but not streaming it.
The following line is responsible for fetching the camera -
var cam:Camera = Camera.get();
There is another static property Camera.names which would give you the names of the camera you have, if its empty then you do not have camera else you do :), quite simple.
Hi where can we download a working sample of simpleRecorder.swf??
ReplyDeleteThanks in Advance :)
Email ID: sanu124@gmail.com
Thanks for this good post....
ReplyDeleteI am using Flex 3.3 and it's not supporting attachVideo. For the recording part I use attachCamera.
ReplyDeleteHowever, for playback I cannot use videoContainer.attachCamera(ns).
So, how I palyback the video?
@Gilbert
ReplyDeleteSorry, but I do not know the answer to your query :(
hi good information u given in this article thanks streaming recorder
ReplyDeleteflash player is very familiar in online videos better you can use real player is the easiest way to record online flv recorder
ReplyDeleteThanks for sharing this tech information.
ReplyDeleteHi All,
ReplyDeleteIts a nice information and good article..thanks.
An informative article. Thanks for sharing this post.
ReplyDeleteHI
ReplyDeletewhere i found the working code example of that.
Hi,
ReplyDeleteIt would be nice to receive an example too if you still have one: yamakasi.014gmailcom
Your tut is already great!
Thanks,
Matt
i need the swf or fla file for the same. can you please provide me with it.
ReplyDelete