avc

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2021 License: MIT Imports: 8 Imported by: 6

Documentation

Index

Constants

View Source
const (
	NaluTypeSlice    uint8 = 1
	NaluTypeIdrSlice uint8 = 5
	NaluTypeSei      uint8 = 6
	NaluTypeSps      uint8 = 7
	NaluTypePps      uint8 = 8
	NaluTypeAud      uint8 = 9  // Access Unit Delimiter
	NaluTypeFd       uint8 = 12 // Filler Data
)
View Source
const (
	SliceTypeP  uint8 = 0
	SliceTypeB  uint8 = 1
	SliceTypeI  uint8 = 2
	SliceTypeSp uint8 = 3
	SliceTypeSi uint8 = 4
)

Variables

View Source
var (
	NaluStartCode3 = []byte{0x0, 0x0, 0x1}
	NaluStartCode4 = []byte{0x0, 0x0, 0x0, 0x1}

	// aud nalu
	AudNalu = []byte{0x00, 0x00, 0x00, 0x01, 0x09, 0xf0}
)
View Source
var ErrAvc = errors.New("lal.avc: fxxk")
View Source
var NaluTypeMapping = map[uint8]string{
	1:  "SLICE",
	5:  "IDR",
	6:  "SEI",
	7:  "SPS",
	8:  "PPS",
	9:  "AUD",
	12: "FD",
}

H.264-AVC-ISO_IEC_14496-15.pdf Table 1 - NAL unit types in elementary streams

View Source
var SliceTypeMapping = map[uint8]string{
	0: "P",
	1: "B",
	2: "I",
	3: "SP",
	4: "SI",
	5: "P",
	6: "B",
	7: "I",
	8: "SP",
	9: "SI",
}

Functions

func BuildSeqHeaderFromSpsPps added in v0.23.0

func BuildSeqHeaderFromSpsPps(sps, pps []byte) ([]byte, error)

@return 内存块为内部独立新申请

func CaptureAvcc2Annexb added in v0.23.0

func CaptureAvcc2Annexb(w io.Writer, payload []byte) error

AVCC -> Annexb

@param payload: rtmp message的payload部分或者flv tag的payload部分

注意,包含了头部2字节类型以及3字节的cts

func IterateNaluAnnexb added in v0.23.0

func IterateNaluAnnexb(nals []byte, handler func(nal []byte)) error

func IterateNaluAvcc added in v0.23.0

func IterateNaluAvcc(nals []byte, handler func(nal []byte)) error

func IterateNaluStartCode added in v0.23.0

func IterateNaluStartCode(nalu []byte, start int) (pos, length int)

遍历直到找到第一个nalu start code的位置

@param start: 从`nalu`的start位置开始查找

@return pos: start code的起始位置(包含start code自身)

length: start code的长度,可能是3或者4
注意,如果找不到start code,则返回-1, -1

func ParseNaluType added in v0.23.0

func ParseNaluType(v uint8) uint8

func ParseNaluTypeReadable added in v0.23.0

func ParseNaluTypeReadable(v uint8) string

func ParseSliceType added in v0.13.0

func ParseSliceType(nalu []byte) (uint8, error)

func ParseSliceTypeReadable added in v0.13.0

func ParseSliceTypeReadable(nalu []byte) (string, error)

func ParseSps added in v0.23.0

func ParseSps(payload []byte, ctx *Context) error

func ParseSpsPpsFromSeqHeader added in v0.23.0

func ParseSpsPpsFromSeqHeader(payload []byte) (sps, pps []byte, err error)

见func ParseSpsPpsFromSeqHeaderWithoutMalloc

@return sps, pps: 内存块为内部独立新申请

func ParseSpsPpsFromSeqHeaderWithoutMalloc added in v0.24.0

func ParseSpsPpsFromSeqHeaderWithoutMalloc(payload []byte) (sps, pps []byte, err error)

从AVCC格式的Seq Header中得到SPS和PPS内存块

@param payload: rtmp message的payload部分或者flv tag的payload部分

