class M3U8::Playlist
- M3U8::Playlist
- Reference
- Object
Overview
Playlist represents an m3u8 playlist, it can be a master playlist or a set of media segments
Included Modules
- M3U8::Concern
Extended Modules
- M3U8::Concern
Defined in:
m3u8/playlist.crConstructors
-
.new(params : NamedTuple = NamedTuple.new)
options = { version: 7, cache: false, target: 12, sequence: 1, discontinuity_sequence: 2, type: "VOD", independent_segments: true, } Playlist.new(options)
- .new(master : Bool | Nil = nil, version : Int32 | Nil = nil, cache : Bool | Nil = nil, discontinuity_sequence : Int32 | Nil = nil, type : Nil | String = nil, target = nil, sequence = nil, iframes_only = nil, independent_segments = nil, live = nil, items = nil)
Class Method Summary
-
.codecs(options = NamedTuple.new)
options = { profile: "baseline", level: 3.0, audio_codec: "aac-lc", } Playlist.codecs(options) # => "avc1.66.30,mp4a.40.2"
-
.parse(input)
m3u8_string = "#EXTM3U....." Playlist.parse(m3u8_string) # => #<M3U8::Playlist......>
Instance Method Summary
-
#body
- #cache : Bool | Nil
- #cache=(cache : Bool | Nil)
- #discontinuity_sequence : Int32 | Nil
- #discontinuity_sequence=(discontinuity_sequence : Int32 | Nil)
-
#duration
-
#footer
-
#header
playlist = Playlist.new(version: 6, independent_segments: true) playlist.header # => "#EXTM3U\n" \ "#EXT-X-VERSION:6\n" \ "#EXT-X-INDEPENDENT-SEGMENTS\n" \ "#EXT-X-MEDIA-SEQUENCE:0\n" \ "#EXT-X-TARGETDURATION:10"
- #iframes_only : Bool
- #iframes_only=(iframes_only : Bool)
- #independent_segments : Bool
- #independent_segments=(independent_segments : Bool)
- #items : Array(Items)
- #items=(items : Array(Items))
- #live : Bool
- #live=(live : Bool)
-
#live?
playlist = Playlist.new(live: true) playlist.items << SegmentItem.new(duration: 10.991, segment: "test_01.ts") playlist.live? # => true
- #master : Bool | Nil
- #master=(master : Bool | Nil)
-
#master?
options = {master: true} playlist = Playlist.new(options) playlist.master? # => true
- #sequence : Int32
- #sequence=(sequence : Int32)
- #target : Float64
- #target=(target : Float64)
-
#to_s
- #type : String | Nil
- #type=(type : String | Nil)
-
#valid!
-
#valid?
- #version : Int32 | Nil
- #version=(version : Int32 | Nil)
Constructor Detail
options = {
version: 7,
cache: false,
target: 12,
sequence: 1,
discontinuity_sequence: 2,
type: "VOD",
independent_segments: true,
}
Playlist.new(options)
Playlist.new
Class Method Detail
options = {
profile: "baseline",
level: 3.0,
audio_codec: "aac-lc",
}
Playlist.codecs(options) # => "avc1.66.30,mp4a.40.2"
m3u8_string = "#EXTM3U....."
Playlist.parse(m3u8_string)
# => #<M3U8::Playlist......>
Instance Method Detail
playlist = Playlist.new(version: 6, independent_segments: true)
options = {duration: 10.991, segment: "test.ts"}
playlist.items << SegmentItem.new(options)
playlist.body # => "#EXTINF:10.991,\ntest.ts"
playlist = Playlist.new
playlist.items << SegmentItem.new(duration: 10.991, segment: "test_01.ts")
playlist.items << SegmentItem.new(duration: 9.891, segment: "test_02.ts")
playlist.items << SegmentItem.new(duration: 10.556, segment: "test_03.ts")
playlist.items << SegmentItem.new(duration: 8.790, segment: "test_04.ts")
playlist.duration # => 40.227999999999994
playlist.duration.round(3) # => 40.228
playlist = Playlist.new(version: 6, independent_segments: true)
playlist.header
# => "#EXTM3U\n" \
"#EXT-X-VERSION:6\n" \
"#EXT-X-INDEPENDENT-SEGMENTS\n" \
"#EXT-X-MEDIA-SEQUENCE:0\n" \
"#EXT-X-TARGETDURATION:10"
playlist = Playlist.new(live: true)
playlist.items << SegmentItem.new(duration: 10.991, segment: "test_01.ts")
playlist.live? # => true
playlist = Playlist.new
options = {program_id: "1", uri: "playlist_url", bandwidth: 6400, audio_codec: "mp3"}
playlist.items << PlaylistItem.new(options)
playlist.to_s
# => %(#EXTM3U\n) \
%(#EXT-X-STREAM-INF:PROGRAM-ID=1,CODECS="mp4a.40.34",) \
%(BANDWIDTH=6400\nplaylist_url\n)
playlist = Playlist.new
options = {program_id: 1, width: 1920, height: 1080, codecs: "avc", bandwidth: 540, uri: "test.url"}
playlist.items << PlaylistItem.new(options)
playlist.valid! # => nil
options = {duration: 10.991, segment: "test.ts"}
playlist.items << SegmentItem.new(options)
playlist.valid! # => Playlist is invalid. (M3U8::Error::PlaylistType)
playlist = Playlist.new
options = {program_id: 1, width: 1920, height: 1080, codecs: "avc", bandwidth: 540, uri: "test.url"}
playlist.items << PlaylistItem.new(options)
playlist.valid? # => true
options = {duration: 10.991, segment: "test.ts"}
playlist.items << SegmentItem.new(options)
playlist.valid? # => false