Delayed stream: Using FMS for semi-live broadcasting

When you watch a live show on TV, its never really live. Its not only the foregone latency made by the different machines - but a very intended delay designed to let the editor a way to stop the transmitting if they fill such need.

You can use your imagination to complete the possible scenario.

Unfortunately, Adobe's Encoder or Flash Media Server don't have live stream delay feature out of the box. So, if you want to have such delay with Adobe FMS, you will need some server-side scripting. (Go ahead, fill a request to adobe's wish list)

On the other hand, this will be quite simple.

[NOTE: The code here is not real tested code.]

Step 1: Record your stream.

  • Method 1:
    You can use SSAS (Server Side ActionScript) to the live stream. Adobe's documentation is fairly descriptove: Stream.record()
    What you actually do is adding the recording functionality to the Application.onPublish event. Your final code will be similar to:


    application.onAppStart = function()
    {
     trace("Starting recoding application");
    };
     
    application.onConnect = function(clientObj)
    {
     this.acceptConnection(clientObj);
    };
     
    application.onPublish = function (clientObj , stream)
    {
     trace("Publish: "+stream.name);
     stream.record();
    };
    application.onUnpublish = function(clientObj, stream)
    {
     trace("Unpublish: "+stream.name);
     stream.record(false);
    };
    
    


    NOTE: Recording using this method will save the file with its default name:
    "When you record a stream, the server creates a file with the
    name you passed to the Stream.get() method. The
    server automatically creates a “streams” directory and subdirectories
    for each application instance name. If a stream isn’t associated
    with an application instance, it is stored in a subdirectory called “_definst_”
    (default instance). For example, a stream from the default lecture application
    instance would be stored here: applications\lectures\streams\_definst_.
    A stream from the monday lectures application instance would be
    stored here: applications\lectures\streams\monday. "
  • Method 2:
    If you are using Adobe's Flash Media Live Encoder - you can simply tick the record checkbox.
Step 2: Play it on your own time (Delayed)
Now, when you start your broadcasting - use the Stream.play() method to stream the recoded file to everyone.

The play function can link one file after another.. so we can add a preliminary video file as a place holder for the delayed time and than add the recorded file right afterward.
Doing that - we can easily use the "onPublish" event to make it all work so our code will be similar to this one:


    
application.onPublish = function (clientObj , stream)
{
 trace("Publish: "+stream.name);
 stream.record() 

stream.play("placeHolder.flv", -1, -1);

stream.play("recorded.flv", -1, -1);

};

application.onUnpublish = function(clientObj, stream)
{
 trace("Unpublish: "+stream.name);
 stream.record(false);

stream.play(false);
};



Enjoy!

WebResources - Watch the creation time

One day I had a simple task to do: take one site, fully working with no issues and load it on another server.

It sounds simple. Well, just like any real time-stealing task everything went fine till I tested it and from some odd reason some of the menus and visual components went crasy.

The problem we saw was bad request or denied access to the .axd compiled resources on page. 

After hours of investigation I found it: The servers TIME & DATE were wrong. When you upload a compiled resource - the server use the creation date to create a key for that resource. That key probably being computed using the current date and file's creation date. When the creation date is in the future - the calculation returns some invalid value and that resource is being denied.

I hope I saved someone's time..