av1

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT, 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 av1 reads the AV1 bitstream (AV1 Bitstream & Decoding Process Specification, version 1.0.0 with Errata 1) as far as a decoder that keeps its own reference state needs: the open bitstream units, the sequence header, the frame headers with the reference frame state their syntax predicts from, and the tile groups' layout. Decoding the tiles is the hardware's (Vulkan Video's).

Index

Constants

View Source
const (
	NumRefFrames      = 8
	RefsPerFrame      = 7
	TotalRefsPerFrame = 8
	PrimaryRefNone    = 7
	MaxSegments       = 8
	SegLvlMax         = 8
	MaxTileCols       = 64
	MaxTileRows       = 64
	// LastFrame is the first reference name of an inter frame, the
	// reference frame ref_frame_idx[0] names.
	LastFrame = 1
	// The reference names of the frames frame_refs_short_signaling
	// codes and the loop filter's defaults name.
	Last2Frame   = 2
	Last3Frame   = 3
	GoldenFrame  = 4
	BwdrefFrame  = 5
	Altref2Frame = 6
	AltrefFrame  = 7
	// SwitchableFilter is interpolation_filter's switchable value.
	SwitchableFilter = 4
	// TxModeOnly4x4, TxModeLargest and TxModeSelect are the TxModes.
	TxModeOnly4x4 = 0
	TxModeLargest = 1
	TxModeSelect  = 2
)

The constants of the syntax (3).

View Source
const (
	RestoreNone       = 0
	RestoreWiener     = 1
	RestoreSgrproj    = 2
	RestoreSwitchable = 3
)

The restoration types of FrameRestorationType.

View Source
const (
	Identity    = 0
	Translation = 1
	RotZoom     = 2
	Affine      = 3
)

The global motion types of GmType.

View Source
const (
	GrainLumaWidth    = 82
	GrainLumaHeight   = 73
	GrainChromaWidth  = 44
	GrainChromaHeight = 38
)

The sizes of the film grain templates (7.18.3.3): the luma one, and the chroma ones of a 4:2:0 picture.

View Source
const (
	// SelectScreenContentTools and SelectIntegerMV are
	// seq_force_screen_content_tools and seq_force_integer_mv leaving
	// the choice to each frame.
	SelectScreenContentTools = 2
	SelectIntegerMV          = 2
)

The values the syntax selects the frame header's choice with (6.4).

View Source
const (
	ColorPrimariesBT709           = 1
	ColorUnspecified              = 2
	TransferSRGB                  = 13
	MatrixIdentity                = 0
	ChromaSamplePositionUnknown   = 0
	ChromaSamplePositionVertical  = 1
	ChromaSamplePositionColocated = 2
)

The colour description values the syntax names (6.4.2).

View Source
const MaxOperatingPoints = 32

MaxOperatingPoints are the operating points a sequence header can describe.

Variables

View Source
var ErrSyntax = errors.New("av1: stream")

ErrSyntax is an AV1 stream a decoder cannot read: malformed, or using syntax outside what it reads. Errors wrap it with what was read.

Functions

func ConfigOBUs

func ConfigOBUs(av1C []byte) ([]byte, error)

ConfigOBUs is the configOBUs of av1C, an AV1CodecConfigurationRecord (AV1 Codec ISO Media File Format Binding 2.3.3, which Matroska's CodecPrivate carries too): the sequence header and metadata units a decoder starts with.

Types

type CDEF

type CDEF struct {
	DampingMinus3            uint8
	Bits                     uint8
	YPri, YSec, UVPri, UVSec [8]uint8
}

CDEF is a cdef_params(), its secondary strengths as coded: 3 stands for 4.

type ColorConfig

type ColorConfig struct {
	BitDepth                   int
	MonoChrome                 bool
	ColorDescriptionPresent    bool
	ColorPrimaries             uint8
	TransferCharacteristics    uint8
	MatrixCoefficients         uint8
	ColorRange                 bool
	SubsamplingX, SubsamplingY bool
	ChromaSamplePosition       uint8
	SeparateUVDeltaQ           bool
}

ColorConfig is a color_config().

func (*ColorConfig) NumPlanes

func (c *ColorConfig) NumPlanes() int

NumPlanes is how many planes the frames have.

type DecoderModelInfo

type DecoderModelInfo struct {
	BufferDelayLengthMinus1           uint8
	NumUnitsInDecodingTick            uint32
	BufferRemovalTimeLengthMinus1     uint8
	FramePresentationTimeLengthMinus1 uint8
}

DecoderModelInfo is a decoder_model_info(): the lengths of the fields frame headers code their times in.

type FilmGrain

type FilmGrain struct {
	ApplyGrain            bool
	GrainSeed             uint16
	UpdateGrain           bool
	ParamsRefIdx          uint8
	NumYPoints            uint8
	PointYValue           [14]uint8
	PointYScaling         [14]uint8
	ChromaScalingFromLuma bool
	NumCbPoints           uint8
	PointCbValue          [10]uint8
	PointCbScaling        [10]uint8
	NumCrPoints           uint8
	PointCrValue          [10]uint8
	PointCrScaling        [10]uint8
	ScalingMinus8         uint8
	ArCoeffLag            uint8
	ArCoeffsYPlus128      [24]uint8
	ArCoeffsCbPlus128     [25]uint8
	ArCoeffsCrPlus128     [25]uint8
	ArCoeffShiftMinus6    uint8
	GrainScaleShift       uint8
	CbMult, CbLumaMult    uint8
	CbOffset              uint16
	CrMult, CrLumaMult    uint8
	CrOffset              uint16
	OverlapFlag           bool
	ClipToRestrictedRange bool
}

FilmGrain is a film_grain_params(), loaded from the reference frame it names when it updates none.

func (*FilmGrain) Synthesize

func (g *FilmGrain) Synthesize(t *Grain, bitDepth, w, h int)

Synthesize fills t for a w x h 4:2:0 frame of bitDepth-bit samples that applies g: the generate grain process (7.18.3.3), the scaling lookup initialization (7.18.3.4) and the random offsets of the add noise synthesis process (7.18.3.5).

type FrameHeader

type FrameHeader struct {
	ShowExistingFrame bool
	FrameToShowMapIdx uint8
	FrameType         FrameType
	FrameIsIntra      bool
	ShowFrame         bool
	ShowableFrame     bool

	ErrorResilientMode       bool
	DisableCDFUpdate         bool
	AllowScreenContentTools  bool
	ForceIntegerMV           bool
	CurrentFrameID           uint32
	FrameSizeOverride        bool
	OrderHint                uint8
	PrimaryRefFrame          uint8
	BufferRemovalTimePresent bool
	RefreshFrameFlags        uint8

	FrameRefsShortSignaling bool
	// RefFrameIdx is ref_frame_idx: the slot of each reference name
	// from LastFrame on.
	RefFrameIdx [RefsPerFrame]uint8
	// ExpectedFrameID is expectedFrameId, by RefFrameIdx's index.
	ExpectedFrameID [RefsPerFrame]uint32

	FrameWidth, FrameHeight     int
	UpscaledWidth               int
	RenderWidth, RenderHeight   int
	RenderAndFrameSizeDifferent bool
	UseSuperres                 bool
	CodedDenom                  uint8
	MiCols, MiRows              int

	AllowIntrabc           bool
	AllowHighPrecisionMV   bool
	IsFilterSwitchable     bool
	InterpolationFilter    uint8
	IsMotionModeSwitchable bool
	UseRefFrameMVs         bool
	// OrderHints and RefFrameSignBias are by reference name.
	OrderHints       [TotalRefsPerFrame]uint8
	RefFrameSignBias [TotalRefsPerFrame]bool

	DisableFrameEndUpdateCDF bool

	Tile  TileInfo
	Quant Quantization
	Seg   Segmentation

	DeltaQPresent  bool
	DeltaQRes      uint8
	DeltaLFPresent bool
	DeltaLFRes     uint8
	DeltaLFMulti   bool
	CodedLossless  bool
	AllLossless    bool

	LoopFilter LoopFilter
	CDEF       CDEF
	LR         LoopRestoration

	TxMode          uint8
	ReferenceSelect bool
	SkipModePresent bool
	// SkipModeFrame are the reference names skip mode predicts from.
	SkipModeFrame     [2]uint8
	AllowWarpedMotion bool
	ReducedTxSet      bool
	GlobalMotion      GlobalMotion
	FilmGrain         FilmGrain

	// HeaderBytes is how many bytes of its OBU's payload the header
	// takes, up to the byte boundary a frame OBU's tile group starts at.
	HeaderBytes int
}

FrameHeader is a frame header (5.9), its values as its semantics (6.8) and the decoding process define them.

type FrameType

type FrameType uint8

FrameType is a frame's frame_type.

const (
	KeyFrame FrameType = iota
	InterFrame
	IntraOnlyFrame
	SwitchFrame
)

The frame types.

func (FrameType) String

func (t FrameType) String() string

type GlobalMotion

type GlobalMotion struct {
	Type   [TotalRefsPerFrame]uint8
	Params [TotalRefsPerFrame][6]int32
}

GlobalMotion is a global_motion_params(): GmType and gm_params by reference name.

type Grain

type Grain struct {
	Luma    [GrainLumaHeight * GrainLumaWidth]int32
	Cb, Cr  [GrainChromaHeight * GrainChromaWidth]int32
	Scaling [3][256]int32
	// Offsets holds, for each row of blocks and each block in it, the
	// eight random bits that place the block in the templates; Stride
	// is the blocks in a row.
	Offsets []int32
	Stride  int
}

Grain is what synthesizing a frame's film grain (7.18.3) reads beside the frame's samples: the grain templates the noise is cut from, the scaling function of each plane, and where in the templates each 32x32 block of the picture starts. It is laid out as words for a shader to read; a Grain kept between frames makes one without allocating.

type LoopFilter

type LoopFilter struct {
	Level           [4]uint8
	Sharpness       uint8
	DeltaEnabled    bool
	DeltaUpdate     bool
	UpdateRefDelta  uint8
	RefDeltas       [TotalRefsPerFrame]int8
	UpdateModeDelta uint8
	ModeDeltas      [2]int8
}

LoopFilter is a loop_filter_params(), the deltas it leaves out loaded from the primary reference frame. UpdateRefDelta and UpdateModeDelta have bit i set for each delta i coded.

type LoopRestoration

type LoopRestoration struct {
	Type         [3]uint8
	Size         [3]uint16
	UsesLr       bool
	UsesChromaLr bool
}

LoopRestoration is an lr_params(): FrameRestorationType and LoopRestorationSize in samples, by plane.

type OBU

type OBU struct {
	Type          OBUType
	Extension     bool
	TemporalID    uint8
	SpatialID     uint8
	Offset        int
	PayloadOffset int
	Payload       []byte
}

OBU is an open bitstream unit (5.3): its type, its extension's layer IDs when it has one, and its payload, a slice of the bytes it was read from; Offset and PayloadOffset are where in them the unit and its payload start.

func (*OBU) InOperatingPoint

func (u *OBU) InOperatingPoint(idc uint16) bool

InOperatingPoint reports whether u belongs to the operating point whose operating_point_idc is idc, the units a decoder of it drops otherwise (7.1, the operating point selection's drop rule).

type OBUType

type OBUType uint8

OBUType is an open bitstream unit's obu_type (6.2.2).

const (
	OBUSequenceHeader       OBUType = 1
	OBUTemporalDelimiter    OBUType = 2
	OBUFrameHeader          OBUType = 3
	OBUTileGroup            OBUType = 4
	OBUMetadata             OBUType = 5
	OBUFrame                OBUType = 6
	OBURedundantFrameHeader OBUType = 7
	OBUTileList             OBUType = 8
	OBUPadding              OBUType = 15
)

The OBU types.

type OBUs

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

OBUs walks the units of a temporal unit in the low overhead bitstream format (5.2), which every unit's size field delimits.

func NewOBUs

func NewOBUs(b []byte) OBUs

NewOBUs walks b.

func (*OBUs) Err

func (o *OBUs) Err() error

Err is why the walk stopped early, nil at the end of the units.

func (*OBUs) Next

func (o *OBUs) Next() (OBU, bool)

Next is the next unit, false at the end or at a unit that does not parse, which Err then says.

type Quantization

type Quantization struct {
	BaseQIdx                                              uint8
	DeltaQYDc, DeltaQUDc, DeltaQUAc, DeltaQVDc, DeltaQVAc int8
	DiffUVDelta                                           bool
	UsingQmatrix                                          bool
	QmY, QmU, QmV                                         uint8
}

Quantization is a quantization_params().

type RefFrame

type RefFrame struct {
	Valid                     bool
	FrameID                   uint32
	FrameType                 FrameType
	Showable                  bool
	UpscaledWidth             int
	FrameWidth, FrameHeight   int
	RenderWidth, RenderHeight int
	MiCols, MiRows            int
	OrderHint                 uint8
	SavedOrderHints           [TotalRefsPerFrame]uint8
	SavedSignBias             [TotalRefsPerFrame]bool
	GmParams                  [TotalRefsPerFrame][6]int32
	LoopFilterRefDeltas       [TotalRefsPerFrame]int8
	LoopFilterModeDeltas      [2]int8
	FeatureEnabled            [MaxSegments][SegLvlMax]bool
	FeatureData               [MaxSegments][SegLvlMax]int16
	FilmGrain                 FilmGrain
	// What a reference picture's decoding reads of the frame.
	DisableFrameEndUpdateCDF bool
	SegmentationEnabled      bool
}

RefFrame is what the reference frame update process (7.20) saves of a frame in a slot, as far as later frame headers read it.

type Segmentation

type Segmentation struct {
	Enabled, UpdateMap, TemporalUpdate, UpdateData bool
	FeatureEnabled                                 [MaxSegments][SegLvlMax]bool
	FeatureData                                    [MaxSegments][SegLvlMax]int16
}

Segmentation is a segmentation_params(), the features it leaves out loaded from the primary reference frame.

type SequenceHeader

type SequenceHeader struct {
	Profile                   uint8
	StillPicture              bool
	ReducedStillPictureHeader bool

	TimingInfoPresent bool
	Timing            TimingInfo

	DecoderModelInfoPresent bool
	DecoderModel            DecoderModelInfo

	InitialDisplayDelayPresent bool
	OperatingPoints            int
	OperatingPointIdc          [MaxOperatingPoints]uint16
	LevelIdx                   [MaxOperatingPoints]uint8
	Tier                       [MaxOperatingPoints]bool
	DecoderModelPresentForOp   [MaxOperatingPoints]bool

	FrameWidthBits, FrameHeightBits int
	MaxFrameWidth, MaxFrameHeight   int

	FrameIDNumbersPresent         bool
	DeltaFrameIDLengthMinus2      uint8
	AdditionalFrameIDLengthMinus1 uint8

	Use128x128Superblock     bool
	EnableFilterIntra        bool
	EnableIntraEdgeFilter    bool
	EnableInterintraCompound bool
	EnableMaskedCompound     bool
	EnableWarpedMotion       bool
	EnableDualFilter         bool
	EnableOrderHint          bool
	EnableJntComp            bool
	EnableRefFrameMVs        bool
	// ForceScreenContentTools and ForceIntegerMV are
	// seq_force_screen_content_tools and seq_force_integer_mv: 0, 1 or
	// the Select value.
	ForceScreenContentTools uint8
	ForceIntegerMV          uint8
	// OrderHintBits is 0 without order hints.
	OrderHintBits int

	EnableSuperres    bool
	EnableCDEF        bool
	EnableRestoration bool
	Color             ColorConfig
	FilmGrainPresent  bool
}

SequenceHeader is a sequence_header_obu (5.5), its values as its semantics (6.4) define them.

func (*SequenceHeader) IDLen

func (s *SequenceHeader) IDLen() int

IDLen is idLen, the bits of a frame ID.

func (*SequenceHeader) Parse

func (s *SequenceHeader) Parse(b []byte) error

Parse reads a sequence header OBU's payload.

type Stream

type Stream struct {
	Seq SequenceHeader
	Ref [NumRefFrames]RefFrame
	// contains filtered or unexported fields
}

Stream is the state a stream's frame headers are read with: its sequence header and the eight reference frame slots.

func (*Stream) ParseFrameHeader

func (s *Stream) ParseFrameHeader(h *FrameHeader, u *OBU) error

ParseFrameHeader reads the frame header u, a frame header or frame OBU, into h with the stream's state, which it moves on as the header's decoding process does; Update takes the frame into the reference slots once it is decoded.

func (*Stream) Peek

func (s *Stream) Peek(b []byte) (showExisting bool, t FrameType)

Peek is what the frame header OBU payload b starts with: whether it shows an existing frame, and the type of the frame it codes when not. It reads no state but the sequence header, so it tells which frame a decoder starting at a random access point can begin with.

func (*Stream) Reset

func (s *Stream) Reset()

Reset forgets the reference frames: what decoding from a random access point does.

func (*Stream) Update

func (s *Stream) Update(h *FrameHeader)

Update takes h, decoded or shown, into the slots its refresh_frame_flags name: the reference frame update process (7.20).

type Tile

type Tile struct {
	Offset, Size int
}

Tile is a tile's coded data within the tile group it was read from: its offset and size in bytes.

func ParseTileGroup

func ParseTileGroup(h *FrameHeader, b []byte, tiles []Tile) (out []Tile, last bool, err error)

ParseTileGroup reads b, a tile group OBU's payload or a frame OBU's after its header, of the frame h heads, appending its tiles to tiles. last is set once the group holds the frame's last tile.

type TileInfo

type TileInfo struct {
	UniformSpacing      bool
	Cols, Rows          int
	ColsLog2, RowsLog2  int
	MiColStarts         [MaxTileCols + 1]uint16
	MiRowStarts         [MaxTileRows + 1]uint16
	WidthInSbsMinus1    [MaxTileCols]uint16
	HeightInSbsMinus1   [MaxTileRows]uint16
	ContextUpdateTileID uint16
	// TileSizeBytes is TileSizeBytes, 4 where the header codes none.
	TileSizeBytes int
}

TileInfo is a tile_info().

type TimingInfo

type TimingInfo struct {
	NumUnitsInDisplayTick    uint32
	TimeScale                uint32
	EqualPictureInterval     bool
	NumTicksPerPictureMinus1 uint32
}

TimingInfo is a timing_info().

Jump to

Keyboard shortcuts

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