Skip to main content
Kristian Wright
Known Participant
January 25, 2008
Question

Record live stream with different name

  • January 25, 2008
  • 3 replies
  • 910 views
Hi all!

I have a live streaming application running with FMS2 and I have come across an issue with recording streams. My application allows a client (from a pool of multiple clients) viewing the stream to record the stream to the FMS server. I start the recording on the server side with the following (simplified) code:

application.recordStream = Stream.get(instanceName);

if (blnRecord)
{
// start recording
application.recordStream.record();
}
else
{
// stop recording
application.recordStream.record(false);
}

There is something that I'm having trouble with though - is there a way to record the stream with a different (unique) name rather than the instance name? I ask this because I need to have different names for each different recording session. Using file.renameTo( ) after the recording finishes works in theory, but in practice it seems that the recorded file is buffered before it is written to disk. So when the application.recordStream.record(false); line is invoked, trying to rename the file now is not possible, as it's still being written to the disk. It seems there is no way to know when the final, complete file has finally been written to the disk.

The problem here is that once the first recording is finished, another user can start the record process again. If the file has not been renamed or moved, the previous recording will be overwritten!

So, is it possible to record a stream, but save it to disk with a unique name?

Thanks in advance,
K.
    This topic has been closed for replies.

    3 replies

    Kristian Wright
    Known Participant
    January 28, 2008
    Thanks loweyson, but no good.

    I can't wait for the UnpublishNotify event, as I don't want everyone connected to that stream have to reconnect to a new stream! By starting and stopping the recording on the server side, there is no UnpublishNotify event ever thrown, as the stream never stops being published! All users are always connected to the live stream, recording or not. Plus I'm not really sure what you're trying to do with the 'st.play' line.. I don't want to play the stream - it's being published from ClientA through to FMS, then onto ClientB -> ClientZ. Recordoing starts and stops on the server side, and there is never need to 'play' the stream from the server side, only from the client side.

    But thanks anyway.

    Anyone have any more ideas? ;-)

    Cheers,
    K.
    Kristian Wright
    Known Participant
    January 28, 2008
    Thanks Genaro, but that's not quite what I'm looking for.

    The issue with that is that if I publish a stream, and then record it from the source client with a unique name when requested, all the users connected to the initial stream will receive a NetStream.Play.UnpublishNotify and will stop receiving the stream. This is because I'm now publishing a entirely new stream, and recording that. To watch the stream being recorded, the other clients would have to switch streams, which I'm trying to avoid.

    By recording on the server side, I can start and stop recording whenever I want, and all users will always be connected to the live stream. But I can't change the name...

    Also, I need to avoid the use of 2 NetStreams from the source client (1 for live and 1 for recording) for bandwidth reasons, so this is not an option either.

    Cheers,
    K.
    January 28, 2008
    Hi Guys, I've only quickly read your post but it sounds like a similar problem I've solved. Basically my approach was to register for a stream (name decided in advance) which I create on the FMS in response to the onAppStart function (however the downside is this only allows 1 stream per app instance, however you could use onConnect generate a random name and use client.call() to tell your client about the new name of the stream before it connects). See sample code below:



    var st = Stream.get("SOMPLACEHOLDERSTREAMNAME");

    st.onStatus = onStreamstatus;

    st.play("predeterminedstreamname", -1, -1);



    When the client connects to your predeterminedstreamname you will get a call to your onStreamstatus function which you can then use to detect when the stream is unpublished. I then use this event to do the following, which detects if a stream was recorded, and then renames it:



    var thePath = "streams/" + application.instanceName + "/predeterminedstreamname.flv";
    var f = new File( thePath );
    if( f.exists )
    {
    archiveName = generateUniqueFileName();

    var newPath = "streams/" + application.instanceName + "/" + archiveName + ".flv";

    if( f.renameTo( newPath ) )
    {
    localLog("Stream archive detected, renamed to: " + newPath );
    }
    else
    {
    localLog("Stream archive detected, but failed to rename it." );
    }
    }



    Hope this helps.
    Inspiring
    January 25, 2008
    If have an app that records video from the client too, but in my case I record the video using netStream.publish() from the client. The stream name is used as file name, so I just create a custom name and use that to get the stream and so when the stream is recorded it gets this as a file name.

    Haven't tried it on the server side, are you getting the instanceName of the application on the file's name, or the stream's name?

    If you are getting the stream name, then its just a matter of you setting a custom name for the recording stream. If this is a live stream, the you would have to make this name available to subscribing clients