nal

package
v0.5.1 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: 5 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 nal writes and reads H.264 and H.265 NAL units: the bit writer and reader with the Exp-Golomb codes the syntax uses, the escaping of start-code-like byte runs and its removal, the parameter sets an encoder that does not write its own (VA-API's, given packed headers) puts in the stream, and the parsing of the parameter sets and slice headers a decoder that manages its own reference pictures (Vulkan Video's) needs.

Index

Constants

View Source
const (
	H264NALSlice = 1
	H264NALIDR   = 5
	H264NALSPS   = 7
	H264NALPPS   = 8
	H264NALAUD   = 9
)

The H.264 NAL unit types a decoder acts on (Table 7-1).

View Source
const (
	H264SliceP  = 0
	H264SliceB  = 1
	H264SliceI  = 2
	H264SliceSP = 3
	H264SliceSI = 4
)

The H.264 slice types, slice_type modulo 5 (Table 7-6).

View Source
const (
	HEVCNALRADLN   = 6
	HEVCNALRASLN   = 8
	HEVCNALRASLR   = 9
	HEVCNALBLAWLP  = 16
	HEVCNALIDRWRAD = 19
	HEVCNALIDRNLP  = 20
	HEVCNALCRA     = 21
	HEVCNALIRAPMax = 23
	HEVCNALVPS     = 32
	HEVCNALSPS     = 33
	HEVCNALPPS     = 34
	HEVCNALAUD     = 35
)

The H.265 NAL unit types a decoder acts on (Table 7-1).

View Source
const (
	HEVCSliceB = 0
	HEVCSliceP = 1
	HEVCSliceI = 2
)

The H.265 slice types (Table 7-7).

View Source
const H264MaxMMCO = 66

H264MaxMMCO bounds the memory management control operations a slice header carries: one per reference frame and field, and two more.

View Source
const H264MaxRefIdx = 32

H264MaxRefIdx bounds the entries of a slice's reference picture list: num_ref_idx_active_minus1 is at most 31.

View Source
const HEVCMaxSubLayers = 7

HEVCMaxSubLayers is the sub-layers a stream may have.

Variables

View Source
var ErrH264 = errors.New("nal: H.264")

ErrH264 is an H.264 header a decoder cannot read: malformed, or using syntax outside what it decodes, which wraps ErrUnsupported too. Errors wrap it with what was read.

View Source
var ErrHEVC = errors.New("nal: H.265")

ErrHEVC is an H.265 header a decoder cannot read: malformed, or using syntax outside what it decodes, which wraps ErrUnsupported too. Errors wrap it with what was read.

View Source
var ErrUnsupported = errors.New("coding tools that are not decoded")

ErrUnsupported marks a header that is well formed and uses coding tools the parser does not read, beside the ErrH264 or ErrHEVC it wraps: an unsupported stream, where those alone are a malformed one.

Functions

func AnnexB

func AnnexB(units ...[]byte) []byte

AnnexB joins NAL units, each behind a four-byte start code.

func AppendAnnexB

func AppendAnnexB(dst []byte, units ...[]byte) []byte

AppendAnnexB appends AnnexB to dst.

func H264HighProfile

func H264HighProfile(idc uint8) bool

H264HighProfile reports whether an SPS of profile_idc carries the chroma format, bit depth and scaling matrix syntax.

func H264RefIdc

func H264RefIdc(unit []byte) uint8

H264RefIdc is an H.264 NAL unit's nal_ref_idc.

func H264SkipSlice

func H264SkipSlice(s *H264SPS, pps *H264PPS, frameNum, pocLsb uint32) []byte

H264SkipSlice is the NAL unit of one P slice covering a frame of s in which every macroblock is skipped, with the deblocking filter off: decoded, it copies the first picture of its reference list. In a sequence of fields it is a frame picture (field_pic_flag 0), and in one of macroblock-adaptive frames every skipped pair is a frame pair, as its neighbours are. A decoder makes one for each frame a gap in frame_num leaves non-existing (8.2.5.2), so the frame has a picture as a decoder that conceals the gap with the frame before has. pps is an H264SkipPPS of s; frameNum and pocLsb are the slice's frame_num and, for pic_order_cnt_type 0, its pic_order_cnt_lsb.

