kaltura / nginx-vod-module

NGINX-based MP4 Repackager
GNU Affero General Public License v3.0
1.96k stars 431 forks source link

Trouble with adaptive streaming (the meaning of BANDWIDTH parameter) #946

Open VanBur opened 5 years ago

VanBur commented 5 years ago

Hello! I'm using kaltura nginx-vod-module for streaming adaptive HLS and DASH content, and i have a problem with stream validation. We already implemented all your suggestions about media preparation (issue #412), but manifest from kaltura nginx-vod-module is still shows non-valid bandwith (HLS and DASH eather). Parameter BANDWIDTH in master manifest is being calculated as average from first 100K frames, and in most cases doesn't reflect peak bandwith. This causes incorrect behavour of client applications (frequently buffering, buffer overrun), so adaptive isn't working as expected.

BANDWITH attribute expectations by Apple: https://developer.apple.com/documentation/http_live_streaming/hls_authoring_specification_for_apple_devices#//apple_ref/doc/uid/TP40016596-CH2-SW1

1.26. For VOD content, the average segment bit rate MUST be within 10% of the AVERAGE-BANDWIDTH attribute. (See Declared versus measured values of bandwidths.)
1.27. For VOD content, the measured peak bit rate MUST be within 10% of the BANDWIDTH attribute.

I've checked same content by bento4 utils to check master-manifest parameters of same mp4 files and this is example of it: bento4 manifest

#EXTM3U
# Created with Bento4 mp4-hls.py version 1.1.0r624
#EXT-X-VERSION:4
# Media Playlists
#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=4836858,BANDWIDTH=9785776,CODECS="avc1.640028,mp4a.40.2",RESOLUTION=1920x1080
media-1/stream.m3u8
#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=2779347,BANDWIDTH=6163392,CODECS="avc1.640028,mp4a.40.2",RESOLUTION=1280x720
media-2/stream.m3u8
#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=1832273,BANDWIDTH=3893104,CODECS="avc1.4D401E,mp4a.40.2",RESOLUTION=960x540
media-3/stream.m3u8

# I-Frame Playlists
#EXT-X-I-FRAME-STREAM-INF:AVERAGE-BANDWIDTH=846139,BANDWIDTH=1510768,CODECS="avc1.640028",RESOLUTION=1920x1080,URI="media-1/iframes.m3u8"
#EXT-X-I-FRAME-STREAM-INF:AVERAGE-BANDWIDTH=343374,BANDWIDTH=719664,CODECS="avc1.640028",RESOLUTION=1280x720,URI="media-2/iframes.m3u8"
#EXT-X-I-FRAME-STREAM-INF:AVERAGE-BANDWIDTH=239024,BANDWIDTH=490304,CODECS="avc1.4D401E",RESOLUTION=960x540,URI="media-3/iframes.m3u8"

kaltura nginx-vod-module manifest

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1736357,RESOLUTION=960x540,FRAME-RATE=25.000,CODECS="avc1.4d401e,mp4a.40.2"
index-f1-v1-a1.m3u8
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=233265,RESOLUTION=960x540,CODECS="avc1.4d401e",URI="iframes-f1-v1-a1.m3u8"

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2665086,RESOLUTION=1280x720,FRAME-RATE=25.000,CODECS="avc1.640028,mp4a.40.2"
index-f1-v1-a1.m3u8
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=335402,RESOLUTION=1280x720,CODECS="avc1.640028",URI="iframes-f2-v1-a1.m3u8"

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=4678605,RESOLUTION=1920x1080,FRAME-RATE=25.000,CODECS="avc1.640028,mp4a.40.2"
index-f1-v1-a1.m3u8
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=827348,RESOLUTION=1920x1080,CODECS="avc1.640028",URI="iframes-f3-v1-a1.m3u8"

So, there is a question: what we need to do with kaltura nginx-vod-module to get valid master-manifest? And if this is manifest generation state issue – maybe it need to be fixed?

VanBur commented 5 years ago

Hello again! Do you have any suggestions about BANDWIDTH parameter?

erankor commented 5 years ago

Sorry, missed the original message. I am aware of this issue, but in our streams I never bumped into such a large discrepancy as in the sample you pasted (x2 difference between average & peak), so this never got a high enough priority. I'll add it to the backlog, but not sure when I'll be able to handle it

waveletbeam commented 2 years ago

@erankor : We are facing the same problem with the BANDWIDTH tag. The values are average bitrates and and not peak values. We are no able to use the apple validation tools and we also get error messages from the client devices.

Is there a workaround available or do you have an advice for a bug-fix?

EXT-X-STREAM-INF:

The following attributes are defined: BANDWIDTH The value is a decimal-integer of bits per second. It represents the peak segment bit rate of the Variant Stream. If all the Media Segments in a Variant Stream have already been created, the BANDWIDTH value MUST be the largest sum of peak segment bit rates that is produced by any playable combination of Pantos & May Expires March 24, 2017 [Page 27] Internet-Draft HTTP Live Streaming September 2016 Renditions. (For a Variant Stream with a single Media Playlist, this is just the peak segment bit rate of that Media Playlist.) An inaccurate value can cause playback stalls or prevent clients from playing the variant. https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-20 https://developer.apple.com/documentation/http_live_streaming/example_playlists_for_http_live_streaming/creating_a_primary_playlist
shruggingatlas commented 2 years ago

@erankor same issue here. We are willing to sponsor the necessary work. If interested, please let me know how.

eduardopuente commented 2 years ago

any updates?

shruggingatlas commented 2 years ago

@erankor in the last couple of weeks, together with German public broadcaster NDR, we at G&L have managed to engage @sannies to take care of this issue on our behalf. He has made good progress. The current plan is to prepare a pull request within the next two weeks.

sannies commented 1 year ago

Hi here, I submitted a draft PR about 6 weeks ago but no reaction so far. I'm still willing to put more work into it but I'd need some feedback from perhaps @erankor

feedanal commented 1 year ago

@erankor , would be very nice to have this merged, as we also encounter weird playback issues on Apple devices with 'native' HLS, and their HLS validation tools report lots of issues with manifests generated by Kaltura, example:

2. I-frame playlists ( EXT-X-I-FRAME-STREAM-INF ) MUST be provided to support scrubbing and scanning UI
Multivariant Playlist
3. You MUST include the AVERAGE-BANDWIDTH attribute
Multivariant Playlist Stream Definition for All Variants
4. If EXT-X-INDEPENDENT-SEGMENTS is not in the multivariant playlist, then you MUST use the EXT-X-INDEPENDENT-SEGMENTS tag in all video media playlists
All Variants