HTTP Live Stream Issue

I have been working on a MediaPortal channel over the past few weeks and in general it works really well on most clients except Android and Plex/Web.

 

The Plex/Web client will just spin indefinitely while trying to load the video. A quick glance with Fiddler shows me that the request for the data will load for quite some time before throwing a 404 error. When I look at the logs its repeatedly calling my PlayStream function until it timeouts.

 

The Android client will actually play video for about 3-5 seconds before it closes the video and goes back to the previous screen. There are no errors in the logs for either client.

 

Here is the relevant code from my URL Service:

def MediaObjectsForURL(url):
	return [
		MediaObject(
			parts = [PartObject(key=HTTPLiveStreamURL(Callback(PlayStream, url=url, profile="HTTP Live Streaming medium")))],
			height = 480,
			width = 600,
			bitrate = 640,
			protocol = "hls",
			container = "mp4",
			video_codec = "h264",
			audio_codec = "aac",
			audio_channels = 6
		)
	]
def PlayStream(url, profile):
mp = MediaPortal(url, profile)
playlist_url = None
active = False

try:
	sessions = mp.request_url(mp.streaming_sessions)
	session_length = len(sessions)

	for s in sessions:
		if mp.id == str(s["Identifier"]):
			active = True

	if active == True:
		playlist_url = mp.custom_transcoder_data % (mp.id)

	else:
		if session_length > 0:
			close = mp.close_streams()

		init = mp.request_url(mp.init_stream, values = {"identifier": mp.id, "itemId": mp.id, "type": "12"})
		start = mp.request_url(mp.start_stream, values = {"identifier": mp.id, "profileName": mp.profile})
		playlist_url = start["Result"]
	return Redirect(playlist_url)
except Exception, e:
	Log(e)
	raise Ex.MediaNotAvailable

 

I can attach the MediaPortal class but essentially it has a bunch of hard coded URLS and JSON.ObjectFromURL calls. Here is what the playlist_url URL returns:



#EXTM3U
#EXT-X-TARGETDURATION:7
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:7,
http://192.168.1.1:4322/MPExtended/StreamingService/stream/CustomTranscoderData?identifier=11&action=segment&parameters=000001.ts
 
Does anyone have any ideas on what I'm doing wrong?

Do you update the playlist for each request? Since the #EXT-X-ENDLIST is not present in the playlist, clients will request the playlist over and over again, looking for new segments. If the playlist is not updated, it seems reasonable that for example the Android client closes after a while(the first segment is 7 seconds)

From the specification:

If the Playlist does not contain the EXT-X-ENDLIST tag, the server
MUST make a new version of the Playlist file available that contains
at least one new media segment. It MUST be made available relative
to the time that the previous version of the Playlist file was made
available: no earlier than one-half the target duration after that
time, and no later than 1.5 times the target duration after that
time.

See chapter 6.2.1 and 6.2.1 in http://tools.ietf.org/html/draft-pantos-http-live-streaming-07

Hi!

The value of the container format (mp4) is wrong, for HLS this should be "mpegts", but since you're using HTTPLiveStreamURL, you can leave out protocol, container, audio_codec and video_codec (they will be set automatically).

Another reason why the Flash based video player fails, could be a crossdomain issue. See the heading "Crossdomain Restrictions" here for more info.

Thanks for the tips meo and sander1. I am now one step closer to making this work. The flash player will now load the first segment but nothing after that. The playlist itself is continuously updated with new segment URLs though. The one thing I did notice is that the playlist never removes any segments that it has already served up. Basically the playlist just keeps getting larger and larger. Could that be an issue? Here is what my code looks like now:

 

def MediaObjectsForURL(url):
	return [
		MediaObject(
			parts = [PartObject(key=HTTPLiveStreamURL(Callback(PlayVideo, url=url, profile="HTTP Live Streaming medium")))]
			,height = 480
			,width = 600
		)
	]
def PlayVideo(url, profile):
mp = MediaPortal(url, profile)
playlist_url = mp.custom_transcoder_data % (mp.id)

