avc

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package avc - parse AVC(H.264) NAL unit headers, slice headers and complete SPS and PPS.

Index

Constants

View Source
const (
	// NALU_NON_IDR - Non-IDR Slice NAL unit
	NALU_NON_IDR = NaluType(1)
	// NALU_IDR - IDR Random Access Slice NAL Unit
	NALU_IDR = NaluType(5)
	// NALU_SEI - Supplementary Enhancement Information NAL Unit
	NALU_SEI = NaluType(6)
	// NALU_SPS - SequenceParameterSet NAL Unit
	NALU_SPS = NaluType(7)
	// NALU_PPS - PictureParameterSet NAL Unit
	NALU_PPS = NaluType(8)
	// NALU_AUD - AccessUnitDelimiter NAL Unit
	NALU_AUD = NaluType(9)
	// NALU_EO_SEQ - End of Sequence NAL Unit
	NALU_EO_SEQ = NaluType(10)
	// NALU_EO_STREAM - End of Stream NAL Unit
	NALU_EO_STREAM = NaluType(11)
	// NALU_FILL - Filler NAL Unit
	NALU_FILL = NaluType(12)
)
View Source
const (
	SEIPicTimingType    = 1
	SEIRegisteredType   = 4
	SEIUnregisteredType = 5
)
View Source
const (
	SLICE_P  = SliceType(0)
	SLICE_B  = SliceType(1)
	SLICE_I  = SliceType(2)
	SLICE_SP = SliceType(3)
	SLICE_SI = SliceType(4)
)

AVC slice types

View Source
const ExtendedSAR = 255

ExtendedSAR - Extended Sample Aspect Ratio Code

Variables

View Source
var (
	ErrCannotParseAVCExtension = errors.New("Cannot parse SPS extensions")
	ErrLengthSize              = errors.New("Can only handle 4byte NAL length size")
)

AVC parsing errors

View Source
var (
	ErrNoSliceHeader      = errors.New("No slice header")
	ErrInvalidSliceType   = errors.New("Invalid slice type")
	ErrTooFewBytesToParse = errors.New("Too few bytes to parse symbol")
)

Errors for parsing and handling AVC slices

View Source
var (
	ErrNotPPS = errors.New("Not an PPS NAL unit")
)

AVC PPS errors

View Source
var (
	ErrNotSPS = errors.New("Not an SPS NAL unit")
)

SPS errors

Functions

func CodecString added in v0.22.0

func CodecString(sampleEntry string, sps *SPS) string

CodecString - sub-parameter for MIME type "codecs" parameter like avc1.42E00C where avc1 is sampleEntry. Defined in ISO/IEC 14496-15 2017.

func ContainsNaluType added in v0.17.0

func ContainsNaluType(sample []byte, specificNalType NaluType) bool

ContainsNaluType - is specific NaluType present in sample

func ConvertByteStreamToNaluSample added in v0.14.0

func ConvertByteStreamToNaluSample(stream []byte) []byte

ConvertByteStreamToNaluSample - Change start codes to 4-byte length fields

func ConvertSampleToByteStream added in v0.14.0

func ConvertSampleToByteStream(sample []byte) []byte

ConvertSampleToByteStream - Replace 4-byte NALU lengths with start codes

func ExtractNalusFromByteStream added in v0.14.0

func ExtractNalusFromByteStream(data []byte) [][]byte

ExtractNalusFromByteStream - extract NALUs without startcode from ByteStream

func GetNalusFromSample added in v0.17.0

func GetNalusFromSample(sample []byte) ([][]byte, error)

GetNalusFromSample - get nalus by following 4 byte length fields

func GetParameterSets added in v0.15.0

func GetParameterSets(sample []byte) (sps [][]byte, pps [][]byte)

GetParameterSets - get (multiple) SPS and PPS from a sample

func GetSARfromIDC added in v0.28.0

func GetSARfromIDC(index uint) (uint, uint, error)

GetSARfromIDC - get Sample Aspect Ratio from IDC index

func HasParameterSets

func HasParameterSets(b []byte) bool

HasParameterSets - Check if H.264 SPS and PPS are present

func IsIDRSample added in v0.14.0

func IsIDRSample(sample []byte) bool

IsIDRSample - does sample contain IDR NALU

Types

type CEA608sei added in v0.26.0

type CEA608sei struct {
	Field1 []byte
	Field2 []byte
	// contains filtered or unexported fields
}

CEA608sei message according to

func NewCEA608sei added in v0.26.0

func NewCEA608sei(sd *SEIData) (*CEA608sei, error)

