Documentation ¶
Overview ¶
Package avc parses AVC (H.264) NAL unit headers, slice headers and complete SPS and PPS.
Index ¶
- Constants
- Variables
- func CodecString(sampleEntry string, sps *SPS) string
- func ContainsNaluType(sample []byte, specificNalType NaluType) bool
- func ConvertByteStreamToNaluSample(stream []byte) []byte
- func ConvertSampleToByteStream(sample []byte) []byte
- func ExtractNalusFromByteStream(data []byte) [][]byte
- func ExtractNalusOfTypeFromByteStream(nType NaluType, data []byte, stopAtVideo bool) [][]byte
- func GetFirstAVCVideoNALUFromByteStream(data []byte) []byte
- func GetNalusFromSample(sample []byte) ([][]byte, error)
- func GetParameterSets(sample []byte) (sps [][]byte, pps [][]byte)
- func GetParameterSetsFromByteStream(data []byte) (spss, ppss [][]byte)
- func GetSARfromIDC(index uint) (uint, uint, error)
- func HasParameterSets(b []byte) bool
- func IsIDRSample(sample []byte) bool
- func IsVideoNaluType(naluType NaluType) bool
- func ParseSEINalu(nalu []byte, sps *SPS) ([]sei.SEIMessage, error)
- type CpbEntry
- type DecConfRec
- type HrdParameters
- type NaluType
- type PPS
- type SPS
- type ScalingList
- type SliceHeader
- type SliceType
- type VUIParameters
Constants ¶
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) )
const ( SLICE_P = SliceType(0) SLICE_B = SliceType(1) SLICE_I = SliceType(2) SLICE_SP = SliceType(3) SLICE_SI = SliceType(4) )
AVC slice types
const ExtendedSAR = 255
ExtendedSAR - Extended Sample Aspect Ratio Code
Variables ¶
var ( ErrCannotParseAVCExtension = errors.New("Cannot parse SPS extensions") ErrLengthSize = errors.New("Can only handle 4byte NAL length size") )
AVC parsing errors
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
var (
ErrNotPPS = errors.New("Not an PPS NAL unit")
)
AVC PPS errors
var (
ErrNotSEINalu = errors.New("not an SEI NAL unit")
)
var (
ErrNotSPS = errors.New("Not an SPS NAL unit")
)
SPS errors
Functions ¶
func CodecString ¶
CodecString - sub-parameter for MIME type "codecs" parameter like avc1.42E00C where avc1 is sampleEntry. Defined in ISO/IEC 14496-15 2017.
func ContainsNaluType ¶
ContainsNaluType - is specific NaluType present in sample
func ConvertByteStreamToNaluSample ¶
ConvertByteStreamToNaluSample changes start codes to 4-byte length fields. This function is codec agnostic.
func ConvertSampleToByteStream ¶
ConvertSampleToByteStream replaces 4-byte NALU lengths with start codes. This function is codec agnostic.
func ExtractNalusFromByteStream ¶
ExtractNalusFromByteStream extracts NALUs without startcode from ByteStream. This function is codec agnostic.
func ExtractNalusOfTypeFromByteStream ¶
ExtractNalusOfTypeFromByteStream returns all AVC nalus of wanted type from bytestream. If stopAtVideo, the stream is not scanned beyond the first video NAL unit.
func GetFirstAVCVideoNALUFromByteStream ¶
GetFirstAVCVideoNALUFromByteStream returns a slice with the first video nal unit. No new memory is allocated, but a subslice of data is returned.
func GetNalusFromSample ¶
GetNalusFromSample - get nalus by following 4 byte length fields
func GetParameterSets ¶
GetParameterSets - get (multiple) SPS and PPS from a sample
func GetParameterSetsFromByteStream ¶
GetParameterSetsFromByteStream copies AVC SPS and PPS nalus from bytestream (Annex B)
func GetSARfromIDC ¶
GetSARfromIDC - get Sample Aspect Ratio from IDC index
func HasParameterSets ¶
HasParameterSets - Check if H.264 SPS and PPS are present
func IsVideoNaluType ¶
IsVideoNaluType returns true if nalu type is a VCL nalu.
func ParseSEINalu ¶ added in v0.36.0
func ParseSEINalu(nalu []byte, sps *SPS) ([]sei.SEIMessage, error)
ParseSEINalu - parse SEI NAL unit (incl header) and return messages given SPS. Returns sei.ErrRbspTrailingBitsMissing if the NALU is missing the trailing bits.
Types ¶
type DecConfRec ¶
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) EncodeSW ¶
func (a *DecConfRec) EncodeSW(sw bits.SliceWriter) error
Encode - write an AVCDecConfRec to w
type HrdParameters ¶
type HrdParameters struct { CpbCountMinus1 uint BitRateScale uint CpbSizeScale uint CpbEntries []CpbEntry InitialCpbRemovalDelayLengthMinus1 uint CpbRemovalDelayLengthMinus1 uint DpbOutputDelayLengthMinus1 uint TimeOffsetLength uint }
HrdParameters inside VUI
type NaluType ¶
type NaluType uint16
NaluType - AVC NAL unit type
func FindNaluTypes ¶
FindNaluTypes - find list of NAL unit types in sample
func FindNaluTypesUpToFirstVideoNALU ¶
FindNaluTypesUpToFirstVideoNALU - find list of NAL unit types in sample
func GetNaluType ¶
GetNaluType - get NALU type from NALU Header byte
type PPS ¶
type PPS struct { PicParameterSetID uint32 SeqParameterSetID uint32 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
type SPS ¶
type SPS struct { Profile uint32 ProfileCompatibility uint32 Level uint32 ParameterID uint32 ChromaFormatIDC byte 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 ¶
ParseSPSNALUnit - Parse AVC SPS NAL unit starting with NAL header
func (*SPS) ChromaArrayType ¶
ChromaArrayType as defined in Section 7.4.2.1.1 under separate_colour_plane_flag
func (*SPS) ConstraintFlags ¶
ConstraintFlags - return the four ConstraintFlag bits
func (*SPS) CpbDpbDelaysPresent ¶
CpbDbpDelaysPresent signals if Cpb and Dbp can be found in Picture Timing SEI
func (*SPS) PicStructPresent ¶
PicStructPresent signals if pic struct can be found in Picture Timing SEI
type ScalingList ¶
type ScalingList []int
ScalingList - 4x4 or 8x8 Scaling lists. Nil if not present
type SliceHeader ¶
type SliceHeader struct { SliceType SliceType FirstMBInSlice uint32 PicParamID uint32 SeqParamID uint32 ColorPlaneID uint32 FrameNum uint32 IDRPicID uint32 PicOrderCntLsb uint32 DeltaPicOrderCntBottom int32 DeltaPicOrderCnt [2]int32 RedundantPicCnt uint32 NumRefIdxL0ActiveMinus1 uint32 NumRefIdxL1ActiveMinus1 uint32 ModificationOfPicNumsIDC uint32 AbsDiffPicNumMinus1 uint32 LongTermPicNum uint32 AbsDiffViewIdxMinus1 uint32 LumaLog2WeightDenom uint32 ChromaLog2WeightDenom uint32 DifferenceOfPicNumsMinus1 uint32 LongTermFramIdx uint32 MaxLongTermFrameIdxPlus1 uint32 CabacInitIDC uint32 SliceQPDelta int32 SliceQSDelta int32 DisableDeblockingFilterIDC uint32 SliceAlphaC0OffsetDiv2 int32 SliceBetaOffsetDiv2 int32 SliceGroupChangeCycle uint32 Size uint32 FieldPicFlag bool BottomFieldFlag bool DirectSpatialMvPredFlag bool NumRefIdxActiveOverrideFlag bool RefPicListModificationL0Flag bool RefPicListModificationL1Flag bool NoOutputOfPriorPicsFlag bool LongTermReferenceFlag bool SPForSwitchFlag bool AdaptiveRefPicMarkingModeFlag bool }
func ParseSliceHeader ¶
func ParseSliceHeader(nalu []byte, spsMap map[uint32]*SPS, ppsMap map[uint32]*PPS) (*SliceHeader, error)
ParseSliceHeader parses AVC slice header following the syntax in ISO/IEC 14496-10 section 7.3.3
type SliceType ¶
type SliceType uint
SliceType - AVC slice type
func GetSliceTypeFromNALU ¶
GetSliceTypeFromNALU - parse slice header to get slice type in interval 0 to 4
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