m3u8

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2018 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// Item tags
	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`

	// Playlist tags
	HeaderTag                = `#EXTM3U`
	FooterTag                = `#EXT-X-ENDLIST`
	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`

	// ByteRange tags
	ByteRangeTag = "BYTERANGE"

	// Encryptable tags
	MethodTag            = "METHOD"
	URITag               = "URI"
	IVTag                = "IV"
	KeyFormatTag         = "KEYFORMAT"
	KeyFormatVersionsTag = "KEYFORMATVERSIONS"

	// DateRangeItem tags
	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"

	// PlaybackStart tags
	TimeOffsetTag = "TIME-OFFSET"
	PreciseTag    = "PRECISE"

	// SessionDataItem tags
	DataIDTag   = "DATA-ID"
	ValueTag    = "VALUE"
	LanguageTag = "LANGUAGE"

	// MediaItem tags
	TypeTag            = "TYPE"
	GroupIDTag         = "GROUP-ID"
	AssocLanguageTag   = "ASSOC-LANGUAGE"
	NameTag            = "NAME"
	AutoSelectTag      = "AUTOSELECT"
	DefaultTag         = "DEFAULT"
	ForcedTag          = "FORCED"
	InStreamIDTag      = "INSTREAM-ID"
	CharacteristicsTag = "CHARACTERISTICS"
	ChannelsTag        = "CHANNELS"

	/// PlaylistItem tags
	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"

	// Values
	NoneValue = "NONE"
	YesValue  = "YES"
	NoValue   = "NO"
)

Variables

View Source
var (
	AudioCodecMap = map[string]string{
		"aac-lc": "mp4a.40.2",
		"he-aac": "mp4a.40.5",
		"mp3":    "mp4a.40.34",
	}

	BaselineCodecMap = map[string]string{
		"3.0": "avc1.66.30",
		"3.1": "avc1.42001f",
	}

	MainCodecMap = map[string]string{
		"3.0": "avc1.77.30",
		"3.1": "avc1.4d001f",
		"4.0": "avc1.4d0028",
		"4.1": "avc1.4d0029",
	}

	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",
	}
)
View Source
var (
	ErrPlaylistInvalid     = errors.New("invalid playlist, must start with #EXTM3U")
	ErrPlaylistInvalidType = errors.New("invalid playlist, mixed master and media")
	ErrResolutionInvalid   = errors.New("invalid resolution")
	ErrBandwidthMissing    = errors.New("missing bandwidth")
	ErrBandwidthInvalid    = errors.New("invalid bandwidth")
	ErrSegmentItemInvalid  = errors.New("invalid segment item")
	ErrPlaylistItemInvalid = errors.New("invalid playlist item")
)

Functions

func FormatTime

func FormatTime(time time.Time) string

func ParseAttributes

func ParseAttributes(text string) map[string]string

func ParseTime

func ParseTime(value string) (time.Time, error)

func Write

func Write(pl *Playlist) (string, error)

Types

type ByteRange

type ByteRange struct {
	Length *int
	Start  *int
}

ByteRange represents sub range of a resource

func NewByteRange

func NewByteRange(text string) (*ByteRange, error)

func (*ByteRange) String

func (br *ByteRange) String() string

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)

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)

func (*DiscontinuityItem) String

func (di *DiscontinuityItem) String() string

type Encryptable

type Encryptable struct {
	Method            string
	URI               *string
	IV                *string
	KeyFormat         *string
	KeyFormatVersions *string
}

func NewEncryptable

func NewEncryptable(attributes map[string]string) *Encryptable

func (*Encryptable) String

func (e *Encryptable) String() string

type Item

type Item interface {
	String() string
}

type KeyItem

type KeyItem struct {
	Encryptable *Encryptable
}

KeyItem represents a set of EXT-X-KEY attributes

func NewKeyItem

func NewKeyItem(text string) (*KeyItem, error)

func (*KeyItem) String

func (ki *KeyItem) String() string

type MapItem

type MapItem struct {
	URI       string
	ByteRange *ByteRange
}

MapItem represents a EXT-X-MAP tag which specifies how to obtain the Media Initialization Section

func NewMapItem

func NewMapItem(text string) (*MapItem, error)

func (*MapItem) String

func (mi *MapItem) String() string

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
}

MediaItem represents a set of EXT-X-MEDIA attributes

func NewMediaItem

func NewMediaItem(text string) (*MediaItem, error)

func (*MediaItem) String

func (mi *MediaItem) String() string

type PlaybackStart

type PlaybackStart struct {
	TimeOffset float64
	Precise    *bool
}

PlaybackStart represents a #EXT-X-START tag and attributes

func NewPlaybackStart

func NewPlaybackStart(text string) (*PlaybackStart, error)

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

func NewPlaylistWithItems

func NewPlaylistWithItems(items []Item) *Playlist

func Read

func Read(reader io.Reader) (*Playlist, error)

func ReadFile

func ReadFile(path string) (*Playlist, error)

func ReadString

func ReadString(text string) (*Playlist, error)

func (*Playlist) AppendItem

func (pl *Playlist) AppendItem(item Item)

func (*Playlist) Duration

func (pl *Playlist) Duration() float64

func (*Playlist) IsLive

func (pl *Playlist) IsLive() bool

func (*Playlist) IsMaster

func (pl *Playlist) IsMaster() bool

func (*Playlist) IsValid

func (pl *Playlist) IsValid() bool

func (*Playlist) ItemSize

func (pl *Playlist) ItemSize() int

func (*Playlist) PlaylistSize

func (pl *Playlist) PlaylistSize() int

func (*Playlist) SegmentSize

func (pl *Playlist) SegmentSize() int

func (*Playlist) String

func (pl *Playlist) String() string

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
}

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)

func (*PlaylistItem) CodecsString

func (pi *PlaylistItem) CodecsString() string

func (*PlaylistItem) String

func (pi *PlaylistItem) String() string

type Resolution

type Resolution struct {
	Width  int
	Height int
}

func NewResolution

func NewResolution(text string) (*Resolution, error)

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)

func (*SegmentItem) String

func (si *SegmentItem) String() string

type SessionDataItem

type SessionDataItem struct {
	DataID   string
	Value    *string
	URI      *string
	Language *string
}

SessionDataItem represents a set of EXT-X-SESSION-DATA attributes

func NewSessionDataItem

func NewSessionDataItem(text string) (*SessionDataItem, error)

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)

func (*SessionKeyItem) String

func (ski *SessionKeyItem) String() string

type TimeItem

type TimeItem struct {
	Time time.Time
}

TimeItem represents EXT-X-PROGRAM-DATE-TIME

func NewTimeItem

func NewTimeItem(text string) (*TimeItem, error)

func (*TimeItem) String

func (ti *TimeItem) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL