h264

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 2 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 h264 holds the H.264 bitstream helpers the containers share: avcC decoder-configuration parsing and AVCC (length-prefixed) to Annex B (start-code) conversion. Inside goav, H.264 packets travel as Annex B; the demuxers of length-prefixed containers convert on read and the muxers of those containers convert back on write.

Index

Constants

View Source
const (
	NALIDR = 5
	NALSPS = 7
	NALPPS = 8
)

NAL unit types the helpers inspect.

Variables

View Source
var ErrInvalid = errors.New("h264: invalid bitstream")

ErrInvalid reports a malformed avcC record or AVCC sample.

View Source
var StartCode = [4]byte{0, 0, 0, 1}

StartCode is the 4-byte Annex B start code.

Functions

func AppendAVC

func AppendAVC(dst []byte, src []byte) ([]byte, error)

AppendAVC appends the Annex B access unit src to dst as an AVCC sample with 4-byte NAL lengths.

func AppendAnnexB

func AppendAnnexB(dst []byte, src []byte, lengthSize int) ([]byte, error)

AppendAnnexB appends the AVCC sample src, converted to Annex B, to dst.

func ConfigFromAnnexB

func ConfigFromAnnexB(units ...[]byte) ([]byte, error)

ConfigFromAnnexB builds an avcC record, with 4-byte NAL lengths, from the parameter sets the Annex B access units carry.

func ContainsNAL

func ContainsNAL(data []byte, nalType byte) bool

ContainsNAL reports whether the Annex B access unit data carries a NAL unit of nalType.

func ForEachNAL

func ForEachNAL(data []byte, fn func(nal []byte) error) error

ForEachNAL calls fn with each NAL unit of the Annex B access unit data, without its start code. Data must begin with a start code, after optional leading zero bytes.

func HasStartCode

func HasStartCode(data []byte) bool

HasStartCode reports whether data begins with an Annex B start code.

Types

type Config

type Config struct {
	// LengthSize is the byte width (1, 2, or 4) of each NAL length prefix in
	// AVCC samples.
	LengthSize int
	SPS        [][]byte
	PPS        [][]byte
}

Config is the subset of an AVCDecoderConfigurationRecord (avcC) the conversions need.

func ParseConfig

func ParseConfig(record []byte) (Config, error)

ParseConfig parses an avcC record. The SPS/PPS slices alias record.

func (Config) AppendParameterSets

func (c Config) AppendParameterSets(dst []byte) []byte

AppendParameterSets appends the config's SPS and PPS NAL units to dst as Annex B, each behind a start code.

Jump to

Keyboard shortcuts

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