Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Type conversion from M3u8::Playlist to M3u8::PlaylistItem #26

Closed
waterjump opened this issue Aug 22, 2018 · 3 comments
Closed

Comments

@waterjump
Copy link

waterjump commented Aug 22, 2018

Recently I had a use case where I was looking to convert a M3u8::Playlist to M3u8::PlaylistItem. I was a bit surprised it's not supported by this gem, and that PlaylistItem instances need to be built from an options hash. This doesn't seem like a rare use case, especially when working with a master playlists, parsing media playlists they contain, working with them, and building a new master playlist as a result.

Here's a short example use case I'm imagining:

my_file = File.open('spec/fixtures/media_playlist-664.m3u8')
media_playlist = M3u8::Playlist.read(my_file)
playlist_item = M3u8::PlaylistItem.new(media_playlist)

My temporary workaround for this is to dump all of a Playlist's instance variables into a hash (excluding items, etc.) and building a new PlaylistItem from that. If there's a more intuitive way to do this that I'm missing, please let me know.

A secondary solution could be to implement a Playlist#to_options method that returns an options hash that allows for easy creation of a PlaylistItem:

my_file = File.open('spec/fixtures/media_playlist-664.m3u8')
media_playlist = M3u8::Playlist.read(my_file)
playlist_item = M3u8::PlaylistItem.new(media_playlist.to_options)

If you are on board with the feature request, I'll be happy to write the specs and open a PR.

Thanks!

@waterjump waterjump changed the title Feature request: Type conversion from M3u8::Playlist to M3u8:PlaylistItem Feature request: Type conversion from M3u8::Playlist to M3u8::PlaylistItem Aug 22, 2018
@sethdeckard
Copy link
Owner

HI @waterjump, I'm a little confused by your request. A PlaylistItem represents the EXT-X-STREAM / EXT-X-I-FRAME-STREAM-INF tags in a master playlist, how do you build a instance of PlaylistItem from the attributes in a Playlist? Assuming the Playlist is a media playlist which would look something like this:

#EXTM3U
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-DISCONTINUITY-SEQUENCE:8
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:12
#EXTINF:11.344644,
1080-7mbps00000.ts
#EXT-X-DISCONTINUITY
#EXTINF:11.261233,
1080-7mbps00001.ts
#EXTINF:7.507489,
1080-7mbps00002.ts

Let me know if I've overlooked something in your request, which wouldn't surprise me. :-)

@waterjump
Copy link
Author

Hi Seth,

Thanks for your quick response. After typing out several hundred words detailing my issue, I realized that the tags found in a media playlist are not congruent to the tags about a media playlist in the context of a master playlist, so it doesn't make sense to transmute between the two types like I thought it would. Basically, I rubber-ducked it and saved you a lot of reading I hope.

Closing

@sethdeckard
Copy link
Owner

Hi @waterjump, I see what you were trying to do now. As you already realized it's outside the scope of this project since this library doesn't actually do anything with the MPEG-TS segments referenced in a media playlist and you would need to know the media information (codecs, bitrate, etc) to generate the attributes for a variant/master playlist. However, there are some other tools that can help you with just that. You might want to take a look at variantplaylistcreator, one of the CLI tools Apple makes available for working with HLS stuff.

Here's all of them: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/UsingHTTPLiveStreaming/UsingHTTPLiveStreaming.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants