Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I record video to a local disk in AIR?

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!

like image 860
Jim OHalloran Avatar asked Jan 21 '10 21:01

Jim OHalloran


2 Answers

It is not possible To stream video directly to the local disk without using some streaming service like Windows Media encoder, or Red5 or Adobe's media server or something else.

I have tried all the samples on the internet with no solution to date.

look at this link for another possibility:

http://www.zeropointnine.com/blog/updated-flv-encoder-alchem/

like image 124
ShaunOReilly Avatar answered Oct 15 '22 15:10

ShaunOReilly


My solution was to embed Red5 into AIR. Sharing with you my article

http://mydevrecords.blogspot.com/2012/01/local-recording-in-adobe-air-using-red5.html

In general, the solution is to embed free media server Red5 into AIR like an asset. So, the server will be present in AIR application folder. Then, through the NativeProcess, you can run Red5 and have its instance in memory. As result, you can have local video recording without any network issues.

like image 36
walv Avatar answered Oct 15 '22 15:10

walv