Video Recording using Flash

Recording Video using Flash is a trend on the high. YouTube Quick Capture is one that has caught our eyes on this. So I was trying to get something done in the same way. I am basically Java developer and have experience of developing Video Recorder using Java Media Framework. Though I am a Java fanatic I feel that at present Flash is the way to Video on Internet. Its adaptation in video technology is very wide spread and well acclaimed. This blog is about is about video recording.

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();

// 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);
The second thing that we can do is detect and select the capture devices.
// get references to the camera and mic
var cam:Camera = Camera.get();
var mic:Microphone = Microphone.get();
Now 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.
// setting dimensions and framerate
cam.setMode(320, 240, 30);
// set to minimum of 70% quality
cam.setQuality(0,70);
//Setting sampling rate to 8kHz
mic.setRate(8);
Next we need to add the device streams to the capture stream.
// This FLV is recorded to webapps/oflaDemo/streams/ directory
// attach cam and mic to the NetStream Object
ns.attachVideo(cam);
ns.attachAudio(mic);
After that we need to add the camera to the container and publish the video.
// attach the cam to the videoContainer on stage so we can see ourselves
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");
Now 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
// attach the netStream object to the video object
videoContainer.attachVideo(ns);
// play back the recorded stream
ns.play(lastVideoName);
Hopefully with these steps a video recording and stream playback should be possible.

20 comments:

  1. Just wanted to add that if anyone needs the FLA file just ask me.

    Thank you

    ReplyDelete
  2. Hi where can we download a working sample of this? (thanks)

    ReplyDelete
  3. hi,

    Can you tell me you email, as the link you gave above it broker?

    thanks

    ReplyDelete
  4. Sure, anyone interested can just send me an email at imran.yousuf@smartitengineering.com and I will send the file in reply.

    ReplyDelete
  5. Sorry for the inconvenience with the email address, actually I did provide it correctly but Blogger.com messed it up.

    ReplyDelete
  6. Neat that webcams can be used with Flash! See some of my experiments & samples on http://www.SillyWebcam.com (no recording here though).

    ReplyDelete
  7. Thank a lot for this excellently explained recorder.

    Could 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 ?

    ReplyDelete
  8. @Karl-Heinz
    If 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.

    ReplyDelete
  9. Hi where can we download a working sample of simpleRecorder.swf??

    Thanks in Advance :)

    Email ID: sanu124@gmail.com

    ReplyDelete
  10. I am using Flex 3.3 and it's not supporting attachVideo. For the recording part I use attachCamera.

    However, for playback I cannot use videoContainer.attachCamera(ns).

    So, how I palyback the video?

    ReplyDelete
  11. @Gilbert
    Sorry, but I do not know the answer to your query :(

    ReplyDelete
  12. hi good information u given in this article thanks streaming recorder

    ReplyDelete
  13. flash player is very familiar in online videos better you can use real player is the easiest way to record online flv recorder

    ReplyDelete
  14. Thanks for sharing this tech information.

    ReplyDelete
  15. Hi All,

    Its a nice information and good article..thanks.

    ReplyDelete
  16. An informative article. Thanks for sharing this post.

    ReplyDelete
  17. HI

    where i found the working code example of that.

    ReplyDelete
  18. Hi,

    It would be nice to receive an example too if you still have one: yamakasi.014gmailcom

    Your tut is already great!

    Thanks,

    Matt

    ReplyDelete
  19. i need the swf or fla file for the same. can you please provide me with it.

    ReplyDelete

Search