func H264Type

func H264Type(unit []byte) uint8

H264Type is an H.264 NAL unit's nal_unit_type.

func HEVCTemporalID

func HEVCTemporalID(unit []byte) uint8

HEVCTemporalID is an H.265 NAL unit's TemporalId; unit is at least its two header bytes.

func HEVCType

func HEVCType(unit []byte) uint8

HEVCType is an H.265 NAL unit's nal_unit_type.

func Unescape

func Unescape(dst, nal []byte) []byte

Unescape appends nal to dst with its emulation prevention bytes, the 3 after each pair of zero bytes, removed: the RBSP Reader reads.

Types

type H264

type H264 struct {
	// ProfileIdc is 77 (Main) or 100 (High).
	ProfileIdc uint8
	// LevelIdc is the level times ten.
	LevelIdc uint8
	// WidthMbs and HeightMbs are the coded size in macroblocks.
	WidthMbs, HeightMbs int
	// CropRight and CropBottom crop the coded size back to the
	// frame's, in pairs of pixels.
	CropRight, CropBottom int
	// Log2MaxFrameNum is log2 of MaxFrameNum.
	Log2MaxFrameNum int
	// MaxNumRefFrames is how many reference frames the stream keeps.
	MaxNumRefFrames int
	// CABAC is entropy_coding_mode_flag.
	CABAC bool
	// Transform8x8 is transform_8x8_mode_flag (High only).
	Transform8x8 bool
	// InitQP is the picture's initial quantiser, 26 + pic_init_qp_minus26.
	InitQP int
}

H264 is what an H.264 stream's sequence and picture parameter sets say, for the streams the encoder writes: frames only, 4:2:0 at 8 bits, picture order count type 2 (output order is decode order), no reordering, BT.709 limited range.

func (*H264) AppendSliceHeader

func (h *H264) AppendSliceHeader(dst []byte, w *Writer, sinceIDR int, idrPicID uint16, qp int) (out []byte, bits int)

AppendSliceHeader appends to dst the slice header (7.3.3) of the picture sinceIDR frames into its key interval, the idrPicID-th IDR when sinceIDR is 0, at quantiser qp: one I slice for the IDR, one P slice predicting from the picture before otherwise, the reference list and marking as the parameter sets imply. It is a packed unit (Writer.AppendPacked), stopping where the slice data starts, written through w, which it resets: with a w kept between frames and room in dst it allocates nothing.

func (*H264) PPS

func (h *H264) PPS() []byte

PPS is the picture parameter set NAL unit (7.3.2.2).

func (*H264) SPS

func (h *H264) SPS() []byte

SPS is the sequence parameter set NAL unit (7.3.2.1.1).

type H264ListModification

type H264ListModification struct {
	Idc uint8
	Arg uint32
}

H264ListModification is one modification_of_pic_nums_idc and its argument (7.3.3.1): abs_diff_pic_num_minus1 for 0 and 1, long_term_pic_num for 2.

type H264ListModifications

type H264ListModifications struct {
	N   int
	Ops [H264MaxRefIdx]H264ListModification
}

H264ListModifications is one list's ref_pic_list_modification, the modifications before the one that ends them.

type H264MMCO

type H264MMCO struct {
	Op                        uint8
	DifferenceOfPicNumsMinus1 uint32
	LongTermPicNum            uint32
	LongTermFrameIdx          uint32
	MaxLongTermFrameIdxPlus1  uint32
}

H264MMCO is one memory_management_control_operation and its arguments (7.3.3.3).

type H264PPS

type H264PPS struct {
	ID, SPSID                         uint8
	EntropyCodingMode                 bool
	BottomFieldPicOrderInFramePresent bool
	NumRefIdxL0DefaultActiveMinus1    uint8
	NumRefIdxL1DefaultActiveMinus1    uint8
	WeightedPred                      bool
	WeightedBipredIdc                 uint8
	PicInitQpMinus26                  int8
	PicInitQsMinus26                  int8
	ChromaQpIndexOffset               int8
	DeblockingFilterControlPresent    bool
	ConstrainedIntraPred              bool
	RedundantPicCntPresent            bool
	Transform8x8Mode                  bool
	ScalingMatrixPresent              bool
	SecondChromaQpIndexOffset         int8
	// Scaling are the picture's scaling lists, resolved against its
	// SPS's: meaningful when ScalingMatrixPresent.
	Scaling H264ScalingLists
}

