HLS auto-switch

Would this work on a Roku Channel? Is working auto-switch with hls? Thanks!

<media>
<streamQuality>SD</streamQuality>
<streamBitrate>0</streamBitrate>
<streamUrl>http://server...../streamSD/playlist.m3u8</streamUrl>
</media>
<media>
<streamQuality>HD</streamQuality>
<streamBitrate>0</streamBitrate>
<streamUrl>http://server...../streamHD/playlist.m3u8</streamUrl>
</media>

You would have to have something to parse it like:


if xml.parse(data)
videos=[]
for each object in xml.media
video={}
video.streamquality=[object.streamquality.gettext()]
video.streambitrate=[object.streambitrate.gettext().toint()]
video.streamurl=[object.streamurl.gettext]
videos.push(video)
end for
end if 
video.SwitchingStrategy="full-adaptation"

and then feed that into your video playback function. But you should ideally have more data than just the videos, such as title, shortdescriptionLine1 and thumbnail images.

also, you need to check the device mode - if SDTV mode you would override the streamQuality with [“SD”] or playback will fail in SDTV mode.

  • Joel

Actually for HLS, you should NOT specify multiple URLs. You should put the URLs for the different streams in the top-level m3u8 as specified by the HLS spec, and pass that one URL to the video player. This allows the player to dynamically switch bitrates.

–Mark

Thanks!

Hello,

I am new to ROKU and using SampleVideoPlayer code to test my HLS streams. Even though, I have 6 different bit rates in my playlist.m3u8 file, ROKU picks the low quality stream and is not switching to high bit rate. I have enough internet bandwidth to use high quality stream.

Below is the section of code, which loads the streams from XML file:


e = curShow.media[0]
	if e  <> invalid then
		item.StreamBitrates.Push(strtoi(validstr(e.streamBitrate.GetText())))
		item.StreamQualities.Push(validstr(e.streamQuality.GetText()))
		item.StreamUrls.Push(validstr(e.streamUrl.GetText()))
	endif

Below is the XML for an item:


<item sdImg="http://xxxzzz.com/images/gh.png" hdImg="http://xxxzzz.com/images/gh.png">
    <title>My Test Stream 2</title>
    <contentId>10053</contentId>
    <contentType>Movies</contentType>
    <contentQuality>SD</contentQuality>
    <streamFormat>hls</streamFormat>
    <media>
      <streamQuality>SD</streamQuality>
      <streamBitrate>0</streamBitrate>
      <streamUrl>http://yyyzzz.com/playlist.m3u8</streamUrl>
    </media>
    <synopsis></synopsis>
    <subtitleUrl></subtitleUrl>
    <genres></genres>
    <runtime>9600</runtime>
    <hdBifUrl></hdBifUrl>
  </item>

And below is the streams in playlist.m3u8 file:


#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=200000
http://yyyzzz.com/mp4:n_150k.mp4/playlist.m3u8?wowzasessionid=1937835477
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=400000
http://yyyzzz.com/mp4:n_300k.mp4/playlist.m3u8?wowzasessionid=1937835477
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=600000
http://yyyzzz.com/mp4:n_500k.mp4/playlist.m3u8?wowzasessionid=1937835477
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1000000
http://yyyzzz.com/mp4:n_800k.mp4/playlist.m3u8?wowzasessionid=1937835477
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1500000
http://yyyzzz.com/mp4:n_1200k.mp4/playlist.m3u8?wowzasessionid=1937835477
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2300000
http://yyyzzz.com/mp4:n_1800k.mp4/playlist.m3u8?wowzasessionid=1937835477

Any suggestions?

Thank you!

Make sure you are setting the SwitchingStrategy value. A bug was introduced a few firmwares ago that would prevent HLS from switching to a higher bitrate if the SwitchingStrategy wasn’t set. I don’t know if that bug was ever fixed, but it’s best to always set that value.

Thank you for quick reply!

I will add that code and will test again!

“TheEndless” wrote:
Make sure you are setting the SwitchingStrategy value. A bug was introduced a few firmwares ago that would prevent HLS from switching to a higher bitrate if the SwitchingStrategy wasn’t set. I don’t know if that bug was ever fixed, but it’s best to always set that value.

Thank you. It worked. I am using SwitchingStrategy as “full-adaptation”.

Another question - As I mentioned above, I am using HLS streams from Wowza server, which has 6 variants from 150k to 3600k. I read in the documentation that, the dots/HD symbol is not displayed, if the stream is HLS. Is there any way to display HD if any of the variant is of HD quality?

I am using “0” as StreamBitrates in XML.

Any other suggestions for quick switching/buffering/scrubbling?

Thank you!

If you set HDBranded=true the HD logo should show.

  • Joel

Hi Joel,

Do you have a simple live streaming zip, an example which I can build on for live streaming studies? Similar to simple video player?
Sometimes, solutions have a way of staring in my face and I am not able to see it.
Appreciate all the help!

Thanks,

Here’s a simplified version of simplevideoplayer code: that should work to stream a live stream:


