media

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package media holds the domain types shared by every analysis stage.

Index

Constants

View Source
const (
	// TransferPQ is the perceptual quantizer of SMPTE ST 2084: absolute
	// display light, up to 10 000 cd/m².
	TransferPQ = "smpte2084"
	// TransferHLG is hybrid log-gamma (ARIB STD-B67): relative scene light,
	// displayed at the peak luminance of the display.
	TransferHLG = "arib-std-b67"
)

Transfer characteristics of the HDR signals of ITU-R BT.2100, as ffmpeg names them (Color.Transfer).

View Source
const HLGNominalPeak = 1000

HLGNominalPeak is the display peak luminance (cd/m²) HLG light levels and colour differences are computed for: the reference display of ITU-R BT.2100 and BT.2124 (conversion 4).

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioStream

type AudioStream struct {
	Index         int    `json:"index"`
	Codec         string `json:"codec"`
	Profile       string `json:"profile,omitempty"`
	SampleRate    int    `json:"sampleRate"`
	Channels      int    `json:"channels"`
	ChannelLayout string `json:"channelLayout,omitempty"`
	BitRate       int64  `json:"bitRate,omitempty"`
	Language      string `json:"language,omitempty"`
	// SampleFormat is the decoder's sample format (fltp, s16, s32p...).
	SampleFormat string `json:"sampleFormat,omitempty"`
	// BitDepth is the coded sample depth of PCM and lossless streams (0
	// for lossy codecs, which have none).
	BitDepth int `json:"bitDepth,omitempty"`
	// StartTime is the stream's start on the container's timeline.
	StartTime Duration `json:"startTime,omitempty"`
	// Duration is the stream's duration, when the container tells.
	Duration Duration `json:"duration,omitempty"`
	// Default is true for the track players pick by default.
	Default bool `json:"default,omitempty"`
}

AudioStream describes an audio elementary stream.

type Chromaticity

type Chromaticity struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

Chromaticity is a CIE 1931 xy colour coordinate.

type Color

type Color struct {
	Range     string `json:"range,omitempty"`
	Space     string `json:"space,omitempty"`
	Transfer  string `json:"transfer,omitempty"`
	Primaries string `json:"primaries,omitempty"`
}

Color holds the signalled colour description of a stream.

func (Color) FullRange

func (c Color) FullRange() bool

FullRange reports whether samples use the full quantisation range ("pc"); limited ("tv") is the default for Y′CbCr video.

func (Color) IsHDR

func (c Color) IsHDR() bool

IsHDR reports whether the transfer characteristic is PQ or HLG.

type ContentLightLevel

type ContentLightLevel struct {
	MaxCLL  int `json:"maxCLL"`
	MaxFALL int `json:"maxFALL"`
}

ContentLightLevel holds MaxCLL / MaxFALL in cd/m².

type DolbyVision

type DolbyVision struct {
	Profile         int  `json:"profile"`
	Level           int  `json:"level"`
	RPUPresent      bool `json:"rpuPresent"`
	ELPresent       bool `json:"elPresent"`
	BLPresent       bool `json:"blPresent"`
	CompatibilityID int  `json:"compatibilityId"`
}

DolbyVision holds the Dolby Vision decoder configuration record.

type Duration

type Duration time.Duration

Duration is a time.Duration serialised in JSON as decimal seconds, which is what charting tools and non-Go consumers expect.

func Seconds

func Seconds(
	s float64,
) Duration

Seconds builds a Duration from a number of seconds.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler, rounded to the microsecond.

func (Duration) Seconds

func (d Duration) Seconds() float64

Seconds returns the duration in seconds.

func (Duration) Std

func (d Duration) Std() time.Duration

Std returns the standard library duration.

func (Duration) String

func (d Duration) String() string

String implements fmt.Stringer.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(
	data []byte,
) error

UnmarshalJSON implements json.Unmarshaler.

type DynamicRange

type DynamicRange string

DynamicRange classifies how a stream is meant to be displayed.

const (
	DynamicRangeSDR         DynamicRange = "SDR"
	DynamicRangeHDR10       DynamicRange = "HDR10"
	DynamicRangeHLG         DynamicRange = "HLG"
	DynamicRangePQ          DynamicRange = "PQ"
	DynamicRangeDolbyVision DynamicRange = "DolbyVision"
	// DynamicRangeHDR10Plus is HDR10 with SMPTE ST 2094-40 dynamic
	// metadata, found in the frames (not at stream level).
	DynamicRangeHDR10Plus DynamicRange = "HDR10+"
)

Dynamic range values.

type HDR

