h264

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Package h264 contains utilities to work with the H264 codec.

Index

Constants

View Source
const (
	// MaxNALUSize is the maximum size of a NALU.
	// with a 250 Mbps H264 video, the maximum NALU size is 2.2MB
	MaxNALUSize = 3 * 1024 * 1024

	// MaxNALUsPerGroup is the maximum number of NALUs per group.
	MaxNALUsPerGroup = 20
)

Variables

This section is empty.

Functions

func AVCCMarshal

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

AVCCMarshal encodes NALUs into the AVCC stream format.

func AVCCUnmarshal

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

AVCCUnmarshal decodes NALUs from the AVCC stream format.

func AnnexBMarshal

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

AnnexBMarshal encodes NALUs into the Annex-B stream format.

func AnnexBUnmarshal

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

AnnexBUnmarshal decodes NALUs from the Annex-B stream format.

func AntiCompetitionRemove

func AntiCompetitionRemove(nalu []byte) []byte

AntiCompetitionRemove removes the anti-competition bytes from a NALU.

func IDRPresent

func IDRPresent(nalus [][]byte) bool

IDRPresent check if there's an IDR inside provided NALUs.

Types

type DTSExtractor

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

DTSExtractor is a utility that allows to extract NALU DTS from PTS.

func NewDTSExtractor

func NewDTSExtractor() *DTSExtractor

NewDTSExtractor allocates a DTSExtractor.

func (*DTSExtractor) Extract

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

Extract extracts the DTS of a group of NALUs.

type NALUType

type NALUType uint8

NALUType is the type of a NALU.

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
)

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
	ChromeFormatIdc                 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
	PicHeightInMbsMinus1           uint32
	FrameMbsOnlyFlag               bool

	// FrameMbsOnlyFlag == false
	MbAdaptiveFrameFieldFlag bool

	Direct8x8InferenceFlag bool

	// frameCroppingFlag == true
	FrameCropping *SPS_FrameCropping

	// vuiParameterPresentFlag == true
	VUI *SPS_VUI
}

SPS is a H264 sequence parameter set.

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
	AspectRatioIdc             uint8
	SarWidth                   uint16
	SarHeight                  uint16
	OverscanInfoPresentFlag    bool
	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

	// timingInfoPresentFlag == true
	TimingInfo *SPS_TimingInfo

	// nalHrdParametersPresentFlag == true
	NalHRD *SPS_HRD

	// vclHrdParametersPresentFlag == true
	VclHRD *SPS_HRD

	LowDelayHrdFlag      bool
	PicStructPresentFlag bool

	// bitstreamRestrictionFlag == true
	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