HLS

Configuration

Config structs, YAML examples, and option helpers for HLS

YAML Configuration Example

config.yaml
extensions:
  hls:
    enabled: true
    basePath: "/hls"
    baseURL: "http://localhost:8080/hls"
    storageBackend: "default"
    storagePrefix: "hls"

    # Segments
    targetDuration: 6                # seconds per segment
    dvrWindowSize: 10                # segments in live playlist
    maxSegmentSize: 10485760         # 10 MB

    # Transcoding
    enableTranscoding: true
    ffmpegPath: "ffmpeg"
    ffprobePath: "ffprobe"
    maxConcurrentTranscodes: 4

    # Distributed
    enableDistributed: false
    nodeID: ""
    clusterID: "hls-cluster"
    redirectToLeader: true
    redirectToOwner: true
    enableFailover: true

    # Cleanup
    segmentRetention: "24h"
    cleanupInterval: "1h"
    enableAutoCleanup: true

    # Security
    requireAuth: false
    enableCORS: true
    allowedOrigins: ["*"]

    # Limits
    maxStreams: 100
    maxViewersPerStream: 10000
    maxBandwidthPerStream: 104857600  # 100 Mbps

    # Caching
    enableCaching: true
    cacheTTL: "5m"

The extension loads config from extensions.hls first, falling back to hls.

Programmatic Configuration

ext := hls.NewExtension(
    hls.WithBasePath("/live"),
    hls.WithBaseURL("https://cdn.example.com/live"),
    hls.WithStorageBackend("s3-backend"),
    hls.WithTranscoding(true),
    hls.WithFFmpegPaths("/usr/bin/ffmpeg", "/usr/bin/ffprobe"),
    hls.WithLimits(50, 5000, 50*1024*1024),
)

Config Struct Reference

Config

FieldTypeDefaultDescription
EnabledbooltrueEnable the extension
BasePathstring"/hls"HTTP base path for endpoints
BaseURLstring"http://localhost:8080/hls"Base URL for segment URLs in playlists
StorageBackendstring"default"Storage backend name
StoragePrefixstring"hls"Key prefix in storage
TargetDurationint6Target segment duration (seconds)
DVRWindowSizeint10Segments in live playlist
MaxSegmentSizeint6410485760 (10 MB)Max segment size
EnableTranscodingbooltrueEnable FFmpeg transcoding
TranscodeProfiles[]TranscodeProfileDefault profilesTranscode quality profiles
FFmpegPathstring"ffmpeg"FFmpeg binary path
FFprobePathstring"ffprobe"FFprobe binary path
MaxConcurrentTranscodesint4Max concurrent transcode jobs
EnableDistributedboolfalseEnable distributed mode
NodeIDstring""Node identifier
ClusterIDstring"hls-cluster"Cluster identifier
EnableFailoverbooltrueAuto-failover in distributed mode
SegmentRetentiontime.Duration24hSegment retention period
CleanupIntervaltime.Duration1hCleanup sweep interval
RequireAuthboolfalseRequire authentication
EnableCORSbooltrueEnable CORS
AllowedOrigins[]string["*"]CORS allowed origins
MaxStreamsint100Max concurrent streams
MaxViewersPerStreamint10000Max viewers per stream
MaxBandwidthPerStreamint64104857600 (100 Mbps)Max bandwidth per stream
EnableCachingbooltrueEnable playlist/segment caching
CacheTTLtime.Duration5mCache TTL

Option Helpers

FunctionDescription
WithBasePath(path)Set the HTTP base path
WithBaseURL(url)Set the base URL for playlists
WithStorageBackend(name)Set the storage backend name
WithStoragePrefix(prefix)Set the storage key prefix
WithTargetDuration(seconds)Set segment duration
WithDVRWindow(segments)Set DVR window size
WithTranscoding(enabled)Toggle transcoding
WithFFmpegPaths(ffmpeg, ffprobe)Set FFmpeg paths
WithDistributed(enabled, nodeID, clusterID)Configure distributed mode
WithFailover(enabled)Toggle failover
WithCleanup(retention, interval)Set cleanup schedule
WithAuth(required)Toggle authentication
WithCORS(enabled, origins...)Configure CORS
WithLimits(streams, viewers, bandwidth)Set resource limits
WithCaching(enabled, ttl)Configure caching
WithConfig(config)Provide a complete config struct

How is this guide?

On this page