NewCEA608sei - new CEA 608 SEI message including parsing of CEA-608 fields

func (*CEA608sei) Payload added in v0.26.0

func (s *CEA608sei) Payload() []byte

Payload - SEI raw rbsp payload

func (*CEA608sei) Size added in v0.26.0

func (s *CEA608sei) Size() uint

Size - size in bytes of raw SEI message rbsp payload

func (*CEA608sei) String added in v0.26.0

func (s *CEA608sei) String() string

func (*CEA608sei) Type added in v0.26.0

func (s *CEA608sei) Type() uint

Type - SEI payload type

type CpbEntry

type CpbEntry struct {
	BitRateValueMinus1 uint
	CpbSizeValueMinus1 uint
	CbrFlag            bool
}

CpbEntry inside HrdParameters

type DecConfRec added in v0.26.0

type DecConfRec struct {
	AVCProfileIndication byte
	ProfileCompatibility byte
	AVCLevelIndication   byte
	SPSnalus             [][]byte
	PPSnalus             [][]byte
	ChromaFormat         byte
	BitDepthLumaMinus1   byte
	BitDepthChromaMinus1 byte
	NumSPSExt            byte
	NoTrailingInfo       bool // To handle strange cases where trailing info is missing
}

DecConfRec - AVCDecoderConfigurationRecord

func CreateAVCDecConfRec

func CreateAVCDecConfRec(spsNalus [][]byte, ppsNalus [][]byte, includePS bool) (*DecConfRec, error)

CreateAVCDecConfRec - extract information from sps and insert sps, pps if includePS set

func DecodeAVCDecConfRec

func DecodeAVCDecConfRec(data []byte) (DecConfRec, error)

DecodeAVCDecConfRec - decode an AVCDecConfRec

func (*DecConfRec) Encode added in v0.26.0

func (a *DecConfRec) Encode(w io.Writer) error

Encode - write box to w

func (*DecConfRec) EncodeSW added in v0.27.0

func (a *DecConfRec) EncodeSW(sw bits.SliceWriter) error

Encode - write an AVCDecConfRec to w

func (*DecConfRec) Size added in v0.26.0

func (a *DecConfRec) Size() uint64

Size - total size in bytes

type HrdParameters

type HrdParameters struct {
	CpbCountMinus1                     uint
	BitRateScale                       uint
	CpbSizeScale                       uint
	CpbEntries                         []CpbEntry
	InitialCpbRemovalDelayLengthMinus1 uint
	CpbRemovalDelayLengthMinus1        uint
	DpbOutpuDelayLengthMinus1          uint
	TimeOffsetLength                   uint
}

HrdParameters inside VUI

type ITUData added in v0.26.0

type ITUData struct {
	CountryCode      byte
	UserDataTypeCode byte
	ProviderCode     uint16
	UserIdentifier   uint32
}

ITUData - first 8 bytes of payload for CEA-608 in type 4 (User data registered by ITU-T Rec T 35)

func (ITUData) IsCEA608 added in v0.26.0

func (i ITUData) IsCEA608() bool

IsCEA608 - check if ITU-T data corresponds to CEA-608

type NaluType added in v0.17.0

type NaluType uint16

NaluType - AVC NAL unit type

func FindNaluTypes added in v0.17.0

func FindNaluTypes(sample []byte) []NaluType

FindNaluTypes - find list of NAL unit types in sample

func FindNaluTypesUpToFirstVideoNALU added in v0.25.0

func FindNaluTypesUpToFirstVideoNALU(sample []byte) []NaluType

FindNaluTypesUpToFirstVideoNALU - find list of NAL unit types in sample

func GetNaluType added in v0.17.0

func GetNaluType(naluHeader byte) NaluType

GetNaluType - get NALU type from NALU Header byte

func (NaluType) String added in v0.17.0

func (a NaluType) String() string

type PPS added in v0.12.0

