probe

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 12 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 probe reads media facts (duration, codecs, tags) with ffprobe.

Index

Constants

View Source
const MediaInfoVersion = 4

MediaInfoVersion goes up when Analyze learns something new, so files analyzed before are looked at again. 4 keeps the chapters themselves, not just how many there are.

Variables

This section is empty.

Functions

func ChannelLabel

func ChannelLabel(n int) string

ChannelLabel names a channel count: mono, stereo, 5.1, 7.1.

func Damaged added in v0.2.4

func Damaged(ctx context.Context, ffmpeg, path string, durationMs int64, lowPriority func(pid int)) bool

Damaged tells a damaged file from a share that was just slow, after a background job's read of the file timed out: it jumps to a few points in the file (a tenth, half and nine tenths of the way in, or 1, 10 and 30 minutes when the length isn't known) and reads a second at each. A file that a jump times out on is damaged, say one whose seek index points past its end or whose end was never written. ffmpeg is FFmpeg's path, and lowPriority, when set, is called with each FFmpeg's process id.

func LeadingInt

func LeadingInt(s string) int

LeadingInt reads "3/12" or "03" as 3, the way track and disc tags are written.

func LowerPriority added in v0.1.3

func LowerPriority(pid int)

LowerPriority makes a running process give way to everything else on the machine, for CPU and (where the system allows) for disk.

func ResolutionLabel

func ResolutionLabel(w, h int) string

ResolutionLabel names a picture size the way people talk about it. Width counts as much as height, so a 1920×800 widescreen film is still 1080p.

Types

type AudioStream

type AudioStream struct {
	Index         int    `json:"index"` // among the file's audio streams, as in FFmpeg's 0:a:N
	Codec         string `json:"codec"`
	Profile       string `json:"profile,omitempty"`
	Channels      int    `json:"channels"`
	ChannelLayout string `json:"channelLayout,omitempty"`
	SampleRate    int    `json:"sampleRate,omitempty"`
	BitDepth      int    `json:"bitDepth,omitempty"`
	Bitrate       int64  `json:"bitrate,omitempty"`
	Atmos         bool   `json:"atmos,omitempty"`
	DTSX          bool   `json:"dtsx,omitempty"`
	Language      string `json:"language,omitempty"`
	Title         string `json:"title,omitempty"`
	Default       bool   `json:"default,omitempty"`
	Forced        bool   `json:"forced,omitempty"`
	Commentary    bool   `json:"commentary,omitempty"`
	Descriptive   bool   `json:"descriptive,omitempty"` // audio description for the blind
}

type Chapter added in v0.1.2

type Chapter struct {
	Title   string `json:"title,omitempty"`
	StartMs int64  `json:"startMs"`
	EndMs   int64  `json:"endMs"`
}

Chapter is a marked part of a file, with its own title.

type MediaInfo

type MediaInfo struct {
	Container  string        `json:"container"`
	Size       int64         `json:"size"`
	DurationMs int64         `json:"durationMs"`
	Bitrate    int64         `json:"bitrate,omitempty"` // bits per second, all streams
	Video      []VideoStream `json:"video"`
	Audio      []AudioStream `json:"audio"`
	Subtitles  []Subtitle    `json:"subtitles"`
	Chapters   int           `json:"chapters,omitempty"`
	// ChapterList is the file's chapters in order, for marks on the seek
	// bar. The API moves it to the item's own chapters.
	ChapterList []Chapter `json:"chapterList,omitempty"`
	// CreditsMs is where the closing credits start, when a chapter says so.
	// Players offer the next episode from there.
	CreditsMs int64 `json:"creditsMs,omitempty"`
	// IntroStartMs and IntroEndMs are where the intro (opening titles,
	// theme song) is, when a chapter says so. Players offer to skip it.
	IntroStartMs int64  `json:"introStartMs,omitempty"`
	IntroEndMs   int64  `json:"introEndMs,omitempty"`
	Error        string `json:"error,omitempty"` // set when ffprobe couldn't read the file
	AnalyzedAt   int64  `json:"analyzedAt"`      // Unix seconds
}

