Documentation
¶
Overview ¶
Package hls packages goav output as HTTP Live Streaming (RFC 8216): fragmented MP4 segments and a media playlist, for live or on-demand delivery.
A packager is a provider.Destination. goav muxes the streams routed to it into fragmented MP4, cut at video keyframes, and the packager splits that byte stream: the ftyp and moov become the init segment, and fragments group into media segments of about the target duration, each starting at a keyframe. After every segment it republishes the playlist; at the end it marks the playlist complete.
live := goav.Custom(hls.New("live.m3u8", hls.Dir("/srv/hls"), hls.Window(6)))
err := bundle.Run(ctx, video.To(live), audio.To(live))
With Window(n), a live playlist lists the last n segments and the packager removes older ones once players can no longer be fetching them; without it, the playlist keeps every segment, an event that becomes an on-demand playlist when the run ends.
A Ladder is an adaptive-bitrate set: each of its variants is a packager, and it writes the multivariant playlist that lists them with their bandwidth, codecs (RFC 6381, read from each init segment), and resolution.
With Parts, a playlist is low-latency HLS: the muxer cuts fragments of at most the part duration, each published as an EXT-X-PART with the next one hinted (EXT-X-PRELOAD-HINT) and wall-clock times on the segments (EXT-X-PROGRAM-DATE-TIME), delta updates for long playlists (EXT-X-SKIP past six target durations), and, in a ladder, rendition reports of where the other renditions stand. A Server holds what LL-HLS asks a server to hold: blocking playlist reloads (_HLS_msn, _HLS_part) and requests for a hinted part. Serve it over HTTPS, so players get HTTP/2.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Ladder ¶
type Ladder struct {
// contains filtered or unexported fields
}
Ladder is an adaptive-bitrate set of renditions. Each Variant is a packager with its own playlist; the ladder writes the multivariant playlist that lists them with their bandwidth, codecs, and resolution, so a player picks the rendition its connection carries and switches as that changes.
ladder := hls.NewLadder("master.m3u8", hls.Dir("/srv/hls"))
hd := goav.Custom(ladder.Variant("hd.m3u8", hls.Window(6)))
sd := goav.Custom(ladder.Variant("sd.m3u8", hls.Window(6)))
It publishes the multivariant playlist once every variant has a segment, and again when a variant's peak bandwidth rises.
func NewLadder ¶
NewLadder returns a ladder writing the multivariant playlist name to store, beside its variants' playlists.
func (*Ladder) Variant ¶
func (l *Ladder) Variant(playlist string, options ...Option) provider.Destination
Variant returns the packager of one rendition, writing its playlist and segments to the ladder's store. Route each rendition's streams to its own variant; audio routed to every variant rides in each.
type Option ¶
type Option func(*config)
Option configures a packager.
func Parts ¶
Parts makes the playlist low-latency (LL-HLS): segments are also published in parts of at most d (200ms to 1s is typical), each a CMAF chunk listed as an EXT-X-PART with the next one hinted, so a player plays within a few parts of the live edge. LL-HLS needs a server that holds blocking playlist reloads and hinted-part requests: package into an hls.Server and serve it.
func SegmentDuration ¶
SegmentDuration sets the target segment length (default 4s). A segment ends at the first fragment boundary, a video keyframe, at or past it, so segments are as long as the stream's keyframe interval allows.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server keeps packagers' files in memory and serves them over HTTP, the origin a CDN or a player reads from. It is a Store, and it holds what LL-HLS asks a server to hold: a playlist request with _HLS_msn (and _HLS_part) waits until the playlist lists that segment (or part), and a request for the part a playlist hints waits until it is published. A request waits at most three target durations, then gets 503.
srv := hls.NewServer()
live := goav.Custom(hls.New("live.m3u8", srv, hls.Parts(250*time.Millisecond), hls.Window(6)))
http.Handle("/live/", http.StripPrefix("/live/", srv))