how to select quality from HLS Stream

I'm trying to figure out how can I make a HLS Stream videoclip work.

 

I have the m3u8 link so I did something like this because I read that Plex framework will handle the playback for me:

# url contains the m3u8 link
# title a string to use as title
# thumb an image link to use as thumbnail
def play(url, title, thumb):
  oc = ObjectContainer( title2 = title )

oc.add(VideoClipObject(
key = Callback(
play,
url = url,
title = title,
thumb = thumb
),
rating_key = title,
items = [
MediaObject(
protocol = Protocol.HLS,
container = Container.MP4,
video_codec = VideoCodec.H264,
audio_codec = AudioCodec.AAC,
audio_channels = 2,
parts = [
PartObject(
key = url
)
]
)
],
title = title,
thumb = Resource.ContentsOfURLWithFallback(url = thumb)
))

return oc

And indeed it works but the quality of the video is horrible.

 

I have downloaded the m3u8 to have a look inside and it looks like this:

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=500000
http://foo.bar/baz/MB_500/chunklist.m3u8?secureHash=OTUuMjAuNS4yMDU=&nva=20150405194831&token=02ba9cef8c1589bb3323b
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1200000
http://foo.bar/baz/MB_1200/chunklist.m3u8?secureHash=OTUuMjAuNS4yMDU=&nva=20150405194831&token=00f41f436a008a009e489
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2000000
http://foo.bar/baz/MB_2000/chunklist.m3u8?secureHash=OTUuMjAuNS4yMDU=&nva=20150405194831&token=031d311bc14d6aa28dcd5

So looks it contains 3 different qualities for the stream.

 

Is there a way to specify which of the qualities to use in the MediaObject? Or must I create a Callback to extract all that data myself and create a MediaObject for each quality? Anyone knows a channel doing something similar?

 

Thanks.

HLS is designed to supply the best quality depending on the line quality and the qualities available in the m3u8 file, rather than allowing the client to select the required quality from a site that offers say 4 different bitrates, in which case you would have to create a PartObject for each quality. I don’t think there is a way to force a minimum bitrate with hls, but if there is there’s probably no way for plex to enforce this

HLS is designed to supply the best quality depending on the line quality and the qualities available in the m3u8 file, rather than allowing the client to select the required quality from a site that offers say 4 different bitrates, in which case you would have to create a PartObject for each quality. I don't think there is a way to force a minimum bitrate with hls, but if there is there's probably no way for plex to enforce this

Then I don't understand why when I play the clip in the website the quality is good and when I try it in plex web with my coded channel the quality is poor. I will try with other plex clients just in case.

Thanks for the heads-up.

Well, I recall that maybe while I was testing the channel my connection was being used by another device on my network so maybe at that moment my bandwidth was poor. So that could be the problem. I will try tomorrow again.

Then I don't understand why when I play the clip in the website the quality is good and when I try it in plex web with my coded channel the quality is poor. I will try with other plex clients just in case.

Thanks for the heads-up.

Well, I recall that maybe while I was testing the channel my connection was being used by another device on my network so maybe at that moment my bandwidth was poor. So that could be the problem. I will try tomorrow again.

Manfer, 

Did you ever figure out why Plex chose the lowest quality in the manifest m3u8? I'm running into the same issue. I've got 3 or 4 different qualities/resolutions available. 480p up to 1080p. For whatever reason, plex only plays the 480p version. If i download the m3u8 and then hardcode the higher quality URL into my service code, Plex plays it just fine. It just doesn't automatically select. 

Edit: What i've found is that if Plex just plays the first file in the manifest. So if that's the 480p version, that's what it uses. I discovered this by downloading and then manually re-arranging the order of the files inside the manifest so that 1080p was listed first. I then uploaded it to the web and pointed my service code at it, and what do you know, i get 1080p. 

@mattrk said:

Edit: What i’ve found is that if Plex just plays the first file in the manifest.

It depends on the Plex client, but yes, certain Plex clients do not support adaptive streaming and stick with the first stream (usually the one with the lowest quality).