h264

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 5 Imported by: 70

Documentation

Overview

Package h264 contains utilities to work with the H264 codec.

Index

Constants

View Source
const (
	// MaxAccessUnitSize is the maximum size of an access unit.
	// With a 50 Mbps 2160p60 H264 video, the maximum size does not seem to exceed 8 MiB.
	MaxAccessUnitSize = 8 * 1024 * 1024

	// MaxNALUsPerAccessUnit is the maximum number of NALUs per access unit.
	// with x264, tune=zerolatency and 4K resolution, NALU count is lower than 25.
	MaxNALUsPerAccessUnit = 25
)

Variables

View Source
var ErrAVCCNoNALUs = errors.New("AVCC unit doesn't contain any NALU")

ErrAVCCNoNALUs is returned by AVCCUnmarshal when no NALUs have been decoded.

Functions

func AVCCMarshal

func AVCCMarshal(au [][]byte) ([]byte, error)

AVCCMarshal encodes an access unit into the AVCC stream format. Specification: ISO 14496-15, section 5.3.4.2.1

func AVCCUnmarshal

func AVCCUnmarshal(buf []byte) ([][]byte, error)

AVCCUnmarshal decodes an access unit from the AVCC stream format. Specification: ISO 14496-15, section 5.3.4.2.1

func AnnexBMarshal

func AnnexBMarshal(au [][]byte) ([]byte, error)

AnnexBMarshal encodes an access unit into the Annex-B stream format. Specification: ITU-T Rec. H.264, Annex B

func AnnexBUnmarshal

func AnnexBUnmarshal(buf []byte) ([][]byte, error)

AnnexBUnmarshal decodes an access unit from the Annex-B stream format. Specification: ITU-T Rec. H.264, Annex B

func EmulationPreventionRemove

func EmulationPreventionRemove(nalu []byte) []byte

EmulationPreventionRemove removes emulation prevention bytes from a NALU. Specification: ITU-T Rec. H.264, 7.4.1 NAL unit semantics

func IDRPresent

func IDRPresent(au [][]byte) bool

IDRPresent check whether there's an IDR inside the access unit.

Types

type DTSExtractor

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

DTSExtractor allows to extract DTS from PTS.

func NewDTSExtractor

func NewDTSExtractor() *DTSExtractor

NewDTSExtractor allocates a DTSExtractor.

func (*DTSExtractor) Extract

func (d *DTSExtractor) Extract(au [][]byte, pts time.Duration) (time.Duration, error)

Extract extracts the DTS of an access unit.

type NALUType

type NALUType uint8

NALUType is the type of a NALU. Specification: ITU-T Rec. H.264, Table 7-1

const (
	NALUTypeNonIDR                        NALUType = 1
	NALUTypeDataPartitionA                NALUType = 2
	NALUTypeDataPartitionB                NALUType = 3
	NALUTypeDataPartitionC                NALUType = 4
	NALUTypeIDR                           NALUType = 5
	NALUTypeSEI                           NALUType = 6
	NALUTypeSPS                           NALUType = 7
	NALUTypePPS                           NALUType = 8
	NALUTypeAccessUnitDelimiter           NALUType = 9
	NALUTypeEndOfSequence                 NALUType = 10
	NALUTypeEndOfStream                   NALUType = 11
	NALUTypeFillerData                    NALUType = 12
	NALUTypeSPSExtension                  NALUType = 13
	NALUTypePrefix                        NALUType = 14
	NALUTypeSubsetSPS                     NALUType = 15
	NALUTypeReserved16                    NALUType = 16
	NALUTypeReserved17                    NALUType = 17
	NALUTypeReserved18                    NALUType = 18
	NALUTypeSliceLayerWithoutPartitioning NALUType = 19
	NALUTypeSliceExtension                NALUType = 20
	NALUTypeSliceExtensionDepth           NALUType = 21
	NALUTypeReserved22                    NALUType = 22
	NALUTypeReserved23                    NALUType = 23

	// additional NALU types for RTP/H264
	NALUTypeSTAPA  NALUType = 24
	NALUTypeSTAPB  NALUType = 25
	NALUTypeMTAP16 NALUType = 26
	NALUTypeMTAP24 NALUType = 27
	NALUTypeFUA    NALUType = 28
	NALUTypeFUB    NALUType = 29
)

NALU types.

func (NALUType) String

func (nt NALUType) String() string

String implements fmt.Stringer.

type SPS

