Documentation
¶
Overview ¶
Package stream serves media files directly or through on-the-fly HLS transcodes.
Index ¶
- Variables
- func MimeType(path string) string
- func ServeDirect(w http.ResponseWriter, r *http.Request, it store.Item)
- type Accelerator
- type Transcoder
- func (t *Transcoder) Active() int
- func (t *Transcoder) Close()
- func (t *Transcoder) Kill(id string)
- func (t *Transcoder) ServeFile(w http.ResponseWriter, r *http.Request, userID int64, sessionID, name string)
- func (t *Transcoder) Start(ctx context.Context, userID int64, it store.Item, startSec float64, ...) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ErrSuperseded = errors.New("replaced by a newer transcode")
ErrSuperseded means a newer Start for the same viewer and item replaced this one before it was ready, as happens while dragging the seek bar.
Functions ¶
func MimeType ¶
MimeType guesses a file's content type for clients deciding whether they can play it.
func ServeDirect ¶
ServeDirect streams the original file with range support, so seeking is instant.
Types ¶
type Accelerator ¶
Accelerator says which hardware accelerator new transcodes use (see hwaccel.Manager); nil means the CPU.
type Transcoder ¶
type Transcoder struct {
FFmpeg string
Dir string
Log *slog.Logger
// HW picks the hardware accelerator, if any; nil transcodes on the CPU.
HW Accelerator
// contains filtered or unexported fields
}
Transcoder runs one FFmpeg process per playback session and serves its HLS output.
func NewTranscoder ¶
func NewTranscoder(ffmpeg, dir string, hw Accelerator, log *slog.Logger) *Transcoder
func (*Transcoder) Active ¶
func (t *Transcoder) Active() int
Active is how many transcodes are running, so background work can wait until nobody is watching.
func (*Transcoder) Kill ¶
func (t *Transcoder) Kill(id string)
Kill stops a session and deletes its files.
func (*Transcoder) ServeFile ¶
func (t *Transcoder) ServeFile(w http.ResponseWriter, r *http.Request, userID int64, sessionID, name string)
ServeFile serves a playlist or segment, waiting briefly for segments FFmpeg hasn't written yet.
func (*Transcoder) Start ¶
func (t *Transcoder) Start(ctx context.Context, userID int64, it store.Item, startSec float64, burnSub, audio int) (string, error)
Start begins a transcode of item from startSec and returns the session id once the first segment is ready. A user watching an item has at most one session for it, so seeking far ahead replaces the old one. burnSub is an embedded subtitle stream to draw into the video, or -1 for none. audio is which of the file's audio streams to play (FFmpeg's 0:a:N), 0 for the first.
With a hardware accelerator, a transcode that fails to start on the GPU starts again with less of it on the GPU, and finally on the CPU alone.