Documentation ¶
Overview ¶
Package m3u8 provides utilities for parsing and generating m3u8 playlists
Index ¶
- Constants
- Variables
- func FormatTime(time time.Time) string
- func ParseAttributes(text string) map[string]string
- func ParseTime(value string) (time.Time, error)
- func Write(pl *Playlist) (string, error)
- type ByteRange
- type DateRangeItem
- type DiscontinuityItem
- type Encryptable
- type Item
- type KeyItem
- type MapItem
- type MediaItem
- type PlaybackStart
- type Playlist
- func (pl *Playlist) AppendItem(item Item)
- func (pl *Playlist) Duration() float64
- func (pl *Playlist) IsLive() bool
- func (pl *Playlist) IsMaster() bool
- func (pl *Playlist) IsValid() bool
- func (pl *Playlist) ItemSize() int
- func (pl *Playlist) PlaylistSize() int
- func (pl *Playlist) Playlists() []*PlaylistItem
- func (pl *Playlist) SegmentSize() int
- func (pl *Playlist) Segments() []*SegmentItem
- func (pl *Playlist) String() string
- type PlaylistItem
- type Resolution
- type SegmentItem
- type SessionDataItem
- type SessionKeyItem
- type TimeItem
Constants ¶
const ( SessionKeyItemTag = `#EXT-X-SESSION-KEY` KeyItemTag = `#EXT-X-KEY` DiscontinuityItemTag = `#EXT-X-DISCONTINUITY` TimeItemTag = `#EXT-X-PROGRAM-DATE-TIME` DateRangeItemTag = `#EXT-X-DATERANGE` MapItemTag = `#EXT-X-MAP` SessionDataItemTag = `#EXT-X-SESSION-DATA` SegmentItemTag = `#EXTINF` ByteRangeItemTag = `#EXT-X-BYTERANGE` PlaybackStartTag = `#EXT-X-START` MediaItemTag = `#EXT-X-MEDIA` PlaylistItemTag = `#EXT-X-STREAM-INF` PlaylistIframeTag = `#EXT-X-I-FRAME-STREAM-INF` HeaderTag = `#EXTM3U` TargetDurationTag = `#EXT-X-TARGETDURATION` CacheTag = `#EXT-X-ALLOW-CACHE` DiscontinuitySequenceTag = `#EXT-X-DISCONTINUITY-SEQUENCE` IndependentSegmentsTag = `#EXT-X-INDEPENDENT-SEGMENTS` PlaylistTypeTag = `#EXT-X-PLAYLIST-TYPE` IFramesOnlyTag = `#EXT-X-I-FRAMES-ONLY` MediaSequenceTag = `#EXT-X-MEDIA-SEQUENCE` VersionTag = `#EXT-X-VERSION` ByteRangeTag = "BYTERANGE" MethodTag = "METHOD" URITag = "URI" IVTag = "IV" KeyFormatTag = "KEYFORMAT" KeyFormatVersionsTag = "KEYFORMATVERSIONS" IDTag = "ID" ClassTag = "CLASS" StartDateTag = "START-DATE" EndDateTag = "END-DATE" DurationTag = "DURATION" PlannedDurationTag = "PLANNED-DURATION" Scte35CmdTag = "SCTE35-CMD" Scte35OutTag = "SCTE35-OUT" Scte35InTag = "SCTE35-IN" EndOnNextTag = "END-ON-NEXT" TimeOffsetTag = "TIME-OFFSET" PreciseTag = "PRECISE" DataIDTag = "DATA-ID" ValueTag = "VALUE" LanguageTag = "LANGUAGE" TypeTag = "TYPE" GroupIDTag = "GROUP-ID" AssocLanguageTag = "ASSOC-LANGUAGE" NameTag = "NAME" AutoSelectTag = "AUTOSELECT" DefaultTag = "DEFAULT" ForcedTag = "FORCED" InStreamIDTag = "INSTREAM-ID" CharacteristicsTag = "CHARACTERISTICS" ChannelsTag = "CHANNELS" StableRenditionIDTag = "STABLE-RENDITION-ID" ResolutionTag = "RESOLUTION" ProgramIDTag = "PROGRAM-ID" CodecsTag = "CODECS" BandwidthTag = "BANDWIDTH" AverageBandwidthTag = "AVERAGE-BANDWIDTH" FrameRateTag = "FRAME-RATE" VideoTag = "VIDEO" AudioTag = "AUDIO" SubtitlesTag = "SUBTITLES" ClosedCaptionsTag = "CLOSED-CAPTIONS" HDCPLevelTag = "HDCP-LEVEL" StableVariantIDTag = "STABLE-VARIANT-ID" NoneValue = "NONE" YesValue = "YES" NoValue = "NO" )
Variables ¶
var ( // AudioCodecMap maps audio codec to representation AudioCodecMap = map[string]string{ "aac-lc": "mp4a.40.2", "he-aac": "mp4a.40.5", "mp3": "mp4a.40.34", } // BaselineCodecMap maps baseline profile with levels to representation BaselineCodecMap = map[string]string{ "3.0": "avc1.66.30", "3.1": "avc1.42001f", } // MainCodecMap maps main profile with levels to representation MainCodecMap = map[string]string{ "3.0": "avc1.77.30", "3.1": "avc1.4d001f", "4.0": "avc1.4d0028", "4.1": "avc1.4d0029", } // HighCodecMap maps high profile with levels to representation HighCodecMap = map[string]string{ "3.0": "avc1.64001e", "3.1": "avc1.64001f", "3.2": "avc1.640020", "4.0": "avc1.640028", "4.1": "avc1.640029", "4.2": "avc1.64002a", "5.0": "avc1.640032", "5.1": "avc1.640033", "5.2": "avc1.640034", } )
var ( // ErrPlaylistInvalid represents playlist error when playlist does not start with #EXTM3U ErrPlaylistInvalid = errors.New("invalid playlist, must start with #EXTM3U") // ErrPlaylistInvalidType represents playlist error when it's mixed between master and media playlist ErrPlaylistInvalidType = errors.New("invalid playlist, mixed master and media") // ErrResolutionInvalid represents error when a resolution is invalid ErrResolutionInvalid = errors.New("invalid resolution") // ErrBandwidthMissing represents error when a segment does not have bandwidth ErrBandwidthMissing = errors.New("missing bandwidth") // ErrBandwidthInvalid represents error when a bandwidth is invalid ErrBandwidthInvalid = errors.New("invalid bandwidth") // ErrSegmentItemInvalid represents error when a segment item is invalid ErrSegmentItemInvalid = errors.New("invalid segment item") // ErrPlaylistItemInvalid represents error when a playlist item is invalid ErrPlaylistItemInvalid = errors.New("invalid playlist item") )
Functions ¶
func FormatTime ¶
FormatTime returns a string in default m3u8 date time format
func ParseAttributes ¶
ParseAttributes parses a text line in playlist and returns an attributes map
Types ¶
type ByteRange ¶
ByteRange represents sub range of a resource
func NewByteRange ¶
NewByteRange parses a text line in playlist file and returns a *ByteRange
type DateRangeItem ¶
type DateRangeItem struct { ID string Class *string StartDate string EndDate *string Duration *float64 PlannedDuration *float64 Scte35Cmd *string Scte35Out *string Scte35In *string EndOnNext bool ClientAttributes map[string]string }
DateRangeItem represents a #EXT-X-DATERANGE tag
func NewDateRangeItem ¶
func NewDateRangeItem(text string) (*DateRangeItem, error)
NewDateRangeItem parses a text line in playlist and returns a *DateRangeItem
func (*DateRangeItem) String ¶
func (dri *DateRangeItem) String() string
type DiscontinuityItem ¶
type DiscontinuityItem struct{}
DiscontinuityItem represents a EXT-X-DISCONTINUITY tag to indicate a discontinuity between the SegmentItems that proceed and follow it.
func NewDiscontinuityItem ¶
func NewDiscontinuityItem() (*DiscontinuityItem, error)
NewDiscontinuityItem returns a *DiscontinuityItem
func (*DiscontinuityItem) String ¶
func (di *DiscontinuityItem) String() string
type Encryptable ¶
type Encryptable struct { Method string URI *string IV *string KeyFormat *string KeyFormatVersions *string }
Encryptable is common representation for KeyItem and SessionKeyItem
func NewEncryptable ¶
func NewEncryptable(attributes map[string]string) *Encryptable
NewEncryptable takes an attributes map and returns an *Encryptable
func (*Encryptable) String ¶
func (e *Encryptable) String() string
type KeyItem ¶
type KeyItem struct {
Encryptable *Encryptable
}
KeyItem represents a set of EXT-X-KEY attributes
func NewKeyItem ¶
NewKeyItem parses a text line and returns a *KeyItem
type MapItem ¶
MapItem represents a EXT-X-MAP tag which specifies how to obtain the Media Initialization Section
func NewMapItem ¶
NewMapItem parses a text line and returns a *MapItem
type MediaItem ¶
type MediaItem struct { Type string GroupID string Name string Language *string AssocLanguage *string AutoSelect *bool Default *bool Forced *bool URI *string InStreamID *string Characteristics *string Channels *string StableRenditionId *string }
MediaItem represents a set of EXT-X-MEDIA attributes
func NewMediaItem ¶
NewMediaItem parses a text line and returns a *MediaItem
type PlaybackStart ¶
PlaybackStart represents a #EXT-X-START tag and attributes
func NewPlaybackStart ¶
func NewPlaybackStart(text string) (*PlaybackStart, error)
NewPlaybackStart parses a text line and returns a *PlaybackStart
func (*PlaybackStart) String ¶
func (ps *PlaybackStart) String() string
type Playlist ¶
type Playlist struct { Items []Item Version *int Cache *bool Target int Sequence int DiscontinuitySequence *int Type *string IFramesOnly bool IndependentSegments bool Live bool Master *bool }
Playlist represents an m3u8 playlist, it can be a master playlist or a set of media segments
func NewPlaylist ¶
func NewPlaylist() *Playlist
NewPlaylist returns a playlist with default target 10
func NewPlaylistWithItems ¶
NewPlaylistWithItems returns a playlist with a list of items
func ReadString ¶
ReadString parses a text string and returns a playlist
func (*Playlist) AppendItem ¶
AppendItem appends an item to the playlist
func (*Playlist) PlaylistSize ¶
PlaylistSize returns number of playlist items in a playlist
func (*Playlist) Playlists ¶ added in v0.1.2
func (pl *Playlist) Playlists() []*PlaylistItem
Playlists returns list of segment items in a playlist
func (*Playlist) SegmentSize ¶
SegmentSize returns number of segment items in a playlist
func (*Playlist) Segments ¶ added in v0.1.2
func (pl *Playlist) Segments() []*SegmentItem
Segments returns list of segment items in a playlist
type PlaylistItem ¶
type PlaylistItem struct { Bandwidth int URI string IFrame bool Name *string Width *int Height *int AverageBandwidth *int ProgramID *string Codecs *string AudioCodec *string Profile *string Level *string Video *string Audio *string Subtitles *string ClosedCaptions *string FrameRate *float64 HDCPLevel *string Resolution *Resolution StableVariantID *string }
PlaylistItem represents a set of EXT-X-STREAM-INF or EXT-X-I-FRAME-STREAM-INF attributes
func NewPlaylistItem ¶
func NewPlaylistItem(text string) (*PlaylistItem, error)
NewPlaylistItem parses a text line and returns a *PlaylistItem
func (*PlaylistItem) CodecsString ¶
func (pi *PlaylistItem) CodecsString() string
CodecsString returns the string representation of codecs for a playlist item
func (*PlaylistItem) String ¶
func (pi *PlaylistItem) String() string
type Resolution ¶
Resolution represents a resolution for a playlist item, e.g: 1920x1080
func NewResolution ¶
func NewResolution(text string) (*Resolution, error)
NewResolution parses a string and returns a *Resolution
func (*Resolution) String ¶
func (r *Resolution) String() string
type SegmentItem ¶
type SegmentItem struct { Duration float64 Segment string Comment *string ProgramDateTime *TimeItem ByteRange *ByteRange }
SegmentItem represents EXTINF attributes with the URI that follows, optionally allowing an EXT-X-BYTERANGE tag to be set.
func NewSegmentItem ¶
func NewSegmentItem(text string) (*SegmentItem, error)
NewSegmentItem parses a text line and returns a *SegmentItem
func (*SegmentItem) String ¶
func (si *SegmentItem) String() string
type SessionDataItem ¶
SessionDataItem represents a set of EXT-X-SESSION-DATA attributes
func NewSessionDataItem ¶
func NewSessionDataItem(text string) (*SessionDataItem, error)
NewSessionDataItem parses a text line and returns a *SessionDataItem
func (*SessionDataItem) String ¶
func (sdi *SessionDataItem) String() string
type SessionKeyItem ¶
type SessionKeyItem struct {
Encryptable *Encryptable
}
SessionKeyItem represents a set of EXT-X-SESSION-KEY attributes
func NewSessionKeyItem ¶
func NewSessionKeyItem(text string) (*SessionKeyItem, error)
NewSessionKeyItem parses a text line and returns a *SessionKeyItem
func (*SessionKeyItem) String ¶
func (ski *SessionKeyItem) String() string