type PPS struct {
	PicParameterSetID                     uint
	SeqParameterSetID                     uint
	EntropyCodingModeFlag                 bool
	BottomFieldPicOrderInFramePresentFlag bool
	NumSliceGroupsMinus1                  uint
	SliceGroupMapType                     uint
	RunLengthMinus1                       []uint
	TopLeft                               []uint
	BottomRight                           []uint
	SliceGroupChangeDirectionFlag         bool
	SliceGroupChangeRateMinus1            uint
	PicSizeInMapUnitsMinus1               uint
	SliceGroupID                          []uint
	NumRefIdxI0DefaultActiveMinus1        uint
	NumRefIdxI1DefaultActiveMinus1        uint
	WeightedPredFlag                      bool
	WeightedBipredIDC                     uint
	PicInitQpMinus26                      int
	PicInitQsMinus26                      int
	ChromaQpIndexOffset                   int
	DeblockingFilterControlPresentFlag    bool
	ConstrainedIntraPredFlag              bool
	RedundantPicCntPresentFlag            bool
	Transform8x8ModeFlag                  bool
	PicScalingMatrixPresentFlag           bool
	PicScalingLists                       []ScalingList
	SecondChromaQpIndexOffset             int
}

PPS - Picture Parameter Set

func ParsePPSNALUnit added in v0.12.0

func ParsePPSNALUnit(data []byte, sps *SPS) (*PPS, error)

ParsePPSNALUnit - Parse AVC PPS NAL unit starting with NAL header

type RegisteredSEI added in v0.26.0

type RegisteredSEI struct {
	ITUTData ITUData
	// contains filtered or unexported fields
}

RegisteredSEI - user_data_registered_itu_t_t35 SEI message

func NewRegisteredSEI added in v0.26.0

func NewRegisteredSEI(sd *SEIData, ituData ITUData) *RegisteredSEI

NewRegisteredSEI - create an ITU-T registered SEI message (type 4)

func (*RegisteredSEI) Payload added in v0.26.0

func (s *RegisteredSEI) Payload() []byte

Payload - SEI raw rbsp payload

func (*RegisteredSEI) Size added in v0.26.0

func (s *RegisteredSEI) Size() uint

Size - size in bytes of raw SEI message rbsp payload

func (*RegisteredSEI) String added in v0.26.0

func (s *RegisteredSEI) String() string

func (*RegisteredSEI) Type added in v0.26.0

func (s *RegisteredSEI) Type() uint

Type - SEI payload type

type SEI added in v0.26.0

type SEI struct {
	SEIMessages []SEIMessage
}

SEI - Supplementary Enhancement Information as defined in ISO/IEC 14496-10 High level syntax in Section 7.3.2.3 The actual types are listed in Annex D

type SEIData added in v0.26.0

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

SEIData - raw parsed SEI message with rbsp data

func ExtractSEIData added in v0.26.0

func ExtractSEIData(r io.ReadSeeker) (seiData []SEIData, err error)

ExtractSEIData - parse ebsp and return SEIData in rbsp format

func (*SEIData) Payload added in v0.26.0

func (s *SEIData) Payload() []byte

Payload - SEI raw rbsp payload

func (*SEIData) Size added in v0.26.0

func (s *SEIData) Size() uint

Size - size in bytes of raw SEI message rbsp payload

func (*SEIData) String added in v0.26.0

func (s *SEIData) String() string

String - print up to 100 bytes of payload

func (*SEIData) Type added in v0.26.0

func (s *SEIData) Type() uint

Type - SEI payload type

type SEIMessage added in v0.26.0

type SEIMessage interface {
	Type() uint
	Size() uint
	String() string
	Payload() []byte
}

SEIMessage is common part of any SEI message

func DecodeSEIMessage added in v0.26.0

func DecodeSEIMessage(sd *SEIData) (SEIMessage, error)

DecodeSEIMessage decodes an SEIMessage

func DecodeUserDataRegisteredSEI added in v0.26.0

func DecodeUserDataRegisteredSEI(sd *SEIData) (SEIMessage, error)

DecodeUserDataRegisteredSEI - decode a SEI message of byte 4

func DecodeUserDataUnregisteredSEI added in v0.26.0

func DecodeUserDataUnregisteredSEI(sd *SEIData) (SEIMessage, error)

DecodeUserDataUnregisteredSEI - Decode an unregistered SEI message (type 5)

type SPS

type SPS struct {
	Profile                         uint
	ProfileCompatibility            uint
	Level                           uint
	ParameterID                     uint
	ChromaFormatIDC                 uint
	SeparateColourPlaneFlag         bool
	BitDepthLumaMinus8              uint
	BitDepthChromaMinus8            uint
	QPPrimeYZeroTransformBypassFlag bool
	SeqScalingMatrixPresentFlag     bool
	SeqScalingLists                 []ScalingList
	Log2MaxFrameNumMinus4           uint
	PicOrderCntType                 uint
	Log2MaxPicOrderCntLsbMinus4     uint
	DeltaPicOrderAlwaysZeroFlag     bool
	OffsetForNonRefPic              uint
	OffsetForTopToBottomField       uint
	RefFramesInPicOrderCntCycle     []uint
	NumRefFrames                    uint
	GapsInFrameNumValueAllowedFlag  bool
	FrameMbsOnlyFlag                bool
	MbAdaptiveFrameFieldFlag        bool
	Direct8x8InferenceFlag          bool
	FrameCroppingFlag               bool
	FrameCropLeftOffset             uint
	FrameCropRightOffset            uint
	FrameCropTopOffset              uint
	FrameCropBottomOffset           uint
	Width                           uint
	Height                          uint
	NrBytesBeforeVUI                int
	NrBytesRead                     int
	VUI                             *VUIParameters
}

