Documentation ¶
Index ¶
- Constants
- Variables
- func BuildSeqHeaderFromSpsPps(sps, pps []byte) ([]byte, error)
- func CaptureAvcc2Annexb(w io.Writer, payload []byte) error
- func IterateNaluAnnexb(nals []byte, handler func(nal []byte)) error
- func IterateNaluAvcc(nals []byte, handler func(nal []byte)) error
- func IterateNaluStartCode(nalu []byte, start int) (pos, length int)
- func ParseNaluType(v uint8) uint8
- func ParseNaluTypeReadable(v uint8) string
- func ParseSliceType(nalu []byte) (uint8, error)
- func ParseSliceTypeReadable(nalu []byte) (string, error)
- func ParseSps(payload []byte, ctx *Context) error
- func ParseSpsPpsFromSeqHeader(payload []byte) (sps, pps []byte, err error)
- func ParseSpsPpsFromSeqHeaderWithoutMalloc(payload []byte) (sps, pps []byte, err error)
- func SplitNaluAnnexb(nals []byte) (nalList [][]byte, err error)
- func SplitNaluAvcc(nals []byte) (nalList [][]byte, err error)
- func SpsPpsSeqHeader2Annexb(payload []byte) ([]byte, error)
- func TryParsePps(payload []byte) error
- func TryParseSeqHeader(payload []byte) error
- type Context
- type DecoderConfigurationRecord
- type Sps
Constants ¶
Variables ¶
var ( NaluStartCode3 = []byte{0x0, 0x0, 0x1} NaluStartCode4 = []byte{0x0, 0x0, 0x0, 0x1} // aud nalu AudNalu = []byte{0x00, 0x00, 0x00, 0x01, 0x09, 0xf0} )
var ErrAvc = errors.New("lal.avc: fxxk")
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
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
@return 内存块为内部独立新申请
func CaptureAvcc2Annexb ¶ added in v0.23.0
AVCC -> Annexb
@param payload: rtmp message的payload部分或者flv tag的payload部分
注意,包含了头部2字节类型以及3字节的cts
func IterateNaluAnnexb ¶ added in v0.23.0
func IterateNaluAvcc ¶ added in v0.23.0
func IterateNaluStartCode ¶ added in v0.23.0
遍历直到找到第一个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 ParseNaluTypeReadable ¶ added in v0.23.0
func ParseSliceType ¶ added in v0.13.0
func ParseSliceTypeReadable ¶ added in v0.13.0
func ParseSpsPpsFromSeqHeader ¶ added in v0.23.0
见func ParseSpsPpsFromSeqHeaderWithoutMalloc
@return sps, pps: 内存块为内部独立新申请
func ParseSpsPpsFromSeqHeaderWithoutMalloc ¶ added in v0.24.0
从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
遍历Annexb格式,去掉start code,获取nal包,正常情况下可能为1个或多个,异常情况下可能一个也没有
具体见单元测试
func SpsPpsSeqHeader2Annexb ¶ added in v0.23.0
AVCC Seq Header -> Annexb
@param payload: rtmp message的payload部分或者flv tag的payload部分
注意,包含了头部2字节类型以及3字节的cts
@return 返回的内存块为内部独立新申请
func TryParsePps ¶ added in v0.23.0
尝试解析PPS所有字段,实验中,请勿直接使用该函数
func TryParseSeqHeader ¶ added in v0.13.0
尝试解析SeqHeader所有字段,实验中,请勿直接使用该函数
@param <payload> rtmp message的payload部分或者flv tag的payload部分
注意,包含了头部2字节类型以及3字节的cts
Types ¶
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