Giter VIP home page Giter VIP logo

Comments (3)

dcoufal avatar dcoufal commented on May 27, 2024

Yes! This is possible. I'm assuming that this is for VOD from context. This doesn't really work for Live playlists, since the concept of absolute time is not really present there, FYI.

I'm describing this from memory, so please feel free to come back to this ticket to ask for clarification.

This is how I would do it in mamba:

(1) Make a custom HLSTagDescriptor that contains your EXT-X-MYCUSTOMTAG tag. You can look at PantosTag to see how to do this, and there are also examples in the unit tests. The important thing that you have to do is that public func scope() -> HLSTagDescriptorScope should return .mediaSegment for EXT-X-MYCUSTOMTAG. This tells mamba that your custom tag belongs with media segments and it will show up in the mediaSegmentGroups (described below!)

(2) You'll have to parse your playlist as usual, making sure to pass your custom HLSTagDescriptor in the initializer of HLSParser (i.e. let parser = HLSParser(tagTypes:[MyCustomTagDescriptor.self])

(3) Once you have your parsed playlist, you can find your tags let tags = playlist.tags.filter { $0.tagDescriptor == MyCustomTagDescriptor.myCustomTag }. You also want the indices of each tag, so let indices = tags.compactMap { playlist.tags.index(of: $0) } <- assumes Swift 4.2

(4) Part of parsing a HLS playlist is dividing the playlist up into sections. There's a "header", a bunch of "media segment groups" and a "footer". We're interested in the "media segment groups".

A "media segment group" is minimally:

#EXTINF:5.005,
789.ts

Every "media segment group" is delimited by a .Location tag, which is the url (usually relative) of the media segment.

But if there are other tags that have HLSTagDescriptorScope.mediaSegment scope, and they are before the .Location tag, they will be put into the "media segment group", i.e.:

#EXT-X-MYCUSTOMTAG:ID="2",X-CUSTOM-ATTRIBUTE="VAL2" <- Part of this group
#EXTINF:5.005,
789.ts

"media segment group"s (which are MediaSegmentTagGroup in mamba code) have all kinds of useful properties, but for you you care that they have time info in them.

Given this, we can loop through the indices to get start and end times:

for index in indices {
  guard let timeRange = playlist.timeRange(forTagIndex: index) else {
    break
  }
  let startTime = timeRange.start
  let endTime = timeRange.end
  let duration = timeRange.duration
}

So, you can do anything you want with the start/end/duration of that segment.

Hope this helps!

from mamba.

dcoufal avatar dcoufal commented on May 27, 2024

Leaving this open. Ideally this would be in a playground as sample code as it's a pretty common use case.

from mamba.

dcoufal avatar dcoufal commented on May 27, 2024

Closing this in favor of #42

from mamba.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.