How to make use of play2() function in order to perform fast stream switching of videos?
Asked Answered
C

2

50

I am currently working on a Flash webplayer with resolution switching functionality. I am trying to make use of the NetStream class's play2() function in Actionscript.

The problem I am running into is that the videos don't change quickly. For those familiar with the play2() function I believe that the player is performing a "standard switch" rather than a "fast switch."

The documentation says that when the offset parameter is -1, fast switching occurs. What actually happens, though is once the "NetStream.Play.Transition" event is received, the player waits until the time denoted by ns.time + ns.bufferLength has been reached, before performing the switch.

I thought fast switching cleared the buffer, but on a check to ns.backbufferlength, I found that everything is still cached. Also it mentions: "When offset is -1, the switch occurs at the first available keyframe after netstream.time + 3," which is why I am confused.

Any help/insight on this matter would be much appreciated.

Here is a snippet of code describing what is going on (newStream() is called when a user clicks to change to a new resolution, youtube style):

public function newStream(address:String):void
{
    var opts:NetStreamPlayOptions = new NetStreamPlayOptions();
    opts.streamName = address;
    opts.transition = NetStreamPlayTransitions.SWITCH;
    opts.offset = -1;
    ns.play2(opts);
}

private function nsCallback(event:NetStatusEvent)
{
    switch(event.info.code)
    {
        case "NetStream.Play.Transition":
        {
            trace("Current time (on Transition): " + 
                  ns.time, "Buffer: " + ns.bufferLength);
            var estTime:Number = ns.time + ns.bufferLength;
            trace("Estimated Completion Time: " + estTime);
            break;
        }
    }
}
Colonialism answered 27/7, 2011 at 17:0 Comment(7)
Have you looked into a framework that does Dynamic Stream Switching for you? I use one because it allows me to focus on other things (one less thing I have to worry about). OSMF will do a lot, but not DSS for http streams (yet). However, OVP (Akamai HDCore) will even do DSS for http streams to flash. Good luck!Itin
I found a few while Googling for an answer to my question, but I was a building a pretty specific player (there are a few extra features that I added to it). Also, since I already had the majority of the player done (minus the "smooth" transitioning), I was hoping for a solution. As of now, I've made do with adding a little "loading" icon anytime there is a stream switch, though I have left the functionality available in case I ever do find an answer for this issue.Colonialism
instead of a switching the video of same content can this be used to switch to a different video stream?Teakettle
Have you tried these "Best practices" from Adobe? help.adobe.com/en_US/flashmediaserver/devguide/…Mezzanine
Pay attention to the video streams you are trying to play and switch. They need to be carefully encoded, especially keyframe value should be set to the same value for all videos/streams. Setting this property depends on if you are playing live or VOD media, or the software you are encoding with.Phocomelia
@MaxGolovanchuk is right. Sometimes keyframes can be pretty far apart. I've seen 10 or 15 seconds.Bettyannbettye
@MaxGolovanchuk There may be keyframe mismatch issue, but for some reason, it still only transitions when the playhead hits the end of the buffer (otherwise, it would transition on the next key frame interval, regardless of what was in the buffer).Colonialism
B
1

As the Documentation says: "The default value of offset is -1, which defaults the switching behavior to standard. In this mode, the server determines a good transition point between the streams forward in time from the point it receives the switch call, and switches at that point."

So you have to change the 'offset' parameter to a value higher than the current playback time (Netstream.time). If the value is less, a NetStream.Play.Failed status event is sent.

Bedfordshire answered 28/12, 2012 at 11:33 Comment(4)
What part of the documentation says offset = -1 is standard switch mode? What I'm looking says this: "The default value of offset is -1, which is fast switch mode." You can find this quote here. Second paragraph, first sentence under "Fast Switch"Colonialism
Also, according the doc, it is not required to set 'offset' to a value greater than the current playback time, because, by default, "When offset is -1, the switch occurs at the first available keyframe after netstream.time + 3"Colonialism
@Colonialism - That is a sort of strange, because I use an offline Documentation (for flash cs5) and it has written "The default value of offset is -1, which defaults the switching behavior to standard." whereas I checked the online documentation and I saw that it has written "The default value of offset is -1, which is fast switch mode." Check it out: dropbox.com/s/2qm143e6mc93byl/offline.pngBedfordshire
Odd - have you tested this to see if it works? I remember trying to set the offset parameter explicitly and it not working as expected (the buffer didn't clear when the playhead reached the expected time)Colonialism
E
1

It could be that the server is trying to find the nearest i-frame to the current offset and that takes time. If you know what FPS is and the time between two i-frames is you could try to seek to a time very near to the next or previous i-frame, that would speed up the search and serving.

more info on i-frame: http://en.wikipedia.org/wiki/Video_compression_picture_types

Evonneevonymus answered 30/1, 2013 at 13:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.