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 ¶
const FrameMs = float64(hop) * 1000 / sampleRate
FrameMs is how much audio each fingerprint value stands for.
const Version = 1
Version goes up when the detector changes enough that episodes it looked at should be looked at again.
Variables ¶
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).
type Print ¶
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 ¶
FingerprintSamples fingerprints mono audio at sampleRate, samples between -1 and 1.
type Segment ¶
type Segment struct{ Start, End int }
Segment is a stretch of a print, in frames: [Start, End).
func Match ¶
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
MatchWithin is Match for passages between shortest and longest long.