Skip to main content
Participant
September 29, 2009
Question

FMIS 3.5 Record Live Stream With Timestamp

  • September 29, 2009
  • 1 reply
  • 1821 views

Greetings,

I have seen lots of different things about recording live streams (maybe too much, pieces everywhere but no one good source for the answers), but not what I am looking for...

I want to setup recording of live streams on FMIS 3.5 where the file is named the stream name plus a timestamp (something like streamname-yyyymmddHHMMSS: myteststream-20090928101015).  The people who use our site tend to start/stop several times (we are dealing with events that have breaks) and I want to be able to combine all the files with the same name into one big file on the server side afterwards using some utilities.

I was hoping recording would be a little more straightforward, but I cannot find a tutorial that walks you through the different functions, the differences between them, and how recording is setup/works.  If anyone can help I would greatly appreciate your help!

Thanks,

Brian

    This topic has been closed for replies.

    1 reply

    BMalekAuthor
    Participant
    October 4, 2009

    *bump* Anyone help?

    I cannot get recording to work at all - let alone with a timestamp...

    October 29, 2009

    I'm trying to achieve something that might be similar (or possibly useful to you?).

    What I'm aiming to achieve should allow the publisher to record each session to a seperate flv with the name of the file someRef_TimeDateStamp.flv

    I have followed a couple of tutorials on using the live stream cache to record video (and audio), however because it's a live stream, the live streaming / recording continues whilst the publisher plays back the session (I'm coding to let the publisher review their work before committing a reference to an XML object that gets written out as a file). Thus far, I haven't found a perfect method of pausing the live record, so I'm going to try and code something that takes the input netstream, records it to a reference_timestamp.flv file on FMIS 3.5 - then, when the publish hits the "end recording" button, it will have to kill the current input netstream and setup another one (which may or may not be recorded - depending on whether the publisher hits the "record" button again).

    Anyway, I'm just about to start work on a UML for this design solution - and will then code later on - if I find a solution, I'll post you a link to it.

    Wondered - have you got any futher with what you were doing?

    Best regards,

    Kevin

    October 29, 2009

    Also, I posted you some code on another forum earlier ... but had only tested on my local dev server - when I tested online (I'm using Influxis), I found a gremlin at play - basically, in the earlier version, I was using the publish() method with a fileName, but without a "record" or "live" parameter to effectively end the live stream ... that way, when I played back from the incoming stream (the one that's written from the cache), it didn't continue recording the out stream from the live feed. That worked fine locally, but when I tested online, the non-existant type parameter was effectively saying "ditch the cache and empty the buffer" ... and I didn't have my recording :-(

    So, what I did was add a couple of methods to my Main.asc file ... and then instead of using the publish(fileName) method on the stream ... I just close it.

    The code I'm now using works fine:

    <?xml version="1.0" encoding="utf-8"?>
    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark"
                           xmlns:mx="library://ns.adobe.com/flex/halo"
                           creationComplete="init()"
                           >
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
                import com.adobe.utils.StringUtil;
               
                import flash.display.Sprite;
                import flash.media.Video;
                import flash.net.NetStream;

                //public var rtmp:String = "rtmp://localhost/dvr";
                public var rtmp:String = ""; // ENTER YOUR FMIS APPLICATION URL HERE
                public var vidName:String;
               
                public var nc:NetConnection = new NetConnection();
                private var nsOut:NetStream;
                private var nsIn:NetStream;
               
                public var cam:Camera = Camera.getCamera();
                public var mic:Microphone = Microphone.getMicrophone();
               
               
                public var blackBackground:Sprite;
                public var recordVid:Video;
                public var playbackVid:Video;
                [Bindable]
                private var recording:Boolean = true;
                [Bindable]
                private var playMode:Boolean = false;
               
                private function init():void
                {
                    var td:Date = new Date();
                    var tdStamp:String = td.toUTCString();
                    tdStamp = StringUtil.remove(tdStamp,"UTC");
                    tdStamp = StringUtil.replace(tdStamp," ","_");
                    tdStamp = StringUtil.replace(tdStamp,":","_");

                    vidName = "TEST_"+tdStamp;
                   
                    trace("VIDNAME: "+vidName);
                   
                    blackBackground = new Sprite();
                    blackBackground.graphics.beginFill(0x000000,1);
                    blackBackground.graphics.drawRect(0,0,320,240);
                    blackBackground.graphics.endFill();
                    vidHolder1.addChild(blackBackground);
                    recordVid = new Video();
                    recordVid.width = 320;
                    recordVid.height = 240;
                    playbackVid = new Video();
                    playbackVid.width = 320;
                    playbackVid.height = 240;
                    vidHolder1.addChild( recordVid );
                   
                    nc.client = this;
                    nc.addEventListener( NetStatusEvent.NET_STATUS, onNetStatus );
                    nc.connect( rtmp );
                };
               
                private function onNetStatus( p_e:NetStatusEvent ):void
                {
                    var code:String = p_e.info.code;
                    trace("onNetStatus "+code);
                   
                    switch( code ) {
                        case "NetConnection.Connect.Success":
                            doStreams();

                            break;
                    }
                   
                };
               
                private function doStreams():void
                {
                    nsOut = new NetStream(nc);
                    nsOut.client = {};
                    nsOut.addEventListener( NetStatusEvent.NET_STATUS, onNetStatus );
                    nsIn = new NetStream( nc );
                    nsIn.client = {};
                    nsIn.addEventListener( NetStatusEvent.NET_STATUS, onNetStatus );
                    recordVid.attachCamera( cam );
                    playbackVid.attachNetStream( nsIn );
                    nsOut.attachAudio( mic );
                    nsOut.attachCamera( cam );
                    recording = false;
                    playMode = false;
                };
               
                private function doPublish():void
                {   
                        recordVid.attachCamera(cam);
                        if (vidHolder1.contains(playbackVid))
                        {
                            vidHolder1.removeChild( playbackVid);   
                        }
                        if (!vidHolder1.contains(recordVid))
                        {
                            vidHolder1.addChild( recordVid);   
                        }
                        recording = true;
                        nsOut.publish( vidName, "record" );
                       
                };
               
                private function stopPublish():void
                {
                    playMode = true;
                    recording = false;
                    nsOut.close();
                    playbackVid.attachNetStream( nsIn );
                    if (vidHolder1.contains(recordVid))
                    {
                        vidHolder1.removeChild( recordVid);   
                    }
                    if (!vidHolder1.contains(playbackVid))
                    {
                        vidHolder1.addChild( playbackVid);   
                    }

                }
               
                private function doPlay():void
                {
                    nsIn.play( vidName, 0, -1 );
                };
               
                public function onBWDone():void{};
            ]]>
        </fx:Script>
                <mx:VBox>
                    <mx:UIComponent id="vidHolder1" width="320" height="240"/>
                    <mx:Button id="recButton" label="Record" visible="{!recording}" enabled="{!recording}" click="doPublish()"/>
                    <mx:Button id="stopRecord" label="End Record" enabled="{recording}" visible="{recording}" click="stopPublish()"/>
                    <mx:Button id="playVid" label="Play" enabled="{playMode}" visible="{!recording}" click="doPlay()"/>
                </mx:VBox>

    </s:WindowedApplication>

    THE Main.asc file I'm using is pasted below: (You might want to take out the first couple of lines if you're not with Influxis and never use the FLVPlayback component).

    load("InfluxisVideoPlayer.asc");
    load("flvplayback8.asc");
    application.onConnect = function(myClient){
         return true;
    }

    application.onPublish = function(myClient,myStream){
         myStream.record( );
    }

    application.onUnpublish = function(myClient,myStream){
         myStream.record(false);
    }