stream

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package stream serves media files directly or through on-the-fly HLS transcodes.

Index

Constants

This section is empty.

Variables

View Source
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

func MimeType(path string) string

MimeType guesses a file's content type for clients deciding whether they can play it.

func ServeDirect

func ServeDirect(w http.ResponseWriter, r *http.Request, it store.Item)

ServeDirect streams the original file with range support, so seeking is instant.

Types

type Accelerator

type Accelerator interface {
	Active() *hwaccel.Accel
}

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) Close

func (t *Transcoder) Close()

Close stops every session.

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.

Jump to

Keyboard shortcuts

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