type HDR struct {
	DynamicRange      DynamicRange       `json:"dynamicRange"`
	MasteringDisplay  *MasteringDisplay  `json:"masteringDisplay,omitempty"`
	ContentLightLevel *ContentLightLevel `json:"contentLightLevel,omitempty"`
	DolbyVision       *DolbyVision       `json:"dolbyVision,omitempty"`
	// HDR10Plus is set when the first frame carries SMPTE ST 2094-40
	// dynamic metadata (HDR10+).
	HDR10Plus bool `json:"hdr10Plus,omitempty"`
}

HDR describes high dynamic range signalling found at stream level.

type Info

type Info struct {
	Path      string        `json:"path"`
	Format    string        `json:"format"`
	Duration  Duration      `json:"duration"`
	Size      int64         `json:"size"`
	BitRate   int64         `json:"bitRate"`
	Video     []VideoStream `json:"video"`
	Audio     []AudioStream `json:"audio"`
	StartTime Duration      `json:"startTime"`
}

Info describes a media file at container and stream level.

func (*Info) DefaultAudio

func (i *Info) DefaultAudio() int

DefaultAudio returns the index in Audio of the default track: the first flagged default, else the first track; -1 without audio.

func (*Info) PrimaryVideo

func (i *Info) PrimaryVideo() (VideoStream, bool)

PrimaryVideo returns the first video stream, if any.

type Interval

type Interval struct {
	Start Duration `json:"start"`
	End   Duration `json:"end"`
}

Interval is a time range [Start, End).

func (Interval) Length

func (i Interval) Length() Duration

Length returns End - Start.

type Levels

type Levels struct {
	Black int `json:"black"`
	White int `json:"white"`
}

Levels are the nominal black and white luma code values of an 8-bit signal.

func LevelsFor

func LevelsFor(
	colorRange string,
) Levels

LevelsFor returns the nominal levels for an ffmpeg color_range value. Unknown ranges default to limited ("tv"), the norm for YUV video.

type MasteringDisplay

type MasteringDisplay struct {
	MinLuminance float64      `json:"minLuminance"`
	MaxLuminance float64      `json:"maxLuminance"`
	Red          Chromaticity `json:"red,omitzero"`
	Green        Chromaticity `json:"green,omitzero"`
	Blue         Chromaticity `json:"blue,omitzero"`
	WhitePoint   Chromaticity `json:"whitePoint,omitzero"`
}

MasteringDisplay is the SMPTE ST 2086 mastering display colour volume: luminances in cd/m², primaries and white point as CIE 1931 xy.

type Packet

type Packet struct {
	PTS      time.Duration
	DTS      time.Duration
	Duration time.Duration
	Size     int
	Keyframe bool
}

Packet is a compressed access unit as stored in the container.

type Rational

type Rational struct {
	Num int64 `json:"num"`
	Den int64 `json:"den"`
}

Rational is an exact fraction such as a frame rate (30000/1001).

func ParseRational

func ParseRational(
	s string,
) (Rational, error)

ParseRational parses "num/den" or a plain integer. An empty or zero-denominator input returns the zero Rational.

func (Rational) Float

func (r Rational) Float() float64

Float returns the rational as a float64, or 0 when undefined.

func (Rational) String

func (r Rational) String() string

String implements fmt.Stringer.

type VideoStream

type VideoStream struct {
	Index        int      `json:"index"`
	Codec        string   `json:"codec"`
	Profile      string   `json:"profile,omitempty"`
	Level        int      `json:"level,omitempty"`
	Width        int      `json:"width"`
	Height       int      `json:"height"`
	PixelFormat  string   `json:"pixelFormat"`
	BitDepth     int      `json:"bitDepth"`
	FrameRate    Rational `json:"frameRate"`
	AvgFrameRate Rational `json:"avgFrameRate"`
	FrameCount   int64    `json:"frameCount,omitempty"`
	BitRate      int64    `json:"bitRate,omitempty"`
	Duration     Duration `json:"duration"`
	FieldOrder   string   `json:"fieldOrder,omitempty"`
	SampleAspect string   `json:"sampleAspectRatio,omitempty"`
	// StartTime is the stream's start on the container's timeline.
	StartTime Duration `json:"startTime,omitempty"`
	Color     Color    `json:"color"`
	HDR       HDR      `json:"hdr"`
}

VideoStream describes a video elementary stream.

func (VideoStream) MeasurableHDR

func (v VideoStream) MeasurableHDR() bool

MeasurableHDR reports whether the decoded frames of the stream are a BT.2100 PQ or HLG Y′CbCr signal that light levels and HDR metrics can be computed on. A Dolby Vision stream without a compatible base layer (profile 5, compatibility id 0) codes IPTPQc2, which only its RPU turns into a picture: it is reported, not measured.

Jump to

Keyboard shortcuts

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