Comments (3)
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.
Leaving this open. Ideally this would be in a playground as sample code as it's a pretty common use case.
from mamba.
Closing this in favor of #42
from mamba.
Related Issues (20)
- Enable module stability. Now can't use with Swift 5.3.2. HOT 5
- Swift Compiler Code Optimization
- Add Swift Package Manager Support HOT 1
- Tag new release 1.5.6 HOT 6
- Remove `HLS` prefix from all classes HOT 1
- Should be an interface to figure out the muxed/demuxed makeup of an asset HOT 1
- The `playlistType` for a variant playlist should be cached and not calculated every time. HOT 1
- Add a simple function to return segment based info from info about a tag to look for. HOT 1
- Remove the HLSTagCriteria and HLSTagCriterion Query Language objects HOT 1
- v 1.2.0 cocoapods HOT 12
- Add more owners to podspec
- Carthage Build Error HOT 9
- Revert deployment changes made in #61 HOT 2
- Using .transform and replacing a tag of tagDescription PantosTag.Location results in a invalid playlist with literal #Location HOT 3
- How could I add it in my project ? HOT 1
- LHLS Support - Low-Latency HLS HOT 1
- improve (HLS)ValidationIssue HOT 2
- Swift Package Manager support? HOT 1
- Parsing malformed HLS causes crash
- Updating podspec to include fix for static libraries HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mamba.