H264PPS is a picture parameter set (7.3.2.2).

func H264SkipPPS

func H264SkipPPS(id, spsID uint8) H264PPS

H264SkipPPS is the picture parameter set H264SkipSlice's slices name: id, of SPS spsID, with CAVLC, one active reference, no weighted prediction and the deblocking filter control present.

func (*H264PPS) Parse

func (p *H264PPS) Parse(rbsp []byte, sps *[32]*H264SPS) error

Parse reads the PPS from rbsp as H264SPS.Parse does; sps are the sequence parameter sets by ID, for the one it names.

type H264SPS

type H264SPS struct {
	ProfileIdc uint8
	// Constraints are constraint_set0_flag to constraint_set5_flag and
	// reserved_zero_2bits as coded: constraint_set0_flag in bit 7.
	Constraints                 uint8
	LevelIdc                    uint8
	ID                          uint8
	ChromaFormatIdc             uint8
	SeparateColourPlane         bool
	BitDepthLumaMinus8          uint8
	BitDepthChromaMinus8        uint8
	QpprimeYZeroTransformBypass bool
	ScalingMatrixPresent        bool
	// Scaling are the sequence's scaling lists, flat when it has none.
	Scaling                        H264ScalingLists
	Log2MaxFrameNum                uint8
	PicOrderCntType                uint8
	Log2MaxPicOrderCntLsb          uint8
	DeltaPicOrderAlwaysZero        bool
	OffsetForNonRefPic             int32
	OffsetForTopToBottomField      int32
	NumRefFramesInPicOrderCntCycle uint8
	OffsetForRefFrame              [255]int32
	MaxNumRefFrames                uint8
	GapsInFrameNumAllowed          bool
	// WidthMbs and HeightMapUnits are the coded size in macroblocks
	// and map units (macroblock pairs in a stream of fields).
	WidthMbs, HeightMapUnits int
	FrameMbsOnly             bool
	MbAdaptiveFrameField     bool
	Direct8x8Inference       bool
	FrameCropping            bool
	// Crop is frame_crop_left, right, top and bottom_offset.
	Crop       [4]uint32
	VUIPresent bool
	VUI        H264VUI
}

H264SPS is a sequence parameter set (7.3.2.1.1).

func (*H264SPS) ChromaArrayType

func (s *H264SPS) ChromaArrayType() uint8

ChromaArrayType is ChromaArrayType: 0 for monochrome or separately coded planes, else chroma_format_idc.

func (*H264SPS) CropRect

func (s *H264SPS) CropRect() (x0, y0, x1, y1 int)

CropRect is the picture inside the coded frame, in luma samples.

func (*H264SPS) FrameHeightMbs

func (s *H264SPS) FrameHeightMbs() int

FrameHeightMbs is the frame's height in macroblocks.

func (*H264SPS) Parse

func (s *H264SPS) Parse(rbsp []byte) error

Parse reads the SPS from rbsp, the NAL unit's payload after its header byte with emulation prevention removed.

type H264ScalingLists

type H264ScalingLists struct {
	List4x4 [6][16]uint8
	List8x8 [6][64]uint8
}

H264ScalingLists are the 4x4 and 8x8 scaling lists in the order the bitstream codes them (zig-zag), every list resolved: present, a default, or what the fall-back rules carry over.

type H264SliceHeader