注意,包含了头部2字节类型以及3字节的cts

@return sps, pps: 复用传入参数`payload`的内存块

func SplitNaluAnnexb added in v0.23.0

func SplitNaluAnnexb(nals []byte) (nalList [][]byte, err error)

遍历Annexb格式,去掉start code,获取nal包,正常情况下可能为1个或多个,异常情况下可能一个也没有

具体见单元测试

func SplitNaluAvcc added in v0.23.0

func SplitNaluAvcc(nals []byte) (nalList [][]byte, err error)

遍历AVCC格式,去掉4字节长度,获取nal包,正常情况下可能返回1个或多个,异常情况下可能一个也没有

具体见单元测试

func SpsPpsSeqHeader2Annexb added in v0.23.0

func SpsPpsSeqHeader2Annexb(payload []byte) ([]byte, error)

AVCC Seq Header -> Annexb

@param payload: rtmp message的payload部分或者flv tag的payload部分

注意,包含了头部2字节类型以及3字节的cts

@return 返回的内存块为内部独立新申请

func TryParsePps added in v0.23.0

func TryParsePps(payload []byte) error

尝试解析PPS所有字段,实验中,请勿直接使用该函数

func TryParseSeqHeader added in v0.13.0

func TryParseSeqHeader(payload []byte) error

尝试解析SeqHeader所有字段,实验中,请勿直接使用该函数

@param <payload> rtmp message的payload部分或者flv tag的payload部分

注意,包含了头部2字节类型以及3字节的cts

Types

type Context added in v0.13.0

type Context struct {
	Profile uint8
	Level   uint8
	Width   uint32
	Height  uint32
}

type DecoderConfigurationRecord added in v0.13.0

type DecoderConfigurationRecord struct {
	ConfigurationVersion uint8
	AvcProfileIndication uint8
	ProfileCompatibility uint8
	AvcLevelIndication   uint8
	LengthSizeMinusOne   uint8
	NumOfSps             uint8
	SpsLength            uint16
	NumOfPps             uint8
	PpsLength            uint16
}

H.264-AVC-ISO_IEC_14496-15.pdf 5.2.4 Decoder configuration information

type Sps added in v0.23.0

type Sps struct {
	ProfileIdc                     uint8
	ConstraintSet0Flag             uint8
	ConstraintSet1Flag             uint8
	ConstraintSet2Flag             uint8
	LevelIdc                       uint8
	SpsId                          uint32
	ChromaFormatIdc                uint32
	ResidualColorTransformFlag     uint8
	BitDepthLuma                   uint32
	BitDepthChroma                 uint32
	TransFormBypass                uint8
	Log2MaxFrameNumMinus4          uint32
	PicOrderCntType                uint32
	Log2MaxPicOrderCntLsb          uint32
	NumRefFrames                   uint32 // num_ref_frames
	GapsInFrameNumValueAllowedFlag uint8  // gaps_in_frame_num_value_allowed_flag
	PicWidthInMbsMinusOne          uint32 // pic_width_in_mbs_minus1
	PicHeightInMapUnitsMinusOne    uint32 // pic_height_in_map_units_minus1
	FrameMbsOnlyFlag               uint8  // frame_mbs_only_flag
	MbAdaptiveFrameFieldFlag       uint8  // mb_adaptive_frame_field_flag
	Direct8X8InferenceFlag         uint8  // direct_8x8_inference_flag
	FrameCroppingFlag              uint8  // frame_cropping_flag
	FrameCropLeftOffset            uint32 // frame_crop_left_offset
	FrameCropRightOffset           uint32 // frame_crop_right_offset
	FrameCropTopOffset             uint32 // frame_crop_top_offset
	FrameCropBottomOffset          uint32 // frame_crop_bottom_offset
}

ISO-14496-10.pdf 7.3.2.1 Sequence parameter set RBSP syntax 7.4.2.1 Sequence parameter set RBSP semantics

Jump to

Keyboard shortcuts

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