videojs / http-streaming

HLS, DASH, and future HTTP streaming protocols library for video.js
https://videojs-http-streaming.netlify.app/
Other
2.49k stars 421 forks source link

Parsing of the #EXT-X-MAP tag assumes fragmented MP4s #151

Open ghost opened 6 years ago

ghost commented 6 years ago

gnujosh commented on Feb 3, 2017, 7:35 PM UTC:

Description

We have a mpeg2ts file that we wish to provide a playlist on, but it requires that we use the EXT-X-MAP tag. However, it appears that the current implementation assumes that the EXT-X-MAP uses fragmented mp4s, so the playlist fails.

Sources

We resolved the issue by making a few small changes in several locations. Perhaps there is a better way to test for the segment type?

In segment-loader.js: handleSegment_()

      if (segment.map) {

to

      if (segment.map && !segment.uri.endsWith('.ts')) {

In sync-controller.js: probeSegmentInfo()

      if (segment.map) {

to

      if (segment.map && !segment.uri.endsWith('.ts')) {

and in master-playlist-controller.js: mimeTypesForPlaylist_

if (media.segments && media.segments.length && media.segments[0].map) {

to

if (media.segments && media.segments.length && media.segments[0].map && !media.segments[0].uri.endsWith('.ts')) {

Steps to reproduce

Try to use a playlist like:

#EXTM3U
#EXT-X-TARGETDURATION:103.336567
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-VERSION:4
#EXT-X-MAP:URI=out.ts,BYTERANGE=376@53016
#EXTINF:2.502500,
#EXT-X-BYTERANGE:500832@53392
out.ts
#EXTINF:2.502500,
#EXT-X-BYTERANGE:508164@554224
out.ts
...

Results

Expected

Playlist to play normally.

Error output

Just running out of the box, you get this message.

VIDEOJS: WARN: Failed to create Source Buffers DOMException: Failed to execute 'remove' on 'SourceBuffer': The start provided (0) is outside the range (0, 0).(…)
video.js:22914 VIDEOJS: ERROR: DOMException: Failed to set the 'duration' property on 'MediaSource': The MediaSource's readyState is not 'open'.(…)logByType @ video.js:22914log.error @ video.js:22950data.dispatcher @ video.js:22495trigger @ video.js:22615EventTarget.trigger @ video.js:7207
video.js:22914 VIDEOJS: ERROR: (CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED) The media could not be loaded, either because the server or network failed or because the format is not supported. MediaError {code: 4, message: "The media could not be loaded, either because the …rk failed or because the format is not supported."}

If you fix master-playlist-controller.js, you get different messages, but they all come down to assuming a segment with a map has mp4 data in it.

Additional Information

videojs-contrib-hls version

videojs-contrib-hls 5.1.0 (although this problem still exists in trunk)

videojs version

video.js 5.15.1

Browsers

Platforms

Other Plugins or javascript

None

This issue was moved by forbesjo from videojs/videojs-contrib-hls#991.

ghost commented 6 years ago

imbcmdth commented on Feb 3, 2017, 7:44 PM UTC:

What do you do with the data pointed to by the map? MPEG2TS don't really have a concept of the "initialization segment" - what is usually pointed to by the EXT-X-MAP header.

What is in that 376 bytes? Does it contain the PSI and PMT packets?

I am curious but this is a good point and something we should look into. Can you submit a PR with your changes so we can discuss this further?

ghost commented 6 years ago

gnujosh commented on Feb 3, 2017, 8:03 PM UTC:

Yeah, I think it was the PAT and PMT packets that were within that 376 bytes. We are under some constraints with the data we are working with, so we can't ensure that the files we are given will start with PAT / PMT packets since we can't change how they are written to disk.

I'm a bit of a github noob, so I'm not sure what you mean with "submit a PR". Since it was just a few changes in a few spots, I thought it would be easier to just point out the locations of changes we made rather than download git, clone the repo, download npm, and get all the tooling set up.

ghost commented 6 years ago

mjneil commented on Feb 3, 2017, 10:52 PM UTC:

PR stands for pull request

Since the changes are small enough, you can do this all through the github website.

First you would want to fork this repo, go to the fork in your repositories and edit the files with these changes and when committing the changes, just make sure "Create a new branch for this commit and start a pull request." is selected. (Since you make changes on multiple files, just make sure to not have "Create a new branch for this commit and start a pull request." selected for the other files, but instead just make sure you are currently viewing your newly created branch and just have "Commit directly to the your-branch branch." selected)

ghost commented 6 years ago

gnujosh commented on Feb 6, 2017, 4:34 PM UTC:

OK, I hope I was able to get the order correct, my attempt at a pull request is here: #996

ghost commented 6 years ago

forbesjo commented on Jul 11, 2018, 8:07 PM UTC:

This is currently in progress in https://github.com/videojs/http-streaming

forbesjo commented 5 years ago

This will be fixed in a branch @gesinger is working on. That PR should be resolved relatively soon