type H264SliceHeader struct {
	FirstMbInSlice uint32
	// SliceType is slice_type modulo 5.
	SliceType             uint8
	PPSID                 uint8
	FrameNum              uint32
	FieldPic, BottomField bool
	IDRPicID              uint16
	// NumRefIdxActive is each list's num_ref_idx_active_minus1 plus
	// one: list 0's for a P, SP or B slice, list 1's for a B slice,
	// else 0; Modifications each list's ref_pic_list_modification.
	NumRefIdxActive        [2]uint8
	Modifications          [2]H264ListModifications
	PicOrderCntLsb         uint32
	DeltaPicOrderCntBottom int32
	DeltaPicOrderCnt       [2]int32
	NoOutputOfPriorPics    bool
	LongTermReference      bool
	AdaptiveRefPicMarking  bool
	NumMMCO                int
	MMCO                   [H264MaxMMCO]H264MMCO
}

H264SliceHeader is what a slice header (7.3.3) says that a decoder managing the reference pictures uses.

func (*H264SliceHeader) Parse

func (h *H264SliceHeader) Parse(rbsp []byte, header byte, pps *[256]*H264PPS, sps *[32]*H264SPS) error

Parse reads the slice header from rbsp, the slice NAL unit's payload after its header byte (unit[0]) with emulation prevention removed, as far as its reference picture marking: a prefix of the payload holding the header is enough. pps and sps are the parameter sets by ID.

func (*H264SliceHeader) ParseType

func (h *H264SliceHeader) ParseType(rbsp []byte) error

ParseType reads only first_mb_in_slice, slice_type and pic_parameter_set_id: enough to tell a picture's slices apart.

type H264VUI

type H264VUI struct {
	AspectRatioInfoPresent   bool
	AspectRatioIdc           uint8
	SarWidth, SarHeight      uint16
	OverscanInfoPresent      bool
	OverscanAppropriate      bool
	VideoSignalTypePresent   bool
	VideoFormat              uint8
	FullRange                bool
	ColourDescriptionPresent bool
	ColourPrimaries          uint8
	TransferCharacteristics  uint8
	MatrixCoefficients       uint8
	ChromaLocInfoPresent     bool
	ChromaSampleLocTypeTop   uint8
	ChromaSampleLocTypeBot   uint8
	TimingInfoPresent        bool
	NumUnitsInTick           uint32
	TimeScale                uint32
	FixedFrameRate           bool
	BitstreamRestriction     bool
	MaxNumReorderFrames      uint8
	MaxDecFrameBuffering     uint8
}

H264VUI is what an SPS's video usability information says that a decoder uses.

type HEVC

type HEVC struct {
	// LevelIdc is the level times thirty.
	LevelIdc uint8
	// Width and Height are the coded size in luma samples.
	Width, Height int
	// ConfRight and ConfBottom crop the coded size back to the frame's,
	// in chroma samples.
	ConfRight, ConfBottom int
	// Log2MaxPocLsb is log2 of MaxPicOrderCntLsb.
	Log2MaxPocLsb int
	// Log2MinCb, Log2Ctb, Log2MinTb and Log2MaxTb are the coding block,
	// coding tree block and transform block sizes, as log2.
	Log2MinCb, Log2Ctb, Log2MinTb, Log2MaxTb int
	// TransformDepth is max_transform_hierarchy_depth, inter and intra.
	TransformDepth int
	// AMP, SAO and TemporalMVP are the SPS's tools of those names.
	AMP, SAO, TemporalMVP bool
	// InitQP is the picture's initial quantiser, 26 + init_qp_minus26.
	InitQP int
	// CuQPDelta is cu_qp_delta_enabled_flag, which rate control needs.
	CuQPDelta bool
}

HEVC is what an H.265 stream's video, sequence and picture parameter sets say, for the streams the encoder writes: Main profile, frames only, one temporal layer, one short-term reference picture set (the picture before), no reordering, BT.709 limited range.

func (*HEVC) AppendSliceHeader

func (h *HEVC) AppendSliceHeader(dst []byte, w *Writer, sinceIDR int, gpb bool, qp int) (out []byte, bits int)

AppendSliceHeader appends to dst the slice segment header (7.3.6.1) of the picture sinceIDR frames into its key interval at quantiser qp: one IDR_W_RADL I slice, or one TRAIL_R slice predicting from the picture before through the sequence's short-term reference set, a P slice or, with gpb, a B slice with the same picture in both lists. It ends byte-aligned, where the slice data starts, written through w, which it resets: with a w kept between frames and room in dst it allocates nothing.

func (*HEVC) PPS

