nal

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 3 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 H.264 and H.265 NAL units: the bit writer with Exp-Golomb codes the syntax uses, the escaping of start-code-like byte runs, and the parameter sets an encoder that does not write its own (VA-API's, given packed headers) puts in the stream.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnnexB

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

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

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) 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).

func (*H264) SliceHeader

func (h *H264) SliceHeader(sinceIDR int, idrPicID uint16, qp int) (unit []byte, bits int)

SliceHeader is 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, stopping where the slice data starts.

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) 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) SliceHeader

func (h *HEVC) SliceHeader(sinceIDR int, gpb bool, qp int) (unit []byte, bits int)

SliceHeader is 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.

func (*HEVC) VPS

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

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

type Writer

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

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

func (*Writer) Flag

func (w *Writer) Flag(b bool)

Flag writes one bit.

func (*Writer) Packed

func (w *Writer) Packed(header ...byte) (unit []byte, bits int)

Packed is 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, and how many of its bits are the unit's.

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