sub main()
    print "Displaying video: "
    p = CreateObject("roMessagePort")
    video = CreateObject("roVideoScreen")
    video.setMessagePort(p)

    videoclip = CreateObject("roAssociativeArray")
    videoclip.StreamBitrates = [0]

    videoclip.StreamUrls = ["http://myserver.com/mylivestream.m3u8"]

    di = CreateObject("roDeviceInfo")
    if di.GetDisplayType() = "HDTV" then 
	  videoclip.streamqualities=["HD"]
    else
	  videoclip.streamqualities=["SD"]
    end if
    
    videoclip.StreamFormat = "hls"
    videoclip.Title = "my awesome live stream"
    videoclip.SubtitleUrl = ""
    videoclip.switchingstrategy="full-adaptation"
        
    video.SetContent(videoclip)
    video.show()

    lastSavedPos   = 0
    statusInterval = 10

    while true
        msg = wait(0, video.GetMessagePort())
        if type(msg) = "roVideoScreenEvent"
            if msg.isScreenClosed() then 'ScreenClosed event
                print "Closing video screen"
                return
                exit while
            else if msg.isPlaybackPosition() then
                nowpos = msg.GetIndex()
                if nowpos > 10000
                    
                end if
                if nowpos > 0
                    if abs(nowpos - lastSavedPos) > statusInterval
                        lastSavedPos = nowpos
                    end if
                end if
            else if msg.isRequestFailed()
                print "play failed: "; msg.GetMessage()
            else
                print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
            endif
        end if
    end while
 end sub

Hello everyone. After reading this post, its clear to me that Roku2 can play multibitrate HLS playlist. However, I am new to Roku and I don’t understand how to make this happen. I am using Wowza v3.1.2 and my HLS adaptive bit rate URL (playlist.m3u8) works fine on Apple iphone, ipad and android devices. However, the same URL is not working on Roku 2. One more point, single stream (single bit rate) from same Wowza server works fine on this same Roku 2. What am i doing wrong or what do i need to do, to publish the multi-bitrate HLS playlist to a Roku 2.

Thank you for your assistance.
Regards
Felix

“videodev” wrote:

“TheEndless” wrote:
Make sure you are setting the SwitchingStrategy value. A bug was introduced a few firmwares ago that would prevent HLS from switching to a higher bitrate if the SwitchingStrategy wasn’t set. I don’t know if that bug was ever fixed, but it’s best to always set that value.

Thank you. It worked. I am using SwitchingStrategy as “full-adaptation”.

Another question - As I mentioned above, I am using HLS streams from Wowza server, which has 6 variants from 150k to 3600k. I read in the documentation that, the dots/HD symbol is not displayed, if the stream is HLS. Is there any way to display HD if any of the variant is of HD quality?

I am using “0” as StreamBitrates in XML.

Any other suggestions for quick switching/buffering/scrubbling?

Thank you!

I am having the same issue like the creator of this thread but since I am very new to the topic, I could not figure the solution for the problem from the answers.

What is the code for the “SwitchingStrategy”? How do I do that?
I also point HLS streams to the playlist.m3u8 file and the Roku insists on choosing the stream with the lowest bitrate :disappointed_face: Thanks in advance!

Go to sdkdocs.roku.com and search for “SwitchingStrategy”.

–Mark

So I add a line

<SwitchingStrategy>full-adaption</SwitchingStrategy> in between the <media></media> tag?

That code will be placed in the showFeed.brs if using videoplayer. Search for the first line here and add the rest.

If item.StreamFormat="" 'set default streamFormat to mp4 if doesn't exist in xml
			item.StreamFormat="mp4"
			End If
			If item.StreamFormat="hls"
				item.SwitchingStrategy="full-adaptation"
			End If

That works great, thank you!

Is there any way to use those commands in the XML-File with tags?
I am talking about the commands on the SDK page http://sdkdocs.roku.com/display/sdkdoc42/Content+Meta-Data

I am asking because I would like to know if I really always have to make a package and install it on the Roku or if I can just change it on the fly.

if you add a tag to your XML:

<SwitchingStrategh>full-adaptation</SwitchingStrategy>	

and a line to your xml parser in ShowFeed.brs (assuming your channel is based on videoplayer example):

    item.SwitchingStrategy=validstr(curshow.switchingStrategy.gettext())

probably should put that after the item.StreamFormat= line.

Then you should be able to control which switching strategy is used by your channel on a per-item basis.

You can put whatever you want in your XML, as long as it is valid xml, and you have an xml parser to decode it, you can control your channel completely from your server.

  • Joel

“RokuJoel” wrote:

Do watch out for typos though! :slightly_smiling_face:

“RokuJoel” wrote:
if you add a tag to your XML:


Can I follow that pattern for the other tags also?

I mean adding the code

<XYZ>whatever</XYZ>
to my XML file

and the code
[code]item.XYZ=validstr(curshow.XYZ.gettext())

to the showfeed.brs? or would that be different for the different tags?
Of course XYZ is a tag from the attributes column on http://sdkdocs.roku.com/display/sdkdoc/ … +Meta-Data