probe

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 6 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 the duration of an audio or video file without decoding it. The bytes are untrusted, so every read is bounds-checked and every loop advances or has a fixed cap.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnreadable = errors.New("probe: could not read the duration")

ErrUnreadable means the duration could not be read from the file.

Functions

func Duration

func Duration(r io.ReaderAt, size int64, f Format) (float64, error)

Duration returns the length in seconds of the size bytes behind r, read as format f. The result errs high: the caller rounds it up, and the rounded value is never below the true duration. Any malformed input returns an error wrapping ErrUnreadable.

Types

type Format

type Format int

Format is a container the probe understands.

const (
	FormatUnknown Format = iota
	FormatMP3
	FormatISOBMFF
	FormatWAV
	FormatFLAC
	FormatOgg
)

The formats Sniff recognizes.

func Sniff

func Sniff(head []byte) Format

Sniff names the container from its first bytes, not from a file name. It accepts MP3 (an ID3 tag or a Layer III frame sync), ISO-BMFF (ftyp at offset 4), WAV (RIFF, RF64 or BW64 with WAVE), FLAC and Ogg, and returns FormatUnknown for anything else.

func SniffAt

func SniffAt(r io.ReaderAt, size int64) Format

SniffAt is Sniff on the start of the size bytes behind r. It reads past an ID3v2 tag to tell a tagged FLAC from an MP3, which a short head cannot. A short or failing reader gives FormatUnknown.

func (Format) String

func (f Format) String() string

String names the format for messages.

Jump to

Keyboard shortcuts

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