func (h *HEVC) PPS() []byte

PPS is the picture parameter set NAL unit (7.3.2.3.1).

func (*HEVC) SPS

func (h *HEVC) SPS() []byte

SPS is the sequence parameter set NAL unit (7.3.2.2.1).

func (*HEVC) VPS

func (h *HEVC) VPS() []byte

VPS is the video parameter set NAL unit (7.3.2.1).

type HEVCLongTerm

type HEVCLongTerm struct {
	PocLsb           uint32
	UsedByCurrPic    bool
	MsbPresent       bool
	DeltaPocMsbCycle uint32
}

HEVCLongTerm is one long-term reference picture a slice header names.

type HEVCPPS

type HEVCPPS struct {
	ID, SPSID                       uint8
	DependentSliceSegments          bool
	OutputFlagPresent               bool
	NumExtraSliceHeaderBits         uint8
	SignDataHiding                  bool
	CabacInitPresent                bool
	NumRefIdxL0DefaultActiveMinus1  uint8
	NumRefIdxL1DefaultActiveMinus1  uint8
	InitQpMinus26                   int8
	ConstrainedIntraPred            bool
	TransformSkipEnabled            bool
	CuQpDeltaEnabled                bool
	DiffCuQpDeltaDepth              uint8
	CbQpOffset, CrQpOffset          int8
	SliceChromaQpOffsetsPresent     bool
	WeightedPred, WeightedBipred    bool
	TransquantBypassEnabled         bool
	TilesEnabled                    bool
	EntropyCodingSyncEnabled        bool
	NumTileColumnsMinus1            uint8
	NumTileRowsMinus1               uint8
	UniformSpacing                  bool
	ColumnWidthMinus1               [19]uint16
	RowHeightMinus1                 [21]uint16
	LoopFilterAcrossTiles           bool
	LoopFilterAcrossSlices          bool
	DeblockingFilterControlPresent  bool
	DeblockingFilterOverrideEnabled bool
	DeblockingFilterDisabled        bool
	BetaOffsetDiv2, TcOffsetDiv2    int8
	ScalingListDataPresent          bool
	// Scaling are the picture's coded lists: meaningful when
	// ScalingListDataPresent.
	Scaling                         HEVCScalingLists
	ListsModificationPresent        bool
	Log2ParallelMergeLevelMinus2    uint8
	SliceSegmentHeaderExtension     bool
	ExtensionPresent                bool
	RangeExtension                  bool
	Log2MaxTransformSkipBlockMinus2 uint8
	CrossComponentPrediction        bool
	ChromaQpOffsetListEnabled       bool
	DiffCuChromaQpOffsetDepth       uint8
	ChromaQpOffsetListLenMinus1     uint8
	CbQpOffsetList, CrQpOffsetList  [6]int8
	Log2SaoOffsetScaleLuma          uint8
	Log2SaoOffsetScaleChroma        uint8
}

HEVCPPS is a picture parameter set (7.3.2.3.1).

func (*HEVCPPS) Parse

func (p *HEVCPPS) Parse(rbsp []byte, sps *[16]*HEVCSPS) error

Parse reads the PPS from rbsp as HEVCVPS.Parse does; sps are the sequence parameter sets by ID, for the one it names.

type HEVCProfileTierLevel

type HEVCProfileTierLevel struct {
	ProfileSpace uint8
	Tier         bool
	ProfileIdc   uint8
	// Compatibility is general_profile_compatibility_flag, flag 0 in
	// bit 31.
	Compatibility uint32
	Progressive   bool
	Interlaced    bool
	NonPacked     bool
	FrameOnly     bool
	LevelIdc      uint8
}

HEVCProfileTierLevel is a profile_tier_level's general part (7.3.3).

type HEVCSPS

