shaka-project / shaka-player

JavaScript player library / DASH & HLS client / MSE-EME player
Apache License 2.0
7.06k stars 1.33k forks source link

API request - getting segments urls from the manifest #1074

Closed odedhutzler closed 6 years ago

odedhutzler commented 6 years ago

Hi,

I would like to get the list of the segments URL's that Shaka parses from the manifest.

Will this API be exposed in the future?

I mean, for example: from this mpd: https://cdnapisec.kaltura.com/p/1982551/sp/198255100/playManifest/entryId/0_rgc5b6a0/format/mpegdash/tags/dash/protocol/https/flavorIds/0_t02pp03c/a.mpd

getting a list of these urls: https://vootvideo.akamaized.net/edash/p/1982551/sp/198255100/serveFlavor/entryId/0_rgc5b6a0/v/2/pv/1/flavorId/0_t,02pp03c,xzuhjd4,/forceproxy/true/name/a.mp4.urlset/fragment-1-f1-a1-x3.m4s

Also an option to chose which flavor/bandwidth etc.

Thanks, Oded

TheModMaker commented 6 years ago

Take a look at #1036. You could create a new ManifestParser that forwards to the regular DashParser and then you could look at it before you return it back to the Player. Take a look at the Manifest object and the Manifest Parser tutorial.

To choose initial streams you could create a custom AbrManager to choose the initial streams. Or you could just switch streams after starting playback using player.selectVariantTrack.

joeyparrish commented 6 years ago

We are adding a method to the player to retrieve the parsed manifest. That should simplify things for you.

joeyparrish commented 6 years ago

New method cherry-picked for v2.2.5.

odedhutzler commented 6 years ago

thanks!

odedhutzler commented 6 years ago

hey @joeyparrish, I want to use getManifest, but the variants inside the periods are lack of segments list. How can I can retrieve the segment list per a period? Do i have to create a new manifest parser plugin?

TheModMaker commented 6 years ago

There isn't an exposed list of segments. This is due to the fact that in some Dash manifests there may be infinite segments. For SegmentTemplate with duration attribute, we know all segments from now to the end of the presentation (which for live is infinity). So there may not be an explicit list available.

What you can do is construct a list by using the getSegmentReference method. This takes an index and gives you the reference at that index. Most indexes start at 0, but you can use findSegmentPosition which takes a time and gives the index. You can pass in 0 for VOD or the live edge for Live content.

var list = [];
var i = stream.findSegmentPosition(0);
while (true) {
  var seg = stream.getSegmentReference(i);
  if (!seg) break;
  list.push(seg);
  i++;
}
odedhutzler commented 6 years ago

thanks @TheModMaker ! I will get the URI with list[i].createUris();

bennypowers commented 6 years ago

I, too, am looking to build a list of segments: specifically all the segments which start at the times I have in a pre-determined list of times. (relative to the video's duration)

e.g. for a 5 minute video, I might want to get all the segments which start or surround each minute, on the 0th second.

After poking around the docs and the source code, I'm stumped. I'd be happy to use findSegmentPosition and getSegmentReference to build up a list of segments, but I just don't know where to find those methods, or how to make use of them.

Is the only option to proxy the parser?

joeyparrish commented 6 years ago

No, you can use player.getManifest() to get access to our internal data structure for the parsed manifest. The findSegmentPosition() and getSegmentReference() methods are on Stream, which is inside that manifest structure. The hierarchy is manifest > period > variant > stream (audio/video). Here are the docs for the manifest structure: https://shaka-player-demo.appspot.com/docs/api/shakaExtern.html#Manifest

joeyparrish commented 6 years ago

I'm sorry that the API for this isn't more obvious, but in some cases (DASH, SegmentTemplate+duration, live content), there is no fixed list of segments at all.

@bennypowers, @odedhutzler, can you tell us why you need a list of segments? If we understood the motivation, it might help us prioritize this idea and build a better API for you.

bennypowers commented 6 years ago

In the app I'm building, the player loads along with a pre-made list of time indexes for the video. I want to be able to pre-cache those time indexes so that seeking to them is smooth and seamless. To do that, I need to fetch the relevant segment from the server before the user seeks to it.

imagine a choose-your-own adventure type app that works off of time indexes in one big video stream. You'd want to pre-load the segments for the start of each section of the video, so that the user doesn't have to sit there and buffer.

odedhutzler commented 6 years ago

@joeyparrish I wanted to download the content, using background fetch, so i needed the segment list. The solution @TheModMaker gave worked great for me. Currently we will try and work with shaka offline storage, because bg fetch is not ready yet.