probe

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package probe reads what a source file actually is, using ffprobe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyframeBefore added in v0.4.0

func KeyframeBefore(
	ctx context.Context,
	ffprobePath, path string,
	at, window time.Duration,
) (keyframe time.Duration, found bool, err error)

KeyframeBefore finds the last keyframe at or before a time.

Only a window before the time is read, so a source whose keyframes are far apart has none to offer. The time is rounded up to the millisecond, because clip marks carry milliseconds, and a mark rounded down would land before the keyframe and seek to the one before it.

Parameters:

  • ctx: Cancellation and deadline for the read.
  • ffprobePath: Path to the ffprobe binary.
  • path: Media file path.
  • at: The time the keyframe may not be after.
  • window: How far before at the keyframe may be.

Returns:

  • keyframe: The keyframe's time, rounded up to the millisecond.
  • found: False when no keyframe lies in the window.
  • err: Non-nil when ffprobe cannot read the file.

func StoreCrop

func StoreCrop(path string, key Key, start, window time.Duration, rect crop.CropRect)

StoreCrop caches a crop rectangle, but only if the source file is unchanged since the analysis read its identity.

Parameters:

  • path: Cleaned source path, re-read to confirm the identity.
  • key: Cache identity of the source file.
  • start: Seek offset.
  • window: Sampling window.
  • rect: Result to store.

func StorePeak

func StorePeak(path string, key Key, start, window time.Duration, peak float64)

StorePeak caches a PQ luma peak under the same identity rules as StoreCrop.

Parameters:

  • path: Cleaned source path, re-read to confirm the identity.
  • key: Cache identity of the source file.
  • start: Seek offset.
  • window: Sampling window.
  • peak: Result to store.

Types

type DolbyVision added in v0.4.0

type DolbyVision struct {
	// Present reports that the stream carries a configuration record.
	Present bool `json:"present"`
	// Profile is the Dolby Vision profile, such as 5, 7, or 8.
	Profile int `json:"profile"`
	// BaseLayerCompatibility is the base layer's signal compatibility id:
	// 0 for none, 1 for HDR10, 2 for SDR, 4 for HLG, and 6 for UHD Blu-ray.
	BaseLayerCompatibility int `json:"base_layer_compatibility"`
}

DolbyVision is a stream's Dolby Vision configuration record.

type Info

type Info struct {
	Duration      time.Duration `json:"duration"`
	Width         int           `json:"width"`
	Height        int           `json:"height"`
	VideoCodec    string        `json:"video_codec"`
	AudioCodec    string        `json:"audio_codec"`
	Format        string        `json:"format"`
	BitRate       int64         `json:"bit_rate"`
	ColorTransfer string        `json:"color_transfer"`
	// PixelFormat is the video stream's pixel format, such as yuv420p.
	PixelFormat string  `json:"pixel_format"`
	AudioTracks []Track `json:"audio_tracks"`
	// DolbyVision is the video stream's Dolby Vision configuration, the zero
	// value when the stream carries none.
	DolbyVision DolbyVision `json:"dolby_vision"`
	// MaxCLLNits is the video stream's MaxCLL in nits, 0 when it is unknown.
	MaxCLLNits float64 `json:"max_cll_nits"`
	// MasteringMaxNits is the mastering display's peak in nits, 0 when it is
	// unknown.
	MasteringMaxNits float64 `json:"mastering_max_nits"`
}

Info represents media file information.

func Probe

func Probe(ctx context.Context, ffprobePath, path string) (Info, error)

Probe reads a media file for information.

Parameters:

  • ctx: Cancellation and deadline for the probe.
  • ffprobePath: Path to the ffprobe binary.
  • path: Media file path.

Returns:

  • info: The probed media information.
  • err: Non-nil when the file cannot be probed.

func (Info) NeedsDolbyVisionReshaping added in v0.4.0

func (info Info) NeedsDolbyVisionReshaping() bool

NeedsDolbyVisionReshaping reports whether the video is Dolby Vision with no displayable base layer, such as profile 5.

Its base layer is in Dolby's own color space and only looks right after the Dolby Vision reshaping, which ffmpeg's decoder does not apply.

Returns:

  • needs: True for profile 5, or for any base layer compatible with nothing.

func (Info) PeakNits added in v0.4.0

func (info Info) PeakNits() (float64, bool)

PeakNits reports the brightest the source's HDR10 metadata says it gets.

It takes MaxCLL when the stream carries it, otherwise the mastering display's peak.

Returns:

  • nits: The peak in nits.
  • ok: False when the stream carries neither.

type Key

type Key struct {
	// contains filtered or unexported fields
}

Key is a probed file's identity on disk.

func KeyFor

func KeyFor(path string) (Key, bool)

KeyFor builds the cache identity for a path, reporting whether the file can be identified on disk.

Parameters:

  • path: Media file path.

Returns:

  • key: The cache identity for the file.
  • ok: False when the file cannot be stat'd.

func (Key) CachedCrop

func (key Key) CachedCrop(start, window time.Duration) (crop.CropRect, bool)

CachedCrop returns a cached crop rectangle for one analysis.

Parameters:

  • start: Seek offset.
  • window: Sampling window, already clamped by the caller.

Returns:

  • rect: The cached rectangle.
  • ok: True when the file had been analyzed and still is that file.

func (Key) CachedPeak

func (key Key) CachedPeak(start, window time.Duration) (float64, bool)

CachedPeak returns a cached PQ luma peak for one analysis.

Parameters:

  • start: Seek offset.
  • window: Sampling window, already clamped by the caller.

Returns:

  • peak: The cached peak.
  • ok: True when the file had been analyzed and still is that file.

type Track

type Track struct {
	Index    int
	Codec    string
	Language string
	Title    string
	Channels int
}

Track is one audio stream on a source file.

Jump to

Keyboard shortcuts

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