type HEVCSPS struct {
	VPSID                       uint8
	MaxSubLayersMinus1          uint8
	TemporalIDNesting           bool
	PTL                         HEVCProfileTierLevel
	ID                          uint8
	ChromaFormatIdc             uint8
	SeparateColourPlane         bool
	Width, Height               int
	ConformanceWindow           bool
	Conf                        [4]uint32
	BitDepthLumaMinus8          uint8
	BitDepthChromaMinus8        uint8
	Log2MaxPocLsb               uint8
	SubLayerOrderingInfoPresent bool
	Ordering                    HEVCSubLayerOrdering
	Log2MinCbMinus3             uint8
	Log2DiffMaxMinCb            uint8
	Log2MinTbMinus2             uint8
	Log2DiffMaxMinTb            uint8
	MaxTransformDepthInter      uint8
	MaxTransformDepthIntra      uint8
	ScalingListEnabled          bool
	ScalingListDataPresent      bool
	// Scaling are the sequence's lists: coded, else the defaults.
	Scaling                 HEVCScalingLists
	AMP, SAO                bool
	PCM                     bool
	PCMBitDepthLumaMinus1   uint8
	PCMBitDepthChromaMinus1 uint8
	Log2MinPCMCbMinus3      uint8
	Log2DiffMaxMinPCMCb     uint8
	PCMLoopFilterDisabled   bool
	NumShortTermRPS         uint8
	ShortTermRPS            [64]HEVCShortTermRPS
	LongTermRefPicsPresent  bool
	NumLongTermRefPicsSPS   uint8
	LtRefPicPocLsbSPS       [32]uint32
	// UsedByCurrPicLtSPS marks entry i in bit i.
	UsedByCurrPicLtSPS       uint32
	TemporalMVP              bool
	StrongIntraSmoothing     bool
	VUIPresent               bool
	VUI                      HEVCVUI
	ExtensionPresent         bool
	RangeExtension           bool
	TransformSkipRotation    bool
	TransformSkipContext     bool
	ImplicitRDPCM            bool
	ExplicitRDPCM            bool
	ExtendedPrecision        bool
	IntraSmoothingDisabled   bool
	HighPrecisionOffsets     bool
	PersistentRiceAdaptation bool
	CabacBypassAlignment     bool
}

HEVCSPS is a sequence parameter set (7.3.2.2.1).

func (*HEVCSPS) CropRect

func (s *HEVCSPS) CropRect() (x0, y0, x1, y1 int)

CropRect is the conformance window, in luma samples.

func (*HEVCSPS) Parse

func (s *HEVCSPS) Parse(rbsp []byte) error

Parse reads the SPS from rbsp as HEVCVPS.Parse does.

type HEVCScalingLists

type HEVCScalingLists struct {
	List4x4   [6][16]uint8
	List8x8   [6][64]uint8
	List16x16 [6][64]uint8
	List32x32 [2][64]uint8
	DC16x16   [6]uint8
	DC32x32   [2]uint8
}

HEVCScalingLists are a scaling_list_data's lists in the order the bitstream codes them (up-right diagonal), every list resolved: coded, a default, or copied from the list it names. List32x32 holds matrices 0 and 3 of size 3.

func (*HEVCScalingLists) Defaults

func (l *HEVCScalingLists) Defaults()

Defaults sets every list to its default: what a stream that enables scaling lists without coding them uses.

type HEVCShortTermRPS

type HEVCShortTermRPS struct {
	InterRPSPred      bool
	DeltaIdxMinus1    uint32
	DeltaRPSSign      bool
	AbsDeltaRPSMinus1 uint32
	// UsedByCurrPicFlag and UseDeltaFlag are the flags of each entry of
	// the set it predicts from, entry j in bit j.
	UsedByCurrPicFlag uint32
	UseDeltaFlag      uint32
	NumNegative       uint8
	NumPositive       uint8
	DeltaPocS0        [16]int32
	DeltaPocS1        [16]int32
	// UsedS0 and UsedS1 mark the pictures the current one references,
	// entry i in bit i.
	UsedS0, UsedS1 uint16
}

HEVCShortTermRPS is a short-term reference picture set (st_ref_pic_set, 7.3.7): its syntax and the delta POCs it works out to (7.4.8).

func (*HEVCShortTermRPS) NumDeltaPocs

func (s *HEVCShortTermRPS) NumDeltaPocs() int

NumDeltaPocs is how many pictures the set names.

type HEVCSliceHeader

