views:

803

answers:

2

I'm trying to record a webcam's video and audio to a FLV file stored on the users local hard disk. I have a version of this code working which uses NetConnection and NetStream to stream the video over a network to a FMS (Red5) server, but I'd like to be able to store the video locally for low bandwidth/flaky network situations. I'm using FLex 3.2 and AIR 1.5, so I don't believe there should be any sandbox restrictions which prevent this from occurring.

Things I've seen:

  • FileStream - Allows reading.writing local files but no .attachCamera and .attachAudio methids for creating a FLV.
  • flvrecorder - Produces screen grabs from the web cam and creates it's own flv file. Doesn't support Audio. License prohibits commercial use.
  • SimpleFLVWriter.as - Similar to flvrecorder without the wierd license. Doesn't support audio.
  • This stackoverflow post - Which demonstrates the playback of a video from local disk using a NetConnection/NetStream.

Given that I have a version already which uses NetStream to stream to the server I thought the last was most promising and went ahead and put together this demo application. The code compiles and runs without errors, but I don't have a FLV file on disk which the stop button is clicked. -

<mx:Script>
    <![CDATA[

        private var _diskStream:NetStream;
        private var _diskConn:NetConnection;
        private var _camera:Camera;
        private var _mic:Microphone; 

        public function cmdStart_Click():void {
            _camera = Camera.getCamera();
            _camera.setQuality(144000, 85);
            _camera.setMode(320, 240, 15);
            _camera.setKeyFrameInterval(60);

            _mic = Microphone.getMicrophone();

            videoDisplay.attachCamera(_camera);

            _diskConn = new NetConnection();
            _diskConn.connect(null);

            _diskStream = new NetStream(_diskConn);
            _diskStream.client = this;
            _diskStream.attachCamera(_camera);
            _diskStream.attachAudio(_mic);
            _diskStream.publish("file://c:/test.flv", "record");

        }

        public function cmdStop_Click() {
            _diskStream.close();
            videoDisplay.close();
        }

    ]]>
</mx:Script>    
    <mx:VideoDisplay x="10" y="10" width="320" height="240" id="videoDisplay" />
    <mx:Button x="10" y="258" label="Start" click="cmdStart_Click()" id="cmdStart"/>
    <mx:Button x="73" y="258" label="Stop" id="cmdStop" click="cmdStop_Click()"/>

</mx:WindowedApplication>

It seems to me that there's either something wrong with the above code which is preventing it from working, or NetStream just can't be abused in this wany to record video.

What I'd like to know is, a) What (if anything) is wrong with the code above? b) If NetStream doesn't support recording to disk, are there any other alternatives which capture Audio AND Video to a file on the users local hard disk?

Thanks in advance!

A: 

Hi, I am also trying to do the same thing, but I have been told from the developers of avchat.net that it is not possible to do this with AIR at the moment. If you do find out how to do it, I would love to know!

I also found this link, not sure how helpful it is http://www.zeropointnine.com/blog/webcam-dvr-for-apollo/

Ali G
Hi, The video recording backend behind the Webcam DVR is the SimpleFLVRecorder.as which I liked to above. The major problem for me with SimpleFLVWriter.as is that it doesn't support audio recording along with the webcam video. In my application the Audio is very important (actually, a solution which records audio only and no video would be better than video without audio).
Jim OHalloran
A: 

Well, I just think that letting it connect to nothing(NULL) doesn't work. I've already let him try to connect to localhost, but that didn't work out either. I don't think this is even possible. Streaming video works only with Flash Media Server and Red5, not local. Maybe you could install Red5 on you PC?

ProNoob13
The objective is to provide an "app" the user downloads from the web site (ideally installed as seamlessly as AIR allows) which they can use to record video and later upload it to a Red5 server. Installing Red5 on the local machine would mean we'd need to create a seperate installer App which installed our application and Red5 for the user. Not the seamles experience we're hoping for.
Jim OHalloran

related questions