HLS

Functions

Public API reference for the HLS extension

Extension Entry Points

FunctionDescription
NewExtension(opts ...ConfigOption) forge.ExtensionCreate the HLS extension with functional options
NewExtensionWithConfig(config Config) forge.ExtensionCreate the HLS extension with a complete config
DefaultConfig() ConfigReturns the default configuration

HLS Interface -- Stream Management

MethodDescription
CreateStream(ctx, options) (*Stream, error)Create a new stream (live, VOD, or event)
GetStream(ctx, streamID) (*Stream, error)Get stream information
DeleteStream(ctx, streamID) errorDelete a stream and its segments
ListStreams(ctx) ([]*Stream, error)List all streams
StartStream(ctx, streamID) errorStart a live stream
StopStream(ctx, streamID) errorStop a live stream

HLS Interface -- Segment Operations

MethodDescription
IngestSegment(ctx, streamID, variantID, data) errorPush a media segment
GetSegment(ctx, streamID, variantID, segmentNum) (io.ReadCloser, error)Retrieve a segment

HLS Interface -- Playlists

MethodDescription
GetMasterPlaylist(ctx, streamID) (string, error)Generate the master playlist (m3u8)
GetMediaPlaylist(ctx, streamID, variantID) (string, error)Generate a media playlist

HLS Interface -- Stats

MethodDescription
GetStreamStats(ctx, streamID) (*StreamStats, error)Get stream statistics

Playlist Generator

FunctionDescription
NewPlaylistGenerator(baseURL) *PlaylistGeneratorCreate a playlist generator
GenerateMasterPlaylist(stream) stringGenerate a master m3u8 playlist
GenerateMediaPlaylist(stream, variantID) stringGenerate a media m3u8 playlist

Utility Functions

FunctionDescription
DefaultProfiles() []TranscodeProfileGet default transcode profiles (360p to 4K)
FormatResolution(width, height) stringFormat a resolution string
ParseResolution(resolution) (width, height, error)Parse a resolution string
GenerateCodecsString(profile) stringGenerate HLS codecs attribute string

Key Types

StreamOptions

FieldTypePurpose
NamestringStream display name
TypeStreamTypelive, vod, or event
Profiles[]TranscodeProfileQuality profiles to generate

TranscodeProfile

FieldTypePurpose
NamestringProfile name (e.g. "720p")
WidthintOutput width
HeightintOutput height
VideoBitrateintVideo bitrate (kbps)
AudioBitrateintAudio bitrate (kbps)
VideoCodecstringVideo codec (e.g. "h264")
AudioCodecstringAudio codec (e.g. "aac")

How is this guide?

On this page