type HEVCSliceHeader struct {
	FirstSliceSegmentInPic bool
	NoOutputOfPriorPics    bool
	PPSID                  uint8
	Dependent              bool
	SliceType              uint8
	PicOutput              bool
	PicOrderCntLsb         uint32
	ShortTermRefPicSetSPS  bool
	ShortTermRefPicSetIdx  uint8
	// RPS is the short-term set the header codes, STRPSBits its
	// length.
	RPS             HEVCShortTermRPS
	STRPSBits       int
	NumLongTermSPS  uint8
	NumLongTermPics uint8
	LongTerm        [32]HEVCLongTerm
}

HEVCSliceHeader is what a slice segment header (7.3.6.1) says that a decoder managing the reference pictures uses.

func (*HEVCSliceHeader) Parse

func (h *HEVCSliceHeader) Parse(rbsp []byte, nalType uint8, pps *[64]*HEVCPPS, sps *[16]*HEVCSPS) error

Parse reads the first slice segment header of a picture from rbsp, the NAL unit's payload after its two header bytes with emulation prevention removed, as far as its reference pictures: a prefix of the payload holding them is enough. nalType is its nal_unit_type; pps and sps the parameter sets by ID.

func (*HEVCSliceHeader) ShortTermRPS

func (h *HEVCSliceHeader) ShortTermRPS(s *HEVCSPS) *HEVCShortTermRPS

ShortTermRPS is the short-term reference picture set the slice uses.

type HEVCSubLayerOrdering

type HEVCSubLayerOrdering struct {
	MaxDecPicBufferingMinus1 [HEVCMaxSubLayers]uint8
	MaxNumReorderPics        [HEVCMaxSubLayers]uint8
	MaxLatencyIncreasePlus1  [HEVCMaxSubLayers]uint32
}

HEVCSubLayerOrdering is the DPB size, reordering and latency of each sub-layer, the ones not coded filled in from the highest.

type HEVCVPS

type HEVCVPS struct {
	ID                          uint8
	MaxSubLayersMinus1          uint8
	TemporalIDNesting           bool
	PTL                         HEVCProfileTierLevel
	SubLayerOrderingInfoPresent bool
	Ordering                    HEVCSubLayerOrdering
	TimingInfoPresent           bool
	NumUnitsInTick, TimeScale   uint32
	PocProportionalToTiming     bool
	NumTicksPocDiffOneMinus1    uint32
}

HEVCVPS is a video parameter set (7.3.2.1), as far as its timing.

func (*HEVCVPS) Parse

func (v *HEVCVPS) Parse(rbsp []byte) error

Parse reads the VPS from rbsp, the NAL unit's payload after its two header bytes with emulation prevention removed.

type HEVCVUI

type HEVCVUI struct {
	AspectRatioInfoPresent         bool
	AspectRatioIdc                 uint8
	SarWidth, SarHeight            uint16
	OverscanInfoPresent            bool
	OverscanAppropriate            bool
	VideoSignalTypePresent         bool
	VideoFormat                    uint8
	FullRange                      bool
	ColourDescriptionPresent       bool
	ColourPrimaries                uint8
	TransferCharacteristics        uint8
	MatrixCoeffs                   uint8
	ChromaLocInfoPresent           bool
	ChromaSampleLocTypeTop         uint8
	ChromaSampleLocTypeBot         uint8
	NeutralChromaIndication        bool
	FieldSeq                       bool
	FrameFieldInfoPresent          bool
	DefaultDisplayWindow           bool
	DefDispWin                     [4]uint16
	TimingInfoPresent              bool
	NumUnitsInTick, TimeScale      uint32
	PocProportionalToTiming        bool
	NumTicksPocDiffOneMinus1       uint32
	HRDParametersPresent           bool
	BitstreamRestriction           bool
	TilesFixedStructure            bool
	MotionVectorsOverPicBoundaries bool
	RestrictedRefPicLists          bool
	MinSpatialSegmentationIdc      uint16
	MaxBytesPerPicDenom            uint8
	MaxBitsPerMinCuDenom           uint8
	Log2MaxMvLengthHorizontal      uint8
	Log2MaxMvLengthVertical        uint8
}