type SPS struct {
	ProfileIdc         uint8
	ConstraintSet0Flag bool
	ConstraintSet1Flag bool
	ConstraintSet2Flag bool
	ConstraintSet3Flag bool
	ConstraintSet4Flag bool
	ConstraintSet5Flag bool
	LevelIdc           uint8
	ID                 uint32

	// only for selected ProfileIdcs
	ChromaFormatIdc                 uint32
	SeparateColourPlaneFlag         bool
	BitDepthLumaMinus8              uint32
	BitDepthChromaMinus8            uint32
	QpprimeYZeroTransformBypassFlag bool

	// seqScalingListPresentFlag == true
	ScalingList4x4                 [][]int32
	UseDefaultScalingMatrix4x4Flag []bool
	ScalingList8x8                 [][]int32
	UseDefaultScalingMatrix8x8Flag []bool

	Log2MaxFrameNumMinus4 uint32
	PicOrderCntType       uint32

	// PicOrderCntType == 0
	Log2MaxPicOrderCntLsbMinus4 uint32

	// PicOrderCntType == 1
	DeltaPicOrderAlwaysZeroFlag bool
	OffsetForNonRefPic          int32
	OffsetForTopToBottomField   int32
	OffsetForRefFrames          []int32

	MaxNumRefFrames                uint32
	GapsInFrameNumValueAllowedFlag bool
	PicWidthInMbsMinus1            uint32
	PicHeightInMapUnitsMinus1      uint32
	FrameMbsOnlyFlag               bool

	// FrameMbsOnlyFlag == false
	MbAdaptiveFrameFieldFlag bool

	Direct8x8InferenceFlag bool
	FrameCropping          *SPS_FrameCropping
	VUI                    *SPS_VUI
}

SPS is a H264 sequence parameter set. Specification: ITU-T Rec. H.264, 7.3.2.1.1

func (SPS) FPS

func (s SPS) FPS() float64

FPS returns the frames per second of the video.

func (SPS) Height

func (s SPS) Height() int

Height returns the video height.

func (*SPS) Unmarshal

func (s *SPS) Unmarshal(buf []byte) error

Unmarshal decodes a SPS from bytes.

func (SPS) Width

func (s SPS) Width() int

Width returns the video width.

type SPS_BitstreamRestriction

type SPS_BitstreamRestriction struct {
	MotionVectorsOverPicBoundariesFlag bool
	MaxBytesPerPicDenom                uint32
	MaxBitsPerMbDenom                  uint32
	Log2MaxMvLengthHorizontal          uint32
	Log2MaxMvLengthVertical            uint32
	MaxNumReorderFrames                uint32
	MaxDecFrameBuffering               uint32
}

SPS_BitstreamRestriction are bitstream restriction infos.

type SPS_FrameCropping

type SPS_FrameCropping struct {
	LeftOffset   uint32
	RightOffset  uint32
	TopOffset    uint32
	BottomOffset uint32
}

SPS_FrameCropping is the frame cropping part of a SPS.

type SPS_HRD

type SPS_HRD struct {
	CpbCntMinus1                       uint32
	BitRateScale                       uint8
	CpbSizeScale                       uint8
	BitRateValueMinus1                 []uint32
	CpbSizeValueMinus1                 []uint32
	CbrFlag                            []bool
	InitialCpbRemovalDelayLengthMinus1 uint8
	CpbRemovalDelayLengthMinus1        uint8
	DpbOutputDelayLengthMinus1         uint8
	TimeOffsetLength                   uint8
}

SPS_HRD is a hypotetical reference decoder.

type SPS_TimingInfo

type SPS_TimingInfo struct {
	NumUnitsInTick     uint32
	TimeScale          uint32
	FixedFrameRateFlag bool
}

SPS_TimingInfo is a timing info.

type SPS_VUI

type SPS_VUI struct {
	AspectRatioInfoPresentFlag bool

	// AspectRatioInfoPresentFlag == true
	AspectRatioIdc uint8
	SarWidth       uint16
	SarHeight      uint16

	OverscanInfoPresentFlag bool

	// OverscanInfoPresentFlag == true
	OverscanAppropriateFlag    bool
	VideoSignalTypePresentFlag bool

	// VideoSignalTypePresentFlag == true
	VideoFormat                  uint8
	VideoFullRangeFlag           bool
	ColourDescriptionPresentFlag bool

	// ColourDescriptionPresentFlag == true
	ColourPrimaries         uint8
	TransferCharacteristics uint8
	MatrixCoefficients      uint8

	ChromaLocInfoPresentFlag bool

	// ChromaLocInfoPresentFlag == true
	ChromaSampleLocTypeTopField    uint32
	ChromaSampleLocTypeBottomField uint32

	TimingInfo *SPS_TimingInfo
	NalHRD     *SPS_HRD
	VclHRD     *SPS_HRD

	LowDelayHrdFlag      bool
	PicStructPresentFlag bool
	BitstreamRestriction *SPS_BitstreamRestriction
}

SPS_VUI is a video usability information.

Jump to

Keyboard shortcuts

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