Documentation ¶
Overview ¶
Package avc - parse 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 GetNalRefIDC(naluHeader byte) uint
- func GetNalusFromSample(sample []byte) ([][]byte, error)
- func GetParameterSets(sample []byte) (sps [][]byte, pps [][]byte)
- func HasParameterSets(b []byte) bool
- func IsIDRSample(sample []byte) bool
- type AVCDecConfRec
- type AdaptiveMemCtrlDecRefPicMarkingParams
- type CpbEntry
- type DecRefPicMarking
- type HrdParameters
- type NaluType
- type PPS
- type PerEntryRefPicListModParams
- type PredWeightTable
- type RefPicListModification
- 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_SSP - 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) )
Variables ¶
var ErrCannotParseAVCExtension = errors.New("Cannot parse SPS extensions")
var ErrInvalidSliceType = errors.New("Invalid slice type")
var ErrLengthSize = errors.New("Can only handle 4byte NAL length size")
var ErrNoSliceHeader = errors.New("No slice header")
var ErrNotPPS = errors.New("Not an PPS NAL unit")
var ErrNotSPS = errors.New("Not an SPS NAL unit")
var ErrParserNotImplemented = errors.New("Parser not implemented")
var ErrTooFewBytesToParse = errors.New("Too few bytes to parse symbol")
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 - Change start codes to 4-byte length fields
func ConvertSampleToByteStream ¶
ConvertSampleToByteStream - Replace 4-byte NALU lengths with start codes
func ExtractNalusFromByteStream ¶
ExtractNalusFromByteStream - extract NALUs without startcode from ByteStream
func GetNalRefIDC ¶
Get NaluRefIDC from NAL Unit Header byte
func GetNalusFromSample ¶
GetNalusFromSample - get nalus by following 4 byte length fields
func GetParameterSets ¶
GetParameterSets - get (multiple) SPS and PPS from a sample
func HasParameterSets ¶
HasParameterSets - Check if H.264 SPS and PPS are present
Types ¶
type AVCDecConfRec ¶
type AVCDecConfRec 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 }
AVCDecConfRec - AVCDecoderConfigurationRecord
func CreateAVCDecConfRec ¶
func CreateAVCDecConfRec(spsNALUs [][]byte, ppsNALUs [][]byte) (*AVCDecConfRec, error)
CreateAVCDecConfRec - Create an AVCDecConfRec based on SPS and PPS
func DecodeAVCDecConfRec ¶
func DecodeAVCDecConfRec(r io.Reader) (AVCDecConfRec, error)
DecodeAVCDecConfRec - decode an AVCDecConfRec
func (*AVCDecConfRec) Encode ¶
func (a *AVCDecConfRec) Encode(w io.Writer) error
Encode - write an AVCDecConfRec to w
func (*AVCDecConfRec) Size ¶
func (a *AVCDecConfRec) Size() uint64
type AdaptiveMemCtrlDecRefPicMarkingParams ¶
type AdaptiveMemCtrlDecRefPicMarkingParams struct { MemoryManagementControlOperation uint // ue(v) DifferenceOfPicNumsMinus1 uint // ue(v) LongTermPicNum uint // ue(v) LongTermFrameIdx uint // ue(v) MaxLongTermFrameIdxPlus1 uint // ue(V) }
AdaptiveMemCtrlDecRefPicMarkingParams - Used as explained in 8.2.5.4
type DecRefPicMarking ¶
type DecRefPicMarking struct { NoOutputOfPriorPicsFlag bool // u(1) LongTermReferenceFlag bool // u(1) AdaptiveRefPicMarkingModeFlag bool // u(1) AdaptiveRefPicMarkingParams []AdaptiveMemCtrlDecRefPicMarkingParams }
DecRefPicMarking - Decoded Reference Picture Marking Syntax
func ParseDecRefPicMarking ¶
func ParseDecRefPicMarking(r *bits.EBSPReader, naluType NaluType) (*DecRefPicMarking, error)
ParseDecRefPicMarking - AVC Slice Decoded Reference Picture Marking parser using bits r
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 NaluType ¶
type NaluType uint16
NaluType - AVC NAL unit type
func FindNaluTypes ¶
FindNaluTypes - find list of NAL unit types in sample
func GetNaluType ¶
Get NaluType from NAL Unit Header byte
type PPS ¶
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 }
type PerEntryRefPicListModParams ¶
type PerEntryRefPicListModParams struct { ModificationOfPicNumsIDC uint // ue(v) AbsDiffPicNumMinus1 uint // ue(v) LongTermPicNum uint // ue(v) }
PerEntryRefPicListModParams - Ref Pic List Mod params per each entry
type PredWeightTable ¶
type PredWeightTable struct { LumaLog2WeightDenom uint // ue(v) ChromaLog2WeightDenom uint // ue(v) LumaWeightL0Flag bool // u(1) LumaWeightL0 []int // se(v) LumaOffsetL0 []int // se(v) ChromaWeightL0Flag bool // u(1) ChromaWeightL0 [][]int // se(v) ChromaOffsetL0 [][]int // se(v) LumaWeightL1Flag bool // u(1) LumaWeightL1 []int // se(v) LumaOffsetL1 []int // se(v) ChromaWeightL1Flag bool // u(1) ChromaWeightL1 [][]int // se(v) ChromaOffsetL1 [][]int // se(v) }
PredWeightTable - AVC Prediction Weight Table in slice header
func ParsePredWeightTable ¶
func ParsePredWeightTable(r *bits.EBSPReader, sps *SPS, avcsh *SliceHeader) (*PredWeightTable, error)
ParsePredWeightTable - AVC Slice Prediction Weight Table parser using bits r
type RefPicListModification ¶
type RefPicListModification struct { RefPicListModificationFlagL0 bool // u(1) RefPicListModificationFlagL1 bool // u(1) PerEntryParams []PerEntryRefPicListModParams }
RefPicListModification - AVC Ref Pic list modification at slice level
func ParseRefPicListModification ¶
func ParseRefPicListModification(r *bits.EBSPReader, avcsh *SliceHeader) (*RefPicListModification, error)
ParseRefPicListModification - AVC Ref Pic list modification parser using bits r
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 ¶
ParseSPSNALUnit - Parse AVC SPS NAL unit starting with NAL header
func (*SPS) ConstraintFlags ¶
ConstraintFlags - return the four ConstraintFlag bits
type ScalingList ¶
type ScalingList []int // 4x4 or 8x8 Scaling lists. Nil if not present
type SliceHeader ¶
type SliceHeader struct { FirstMbInSlice uint // ue(v) SliceType SliceType // ue(v) PicParameterSetID uint // ue(v) ColourPlaneID uint // u(2) FrameNum uint // u(v) - uses Log2MaxFrameNumMinus4 FieldPicFlag bool // u(1) BottomFieldFlag bool // u(1) IDRPicID uint // ue(v) PicOrderCntLSB uint // u(v) - TODO: what does 'v' depend on? DeltaPicOrderCntBottom int // se(v) DeltaPicOrderCnt [2]int // se(v) RedundantPicCnt uint // ue(v) DirectSpatialMVPredFlag bool // u(1) NumRefIdxActiveOverrideFlag bool // u(1) NumRefIdxL0ActiveMinus1 uint // ue(v) NumRefIdxL1ActiveMinus1 uint // ue(v) // Ref Pic List Modification MVC not implmented RefPicListModification *RefPicListModification PredWeightTable *PredWeightTable DecRefPicMarking *DecRefPicMarking CabacInitIDC uint // ue(v) SliceQPDelta int // se(v) SPForSwitchFlag bool // u(1) SliceQSDelta int // se(v) DisableDeblockingFilterIDC uint // ue(v) SliceAlphaC0OffsetDev2 int // se(v) SliceBetaOffsetDev2 int // se(v) SliceGroupChangeCycle uint // u(v) - TODO: what does 'v' depend on? }
SliceHeader - AVC Slice header
func ParseSliceHeader ¶
ParseSliceHeader - Parse AVC Slice Header starting with NAL header
type SliceType ¶
type SliceType uint
func GetSliceTypeFromNALU ¶
GetSliceTypeFromNALU - parse slice header to get slice type in interval 0 to 4 This function is no longer necessary after the ParseSliceHeader is added
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