Skip to main content
January 26, 2007
Question

serverside stream manipulation

  • January 26, 2007
  • 2 replies
  • 1176 views
Hi

I was wondering. is it possible to manipulate in any way the video streams on the server side? Like for example, to have two streams coming from two clients and mix them into one stream, so a third client (or more) can play just one stream per client instead of two?
    This topic has been closed for replies.

    2 replies

    January 30, 2007
    Can you give an example of that, sinergia? I was looking into this in the docs, but the examples didn't make much sense.
    Participating Frequently
    July 3, 2009

    If you want to just play one client stream after one another that's simple. You can do it this way:

    var myStream;

    application.onAppStart = function(){

         myStream = Stream.get("hello");

    }

    application.onPublish = function(newClient,newStream){

           myStream.play(newStream.name);

    }

    Now here client would be suscribing only to "hello" - but above code is very trivial and would work when one client's publish is followed by another client's publish.

    But if you want it to be mixed say play one client's publish for 30 seconds and second client's publish for next 30 secs and so on so forth - you might have to do following type of thing - I am just writing code on the fly , you can correct it when you are actaully trying it out. -

    var myStream;

    var cStream;

    var count=0;

    var intervalID;

    var playing=1;

    application.onAppStart = function(){

         myStream = Stream.get("hello");

         myStream.onStatus = function(info){

              if(info.code == "Netstream.Play.Stop"){

                   playing++;  

                   if(cStream[playing%2] !=null)

                    myStream.play(cStream[playing%2].name,-1,30,true);

             }

         }

         cStream = new Array();

    }

    application.onPublish = function(newClient,newStream){

         cStream[count++] =  newStream;
      
         intervalID = setInterval(startPlay,10);
    }

    application.onUnpublish = function(newClient,newStream){

         if(cStream[0].name == newStream.name)
            cStream[0] = null;
         else
           cStream[1] = null;
    }

    function startPlay(){

         playing=2;

         myStream.play(cStream[playing%2].name,-1,30,true);

    }             

    Again i am just writing this on the fly - please pardon my code errors if any.

    July 3, 2009

    Just so it's mentioned... if you're using server side switching on a common stream, and you're not setting the client side buffer to zero, you may find that the video starts to lag. I find that clearing the setting the buffer to zero and then back to your desired buffer time in the onPlayStatus handler elimitates the lag, but depending on the length of your buffer, the video can pause for a bit (while the buffer fills back up).

    If anyone knows a better solution to this, I'd love to hear it. The approach I'm using feels a bit hackish.

    January 26, 2007
    Nope. FMS can't do that.
    Participating Frequently
    January 30, 2007
    on server side you can only create a new stream (real-time) chaining cuts of various stream.