intro

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: AGPL-3.0 Imports: 20 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 intro finds where a TV show's intro (its theme song or title sequence) plays in each episode, so players can offer to skip it.

Episodes of a season share their intro's audio, so the package decodes the start of each episode's soundtrack into an audio fingerprint, lines two episodes' fingerprints up at every possible offset, and takes the longest stretch they have in common as the intro in both. Chapters named Intro or Opening, when a file has them, come first (see probe).

Index

Constants

View Source
const FrameMs = float64(hop) * 1000 / sampleRate

FrameMs is how much audio each fingerprint value stands for.

View Source
const Version = 1

Version goes up when the detector changes enough that episodes it looked at should be looked at again.

Variables

View Source
var (
	MinIntro = 15 * time.Second
	MaxIntro = 200 * time.Second
)

MinIntro and MaxIntro bound what counts as an intro. A shorter shared passage is a channel ident or a sound effect; a longer one is a recap or the same file twice.

Functions

This section is empty.

Types

type Detector

type Detector struct {
	Store  *store.Store
	FFmpeg string
	Log    *slog.Logger
	// LowPriority is called with each FFmpeg's process id.
	LowPriority func(pid int)
	// contains filtered or unexported fields
}

Detector finds the intros of TV episodes, a season at a time, and stores them (see store.SetIntro).

func (*Detector) Pass

func (d *Detector) Pass(ctx context.Context, next func(first store.IntroEpisode) bool) (int, error)

Pass looks at every season with an episode the detector hasn't looked at as it is now. Before each season it calls next with the season's first episode, which returns false to stop the pass (paused, or shutting down). It returns how many episodes it looked at.

func (*Detector) Season

func (d *Detector) Season(ctx context.Context, season []store.IntroEpisode) int

Season finds the intros of one season's episodes that need looking at, comparing each with the episodes nearest it until two share an intro. It returns how many episodes it stored a result for.

type Print

type Print struct {
	Values []uint32
	Quiet  []bool
}

Print is a stretch of audio's fingerprint: one value per FrameMs, and whether each frame was too quiet to say anything. Silence looks the same in every episode, so quiet frames never count as shared.

func Fingerprint

func Fingerprint(ctx context.Context, ffmpeg, file string, limit time.Duration, lowPriority func(pid int)) (Print, error)

Fingerprint decodes up to limit of a file's first audio stream with FFmpeg and fingerprints it. lowPriority, when set, is called with the FFmpeg process id as soon as it starts.

func FingerprintFrom added in v0.1.13

func FingerprintFrom(ctx context.Context, ffmpeg, file string, start, limit time.Duration, lowPriority func(pid int)) (Print, error)

FingerprintFrom is Fingerprint of up to limit of audio from start on. The print's first frame is at start.

func FingerprintSamples

func FingerprintSamples(samples []float64) Print

FingerprintSamples fingerprints mono audio at sampleRate, samples between -1 and 1.

func (Print) Len

func (p Print) Len() int

Len is how many frames the print has.

type Segment

type Segment struct{ Start, End int }

Segment is a stretch of a print, in frames: [Start, End).

func Match

func Match(a, b Print) (inA, inB Segment, ok bool)

Match finds the longest passage two prints share, wherever it is in each, and where it is in a and in b. ok is false when they share nothing between MinIntro and MaxIntro long.

It tries every way of lining the two up. That is a couple of hundred million cheap comparisons for ten minutes of each, under a second.

func MatchWithin added in v0.1.13

func MatchWithin(a, b Print, shortest, longest time.Duration) (inA, inB Segment, ok bool)

MatchWithin is Match for passages between shortest and longest long.

func (Segment) EndMs

func (s Segment) EndMs() int64

func (Segment) Len

func (s Segment) Len() int

func (Segment) StartMs

func (s Segment) StartMs() int64

StartMs and EndMs turn a segment's frames into time.

Jump to

Keyboard shortcuts

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