class M3U8::Playlist

Overview

Playlist represents an m3u8 playlist, it can be a master playlist or a set of media segments

Included Modules

Extended Modules

Defined in:

m3u8/playlist.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.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)

[View source]
def self.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) #
Playlist.new

[View source]

Class Method Detail

def self.codecs(options = NamedTuple.new) #
options = {
  profile:     "baseline",
  level:       3.0,
  audio_codec: "aac-lc",
}
Playlist.codecs(options) # => "avc1.66.30,mp4a.40.2"

[View source]
def self.parse(input) #
m3u8_string = "#EXTM3U....."
Playlist.parse(m3u8_string)
# => #<M3U8::Playlist......>

[View source]

Instance Method Detail

def body #
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"

[View source]
def cache : Bool | Nil #

[View source]
def cache=(cache : Bool | Nil) #

[View source]
def discontinuity_sequence : Int32 | Nil #

[View source]
def discontinuity_sequence=(discontinuity_sequence : Int32 | Nil) #

[View source]
def duration #
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

[View source]
def footer #
playlist = Playlist.new(version: 6, independent_segments: true)

options = {duration: 10.991, segment: "test.ts"}
playlist.items << SegmentItem.new(options)

playlist.footer # => "#EXT-X-ENDLIST"

[View source]
def 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"

[View source]
def iframes_only : Bool #

[View source]
def iframes_only=(iframes_only : Bool) #

[View source]
def independent_segments : Bool #

[View source]
def independent_segments=(independent_segments : Bool) #

[View source]
def items : Array(Items) #

[View source]
def items=(items : Array(Items)) #

[View source]
def live : Bool #

[View source]
def live=(live : Bool) #

[View source]
def live? #
playlist = Playlist.new(live: true)
playlist.items << SegmentItem.new(duration: 10.991, segment: "test_01.ts")
playlist.live? # => true

[View source]
def master : Bool | Nil #

[View source]
def master=(master : Bool | Nil) #

[View source]
def master? #
options = {master: true}
playlist = Playlist.new(options)
playlist.master? # => true

[View source]
def sequence : Int32 #

[View source]
def sequence=(sequence : Int32) #

[View source]
def target : Float64 #

[View source]
def target=(target : Float64) #

[View source]
def to_s #
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)

[View source]
def type : String | Nil #

[View source]
def type=(type : String | Nil) #

[View source]
def valid! #
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)

[View source]
def valid? #
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

[View source]
def version : Int32 | Nil #

[View source]
def version=(version : Int32 | Nil) #

[View source]