Skip to main content
Known Participant
July 22, 2009
Answered

How do I record streams in chunks on Flash Media Server?

  • July 22, 2009
  • 5 replies
  • 2703 views

I want to record a stream which is published with Flash Live Encoder to FMS 3.5, but split the recording in files with predefined length. For example if a stream 'webcam' is published I want to record it in chunks of 10 minutes: 'webcam1.flv', 'webcam2.flv' ... From what I can tell there's no facility to work with timers. The only solution I could think of was using stream.record() with a time limit parameter but that seems like a hack because it triggers NetStream.Record.DiskQuotaExceeded on the stream when the recordin should stop and start recording another chunk. Has anyone done something similar?

    This topic has been closed for replies.
    Correct answer

    please can you tell me how can i make chunk files with serverside actionscript? as i see in documentation there is only one method to record

    stream.record();

    and i can't give to it filename. as i understand recorded stream filename is the same that i set from FMLE stream name, but how can i change it?


    I like to approach it by recording to a new server side stream instead of directly recording the client's publish stream. A rough example would be something like this (I didn't test the code... this is just an example):

    application.onPublish = function(client, stream){

    client.publishingStreamName = stream.name;

    application.chunkRecording(client);

    }

    application.onDisconnect = function(client){

    clearInterval(client.chunkInterval);

    if(client.recordingStream){

    client.recordingStream.play(false);

    client.recordingStream.record(false);

    }

    }

    application.chunkRecording = function(client){

    clearInterval(client.chunkInterval);

    // Stop any old recording

    if(client.recordingStream){

    client.recordingStream.play(false);

    client.recordingStream.record(false);

    }

    // Start the new recording. Create a new name for the stream based on the time.

    var recordStreamName = client.publishingStreamName + "-" + new Date().getTime();

    client.recordingStream = Stream.get(recordStreamName);

    client.recordingStream.record();

    // Run me again in an hour.

    client.chunkInterval - setInterval(application, "chunkRecording", 3600000, client);

    }

    5 replies

    Known Participant
    July 24, 2009

    god damn it, documentation says

    "The server truncates recordings greater than MaxCapSize and MaxCapDuration."

    it's not true, server just stops recording and says Disk Quota exceeded

    im trying to do this almost 3 weeks the documentation are very weak

    July 24, 2009

    Whoops... forgot to start playing the publish stream in my code:

    application.chunkRecording = function(client){

    clearInterval(client.chunkInterval);

    // Stop any old recording

    if(client.recordingStream){

    client.recordingStream.play(false);

    client.recordingStream.record(false);

    }

    // Start the new recording. Create a new name for the stream based on the time.

    var recordStreamName = client.publishingStreamName + "-" + new Date().getTime();

    client.recordingStream = Stream.get(recordStreamName);

    client.recordingStream.record();

    client.recordingStream.play(client.publishingStreamName, -1, -1);

    // Run me again in an hour.

    client.chunkInterval - setInterval(application, "chunkRecording", 3600000, client);

    }

    Known Participant
    July 24, 2009

    big thanks

    i tryied client.recordingStream.play(client.publishingStreamName);

    but forgot to pass -1,-1

    now it works thank you

    Known Participant
    July 24, 2009

    ops  there is another problem, new recorded streams are only 281Bytes, i think something wrong is here.

    as i understand

        var recordStreamName = client.publishingStreamName + "-" + new Date().getTime();
        client.recordingStream = Stream.get(recordStreamName);
        client.recordingStream.record();

    Stream.get(recordStreamName); didn’t gets actual stream, it just creates new empty one and records it with 281Bytes.

    Known Participant
    July 24, 2009

    Thank you very much, your code solves my problem

    Known Participant
    July 22, 2009

    Let me to clarify the problem.

    I need to record last 10 days of the stream encoded by FMLE 3.5.

    My DVR player must be able to seek any time during that last 10 days.

    The problem is, that I didn’t find solution how to split files by day and overwrite old ones and how to seek for special time between that splited files.

    July 22, 2009

    Yeah... that's a horse of a diffifferent color.

    In this case, I don't think the out-of-the-box DVR setup is going to work for you. The problem is that (as you've already found) it would be impractical to write the whole 10 days to a single file (and would definitely result in a file bigger than 2GB).

    I'd approach this by recording in chunks (maybe an hour or two in duration), and keeping a record of the start and end times of each file (perhaps in a text file or on a database). I would then change the scrubber behavior to call out to the server with the desired start time, and let the server return the name of the appropriate file to play, and the time within that file that corresponds to the desired playback start time. You can then use a client side netstream.play call to start playback of the recorded stream.

    Known Participant
    July 22, 2009

    please can you tell me how can i make chunk files with serverside actionscript? as i see in documentation there is only one method to record

    stream.record();

    and i can't give to it filename. as i understand recorded stream filename is the same that i set from FMLE stream name, but how can i change it?

    July 22, 2009

    There is no server side timer class, but you can use setInterval to achieve the same results.