Documentation
¶
Overview ¶
Package thumbs makes the pictures the players show above the seek bar while someone scrubs: a small frame every few seconds of each video, packed into JPEG sheets of Across by Down frames so a player loads a handful of images rather than hundreds.
FFmpeg reads only the video's keyframes, at the lowest CPU and disk priority. For most files it reads the file once, front to back; for files so big that would mean reading many megabytes per picture (4K remuxes on a network share), it jumps to each point instead. HDR video is tone mapped, so its pictures don't look washed out.
The sheets live in the data folder, one folder per video, and the database says how they're laid out (see store.Thumbnails).
Index ¶
- Constants
- Variables
- func Interval(durationMs int64) time.Duration
- func Key(f store.ThumbnailFile) string
- type Generator
- func (g *Generator) Clean(ctx context.Context)
- func (g *Generator) Done(f store.ThumbnailFile) bool
- func (g *Generator) Make(ctx context.Context, f store.ThumbnailFile) bool
- func (g *Generator) Mode(ctx context.Context) (Mode, error)
- func (g *Generator) OnUnreadable(report func(ctx context.Context, id int64))
- func (g *Generator) Pass(ctx context.Context, next func(f store.ThumbnailFile) bool) (int, error)
- func (g *Generator) Request(ctx context.Context, id int64) bool
- func (g *Generator) Serve(ctx context.Context)
- func (g *Generator) SetMode(ctx context.Context, m Mode) error
- func (g *Generator) SheetPath(id int64, n int) string
- type Mode
Constants ¶
const Version = 1
Version goes up when the pictures change enough that videos should get new ones.
Variables ¶
var ( Width = 240 // of one picture; the height follows the video's shape Across = 10 // pictures across one sheet Down = 10 // and down )
Sizes and timings, variables so tests can change them.
Functions ¶
func Key ¶
func Key(f store.ThumbnailFile) string
Key is what a video's pictures are stored under, see store.MediaKey.
Types ¶
type Generator ¶
type Generator struct {
Store *store.Store
FFmpeg string
Dir string
Log *slog.Logger
// LowPriority is called with each FFmpeg's process id.
LowPriority func(pid int)
// contains filtered or unexported fields
}
Generator makes the pictures and keeps track of them.
func (*Generator) Clean ¶
Clean deletes the pictures of videos that are gone, and anything left over from making pictures when the server stopped.
func (*Generator) Done ¶
func (g *Generator) Done(f store.ThumbnailFile) bool
Done says whether a video's pictures are made, as it is now, and still there: a data folder that was emptied, as on a server whose data folder isn't kept, means making them again.
func (*Generator) Make ¶
Make makes one video's pictures and stores them. It reports whether it stored anything.
func (*Generator) OnUnreadable ¶ added in v0.2.4
OnUnreadable has report hear about each video given up on because reading it keeps timing out (most likely a damaged file), to report it.
func (*Generator) Pass ¶
Pass makes the pictures of every video that needs them, in id order. Before each it calls next, which returns false to stop the pass (paused, or shutting down). It returns how many videos it made pictures of.
func (*Generator) Request ¶
Request has a video's pictures made soon, ahead of the background pass, because someone is playing it. It reports whether they're on their way.