Skip to main content
Known Participant
February 22, 2007
Question

Capturing webcam images

  • February 22, 2007
  • 1 reply
  • 227 views
Hi,

I have flash working with flash media server to record a webcam. There are two things I also need the application to do which it currently doesn't.

1) How do you capture a still image from the webcam? At the moment im using this line of code to record:

publish_ns.publish("allAboutMe + 1", "record");

2) How do you show what is being recorded as you record?, at present it records with a blank screen and you cant see the results until you play it back. This is the code used at the moment.

var my_nc:NetConnection = new NetConnection();
my_nc.connect("rtmp://localhost/allAboutMe");
var publish_ns:NetStream = new NetStream(my_nc);
publish_ns.attachVideo(Camera.get());
publish_ns.attachAudio(Microphone.get());
publish_ns.publish("allAboutMe + 1", "record");

thanks

Gavin
    This topic has been closed for replies.

    1 reply

    Inspiring
    February 22, 2007
    For starters, you should not call NetStream.publish() until AFTER you receive a NetConnection.Connect.Success message from the server. Failure to do so may prevent anything from streaming. Create a new "onStatus" method as follows:

    var my_nc:NetConnection = new NetConnection();
    my_nc.onStatus = function (info:Object)
    {
    if(info.code == "NetConnection.Connect.Success")
    {
    // Publish your stream here
    var publish_ns:NetStream = new NetStream(my_nc);
    publish_ns.attachVideo(Camera.get());
    publish_ns.attachAudio(Microphone.get());
    publish_ns.publish("allAboutMe + 1", "record");
    }
    }
    my_nc.connect("rtmp://localhost/allAboutMe");

    To watch the video, you need to create a Video component on the stage and then attach the camera as follows:

    var video:Video; // Don't forget to create this component on the stage!
    video.attachVideo(Camera.get());


    As for capturing a single image, I'm not sure how to do that, but you can make the player display a single image like this:
    your_netstream.play(yourstream, -1, 0);
    The zero parameter tells Flash to play the stream for zero seconds (i.e. 1 frame)


    Good luck,
    Barry