HEVCVUI is what an SPS's video usability information says (E.2.1), its HRD parameters read past.

type Reader

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

Reader reads an RBSP's bits, most significant first, with the Exp-Golomb codes the syntax uses. Reading past the end yields zeros and marks the reader Short, which a parser checks once at the end.

func NewReader

func NewReader(rbsp []byte) Reader

NewReader reads rbsp, whose emulation prevention bytes Unescape has removed.

func (*Reader) Flag

func (r *Reader) Flag() bool

Flag reads one bit as a flag, u(1).

func (*Reader) MoreRBSPData

func (r *Reader) MoreRBSPData() bool

MoreRBSPData is more_rbsp_data(): whether syntax remains before the RBSP's trailing bits, the last one bit and the zeros after it.

func (*Reader) Pos

func (r *Reader) Pos() int

Pos is how many bits have been read.

func (*Reader) SE

func (r *Reader) SE() int32

SE reads a signed Exp-Golomb code, se(v).

func (*Reader) Short

func (r *Reader) Short() bool

Short reports whether a read ran past the end of the RBSP.

func (*Reader) Skip

func (r *Reader) Skip(n int)

Skip passes over n bits.

func (*Reader) U

func (r *Reader) U(n int) uint32

U reads an n-bit unsigned value, u(n), n up to 32.

func (*Reader) U8

func (r *Reader) U8(n int) uint8

U8 reads an n-bit value, n up to 8.

func (*Reader) U16

func (r *Reader) U16(n int) uint16

U16 reads an n-bit value, n up to 16.

func (*Reader) UE

func (r *Reader) UE() uint32

UE reads an unsigned Exp-Golomb code, ue(v). A code past 32 bits marks the reader Short.

type Writer

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

Writer collects a NAL unit's RBSP bits, most significant first.

func (*Writer) AppendPacked

func (w *Writer) AppendPacked(dst []byte, header ...byte) (out []byte, bits int)

AppendPacked appends to dst the NAL unit of header bytes and the bits written so far for a driver to continue (a slice header before its slice data): escaped, its last byte zero-padded. It returns dst so grown and how many of the bits appended are the unit's.

func (*Writer) AppendUnit

func (w *Writer) AppendUnit(dst []byte, header ...byte) []byte

AppendUnit appends Unit to dst.

func (*Writer) Flag

func (w *Writer) Flag(b bool)

Flag writes one bit.

func (*Writer) Reset

func (w *Writer) Reset()

Reset empties the writer for another unit, keeping its storage: a Writer kept between units writes them without allocating.

func (*Writer) SE

func (w *Writer) SE(v int32)

SE writes v as a signed Exp-Golomb code, se(v).

func (*Writer) SEInt

func (w *Writer) SEInt(v int)

SEInt writes v as se(v) where the syntax element is held as a Go int; a v outside int32 is a caller bug, and panics.

func (*Writer) Trailing

func (w *Writer) Trailing()

Trailing writes rbsp_trailing_bits: a one, then zeros to the byte.

func (*Writer) U

func (w *Writer) U(n uint, v uint32)

U writes v's low n bits, n up to 32.

func (*Writer) UE

func (w *Writer) UE(v uint32)

UE writes v as an unsigned Exp-Golomb code, ue(v).

func (*Writer) UEInt

func (w *Writer) UEInt(v int)

UEInt writes v as ue(v) where the syntax element is held as a Go int; a v below 0 or above 2^32-2 is a caller bug, and panics.

func (*Writer) UInt

func (w *Writer) UInt(n uint, v int)

UInt writes v as u(n) where the syntax element is held as a Go int; a v outside what n bits hold is a caller bug, and panics.

func (*Writer) Unit

func (w *Writer) Unit(header ...byte) []byte

Unit is the NAL unit of header bytes and the RBSP written so far (byte-aligned by Trailing), emulation prevention bytes inserted.

Directories

Path Synopsis
Package naltest reads H.264 and H.265 headers back through ffmpeg's trace_headers, for tests of what writes them.
Package naltest reads H.264 and H.265 headers back through ffmpeg's trace_headers, for tests of what writes them.

Jump to

Keyboard shortcuts

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