MediaInfo is everything worth knowing about a file's streams, from a slower and more thorough look than the scanner's.

func (MediaInfo) Tags

func (mi MediaInfo) Tags() []string

Tags sums a file up as short keys that lists can filter on: resolution (4k, 1080p…), hdr plus its kind, the video codec, atmos or dts-x, the most audio channels (7.1, 5.1, stereo, mono), and lossless or hi-res for music. A file ffprobe couldn't read is tagged unreadable.

type Prober

type Prober struct {
	Path    string
	Timeout time.Duration
	// LowPriority runs ffprobe at the lowest CPU and disk priority, for work
	// in the background that nobody is waiting on.
	LowPriority bool
}

func (Prober) Analyze

func (p Prober) Analyze(ctx context.Context, file string) (MediaInfo, error)

Analyze reads a file's streams in full detail. It runs one ffprobe for the streams and, for PQ video only, a second that decodes nothing but reads the first frame's side data to tell HDR10+ from HDR10.

func (Prober) Probe

func (p Prober) Probe(ctx context.Context, file string) (Result, error)

type Result

type Result struct {
	DurationMs int64
	Container  string // first name ffprobe gives, e.g. "matroska" or "mov"
	VideoCodec string
	AudioCodec string
	Width      int
	Height     int
	HasCover   bool              // an embedded picture, like album art in a FLAC or MP3
	Tags       map[string]string // lower-cased keys: title, artist, album_artist, album, track, disc, date
	Subtitles  []Subtitle        // embedded subtitle streams, in file order
	Chapters   []Chapter         // marked chapters, such as an audiobook's, in order
}

func (Result) SubtitleList

func (r Result) SubtitleList() []Subtitle

SubtitleList is Subtitles, never nil, so it encodes as [] rather than null.

type Subtitle

type Subtitle struct {
	Index    int    `json:"index"` // among the file's subtitle streams, as in FFmpeg's 0:s:N
	Codec    string `json:"codec"`
	Language string `json:"language,omitempty"` // as tagged, usually ISO 639-2 like "eng"
	Title    string `json:"title,omitempty"`
	Default  bool   `json:"default,omitempty"`
	Forced   bool   `json:"forced,omitempty"`
	SDH      bool   `json:"sdh,omitempty"` // for the deaf and hard of hearing
}

Subtitle is an embedded subtitle stream.

type VideoStream

type VideoStream struct {
	Index          int     `json:"index"` // among the file's video streams, as in FFmpeg's 0:v:N
	Codec          string  `json:"codec"`
	Profile        string  `json:"profile,omitempty"`
	Width          int     `json:"width"`
	Height         int     `json:"height"`
	Resolution     string  `json:"resolution"` // 4K, 1080p…, see ResolutionLabel
	FrameRate      float64 `json:"frameRate,omitempty"`
	Bitrate        int64   `json:"bitrate,omitempty"`
	BitDepth       int     `json:"bitDepth,omitempty"`
	PixFmt         string  `json:"pixFmt,omitempty"`
	ColorPrimaries string  `json:"colorPrimaries,omitempty"`
	ColorTransfer  string  `json:"colorTransfer,omitempty"`
	ColorSpace     string  `json:"colorSpace,omitempty"`
	// HDR is "" for SDR, else dolby-vision, hdr10+, hdr10 or hlg. A Dolby
	// Vision file says which HDR10 or HLG layer it falls back to in HDRBase.
	HDR       string `json:"hdr,omitempty"`
	HDRBase   string `json:"hdrBase,omitempty"`
	DVProfile int    `json:"dvProfile,omitempty"`
	DVLevel   int    `json:"dvLevel,omitempty"`
	Language  string `json:"language,omitempty"`
	Title     string `json:"title,omitempty"`
	Default   bool   `json:"default,omitempty"`
}

Jump to

Keyboard shortcuts

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