SPS - AVC SPS parameters

func ParseSPSNALUnit

func ParseSPSNALUnit(data []byte, parseVUIBeyondAspectRatio bool) (*SPS, error)

ParseSPSNALUnit - Parse AVC SPS NAL unit starting with NAL header

func (*SPS) ConstraintFlags

func (a *SPS) ConstraintFlags() byte

ConstraintFlags - return the four ConstraintFlag bits

func (*SPS) CpbDpbDelaysPresent added in v0.26.0

func (s *SPS) CpbDpbDelaysPresent() bool

CpbDbpDelaysPresent signals if Cpb and Dbp can be found in Picture Timing SEI

func (*SPS) PicStructPresent added in v0.26.0

func (s *SPS) PicStructPresent() bool

PicStructPresent signals if pic struct can be found in Picture Timing SEI

type ScalingList added in v0.12.0

type ScalingList []int

ScalingList - 4x4 or 8x8 Scaling lists. Nil if not present

type SliceType

type SliceType uint

SliceType - AVC slice type

func GetSliceTypeFromNALU added in v0.17.0

func GetSliceTypeFromNALU(data []byte) (sliceType SliceType, err error)

GetSliceTypeFromNALU - parse slice header to get slice type in interval 0 to 4

func (SliceType) String

func (s SliceType) String() string

type UnregisteredSEI added in v0.26.0

type UnregisteredSEI struct {
	UUID []byte
	// contains filtered or unexported fields
}

UnregisteredSEI - SEI message of type 5

func NewUnregisteredSEI added in v0.26.0

func NewUnregisteredSEI(sd *SEIData, uuid []byte) *UnregisteredSEI

NewUnregisteredSEI - Create an unregistered SEI message (type 5)

func (*UnregisteredSEI) Payload added in v0.26.0

func (s *UnregisteredSEI) Payload() []byte

Payload - SEI raw rbsp payload

func (*UnregisteredSEI) Size added in v0.26.0

func (s *UnregisteredSEI) Size() uint

Size - size in bytes of raw SEI message rbsp payload

func (*UnregisteredSEI) String added in v0.26.0

func (s *UnregisteredSEI) String() string

func (*UnregisteredSEI) Type added in v0.26.0

func (s *UnregisteredSEI) Type() uint

Type - SEI payload type

type VUIParameters

type VUIParameters struct {
	SampleAspectRatioWidth             uint
	SampleAspectRatioHeight            uint
	OverscanInfoPresentFlag            bool
	OverscanAppropriateFlag            bool
	VideoSignalTypePresentFlag         bool
	VideoFormat                        uint
	VideoFullRangeFlag                 bool
	ColourDescriptionFlag              bool
	ColourPrimaries                    uint
	TransferCharacteristics            uint
	MatrixCoefficients                 uint
	ChromaLocInfoPresentFlag           bool
	ChromaSampleLocTypeTopField        uint
	ChromaSampleLocTypeBottomField     uint
	TimingInfoPresentFlag              bool
	NumUnitsInTick                     uint
	TimeScale                          uint
	FixedFrameRateFlag                 bool
	NalHrdParametersPresentFlag        bool
	NalHrdParameters                   *HrdParameters
	VclHrdParametersPresentFlag        bool
	VclHrdParameters                   *HrdParameters
	LowDelayHrdFlag                    bool // Only present with HrdParameters
	PicStructPresentFlag               bool
	BitstreamRestrictionFlag           bool
	MotionVectorsOverPicBoundariesFlag bool
	MaxBytesPerPicDenom                uint
	MaxBitsPerMbDenom                  uint
	Log2MaxMvLengthHorizontal          uint
	Log2MaxMvLengthVertical            uint
	MaxNumReorderFrames                uint
	MaxDecFrameBuffering               uint
}

VUIParameters - extra parameters according to 14496-10, E.1

Jump to

Keyboard shortcuts

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