try:
	close = mp.close_streams()
	init = mp.request_url(mp.init_stream, values = {"identifier": mp.id, "itemId": mp.id, "type": "12"})
	start = mp.request_url(mp.start_stream, values = {"identifier": mp.id, "profileName": mp.profile})

	return "#EXTM3U

#EXT-X-STREAM-INF:PROGRAM-ID=" + mp.id + ",BANDWIDTH=832000,RESOLUTION=600x480
" + playlist_url
except Exception, e:
Log(e)
raise Ex.MediaNotAvailable

Do you update the playlist for each request? Since the #EXT-X-ENDLIST is not present in the playlist, clients will request the playlist over and over again, looking for new segments. If the playlist is not updated, it seems reasonable that for example the Android client closes after a while(the first segment is 7 seconds)

From the specification:

See chapter 6.2.1 and 6.2.1 in http://tools.ietf.org/html/draft-pantos-http-live-streaming-07

i don't think the playlist is updated for each request. It looks like the Flash player requests the playlist almost every second and the playlist itself is only updated every 7 seconds.

i don't think the playlist is updated for each request. It looks like the Flash player requests the playlist almost every second and the playlist itself is only updated every 7 seconds.

Sorry, my bad, what I meant was the quote from the HLS spec, i.e. your approach of updating every 7 seconds seems fine.

Take a look at the below example(taken from a swedish tv channel live HLS stream):

First version:

#EXTM3U

#EXT-X-TARGETDURATION:10
#EXT-X-ALLOW-CACHE:YES
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:136655230
#EXTINF:10.000,
segment136655230_6_av-b.ts?sd=10&rebase=on&e=1
#EXTINF:10.000,
segment136655231_6_av-b.ts?sd=10&rebase=on&e=1
#EXTINF:10.000,
segment136655232_6_av-b.ts?sd=10&rebase=on&e=1

After a while:

#EXTM3U

#EXT-X-TARGETDURATION:10
#EXT-X-ALLOW-CACHE:YES
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:136655237
#EXTINF:10.000,
segment136655237_6_av-b.ts?sd=10&rebase=on&e=1
#EXTINF:10.000,
segment136655238_6_av-b.ts?sd=10&rebase=on&e=1
#EXTINF:10.000,
segment136655239_6_av-b.ts?sd=10&rebase=on&e=1

(I've "cleaned" the paths a bit, but that should not be relevant here)

This example shows that the "old" segments are removed, but I can't see in the specification that you MUST do that.... There are quite a few more requirements(see http://tools.ietf.org/html/draft-pantos-http-live-streaming-07#section-6.2.2) attached if doing this.

One thought about this is that maybe the client looks at the #EXT-X-MEDIA-SEQUENCE tag to see if there are any new segments, i.e. if it has increased since the last time? This shouldn't be the way to do it in a correct way though...

Sorry, my bad, what I meant was the quote from the HLS spec, i.e. your approach of updating every 7 seconds seems fine.

Take a look at the below example(taken from a swedish tv channel live HLS stream):

First version:

After a while:

(I've "cleaned" the paths a bit, but that should not be relevant here)

This example shows that the "old" segments are removed, but I can't see in the specification that you MUST do that.... There are quite a few more requirements(see http://tools.ietf.org/html/draft-pantos-http-live-streaming-07#section-6.2.2) attached if doing this.

One thought about this is that maybe the client looks at the #EXT-X-MEDIA-SEQUENCE tag to see if there are any new segments, i.e. if it has increased since the last time? This shouldn't be the way to do it in a correct way though...


This playlist is coming from MediaPortal so I don't think I can change it directly. That being said, I'm thinking I could make a new playlist route in my channel that mimics the functionality in the Swedish tv stream you mentioned above. I will let you know how it goes. Thanks for your help meo.

I was unable to get this working by creating a playlist route that mimics the functionality found in other HTTP Live Streams. An interesting thing to note is I actually get a very similar issue with aMPdroid (a MediaPortal client for Android). The first 5 or so seconds of video will play and then immediately error out. I am attempting to get some help in the MP forums now. Thanks for everyone's help.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.