codec

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VERSION_RESERVED = 0
	VERSION_MPEG_1   = 1
	VERSION_MPEG_2   = 2
	VERSION_MPEG_2_5 = 3
)
View Source
const (
	LAYER_RESERVED = 0
	LAYER_1        = 1
	LAYER_2        = 2
	LAYER_3        = 3
)
View Source
const (
	LEFT_CHANNEL  = 0
	RIGHT_CHANNEL = 1
)

Variables

View Source
var (
	/// 10ms,20ms,40ms,60ms, samplerate 48000
	//  sample num per millisecond
	//  48000 / 1000ms * 10 = 480 ...
	SLKOpusSampleSize    [4]int = [4]int{480, 960, 1920, 2880}
	HybridOpusSampleSize [4]int = [4]int{480, 960}
	CELTOpusSampleSize   [4]int = [4]int{120, 210, 480, 960}
)
View Source
var AAC_Sampling_Idx [13]int = [13]int{96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350}
View Source
var BitMask [8]byte = [8]byte{0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF}
View Source
var BitRateTable [2][3][16]int = [2][3][16]int{
	{
		{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, -1},
		{0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 380, -1},
		{0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1},
	},
	{
		{0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, -1},
		{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1},
		{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1},
	},
}

ffmpeg mpegaudiotabs.h ff_mpa_bitrate_tab

View Source
var SampleRateTable [3][4]int = [3][4]int{
	{44100, 48000, 32000, 0},
	{22050, 24000, 16000, 0},
	{11025, 12000, 8000, 0},
}

Functions

func AACSampleIdxToSample

func AACSampleIdxToSample(idx int) int

func CalcCrc32

func CalcCrc32(crc uint32, buffer []byte) uint32

func CodecString

func CodecString(codecid CodecID) string

func ConvertAnnexBToAVCC

func ConvertAnnexBToAVCC(annexb []byte) []byte

func CovertAVCCToAnnexB

func CovertAVCCToAnnexB(avcc []byte)

func CovertExtradata

func CovertExtradata(extraData []byte) ([][]byte, [][]byte)

func CovertRbspToSodb

func CovertRbspToSodb(rbsp []byte) []byte

func CreateH264AVCCExtradata

func CreateH264AVCCExtradata(spss [][]byte, ppss [][]byte) ([]byte, error)

func FindSyncword

func FindSyncword(aac []byte, offset int) int

func GetH264FirstMbInSlice

func GetH264FirstMbInSlice(nalu []byte) uint64

func GetH264Resolution

func GetH264Resolution(sps []byte) (width uint32, height uint32)

https://stackoverflow.com/questions/12018535/get-the-width-height-of-the-video-from-h-264-nalu int Width = ((pic_width_in_mbs_minus1 +1)*16) - frame_crop_right_offset *2 - frame_crop_left_offset *2; int Height = ((2 - frame_mbs_only_flag)* (pic_height_in_map_units_minus1 +1) * 16) - (frame_crop_bottom_offset* 2) - (frame_crop_top_offset* 2);

func GetH265FirstMbInSlice

func GetH265FirstMbInSlice(nalu []byte) uint64

func GetH265PPSId

func GetH265PPSId(pps []byte) uint64

func GetH265PPSIdWithStartCode

func GetH265PPSIdWithStartCode(pps []byte) uint64

func GetH265Resolution

func GetH265Resolution(sps []byte) (width uint32, height uint32)

func GetH265SPSId

func GetH265SPSId(sps []byte) uint64

func GetH265SPSIdWithStartCode

func GetH265SPSIdWithStartCode(sps []byte) uint64

func GetPPSId

func GetPPSId(pps []byte) uint64

func GetPPSIdWithStartCode

func GetPPSIdWithStartCode(pps []byte) uint64

func GetSPSId

func GetSPSId(sps []byte) uint64

func GetSPSIdWithStartCode

func GetSPSIdWithStartCode(sps []byte) uint64

func GetVPSId

func GetVPSId(vps []byte) uint8

func GetVPSIdWithStartCode

func GetVPSIdWithStartCode(vps []byte) uint8

func IsH264IDRFrame

func IsH264IDRFrame(h264 []byte) bool

func IsH264VCLNaluType

func IsH264VCLNaluType(nal_type H264_NAL_TYPE) bool

func IsH265IDRFrame

func IsH265IDRFrame(h265 []byte) bool

func IsH265VCLNaluType

func IsH265VCLNaluType(nal_type H265_NAL_TYPE) bool

func Max

func Max(x, y int) int

func Min

func Min(x, y int) int

func OpusPacketDuration

func OpusPacketDuration(packet []byte) uint64

func SampleToAACSampleIndex

func SampleToAACSampleIndex(sampling int) int

func ShowPacketHexdump

func ShowPacketHexdump(data []byte)

func SplitAACFrame

func SplitAACFrame(frames []byte, onFrame func(aac []byte))

func SplitFrame

func SplitFrame(frames []byte, onFrame func(nalu []byte) bool)

func SplitFrameWithStartCode

func SplitFrameWithStartCode(frames []byte, onFrame func(nalu []byte) bool)

func SplitMp3Frames

func SplitMp3Frames(data []byte, onFrame func(head *MP3FrameHead, frame []byte)) error

func WriteDefaultOpusExtraData

func WriteDefaultOpusExtraData() []byte

Types

type AAC_PROFILE

type AAC_PROFILE int
const (
	MAIN AAC_PROFILE = iota
	LC
	SSR
)

type AAC_SAMPLING_FREQUENCY

type AAC_SAMPLING_FREQUENCY int
const (
	AAC_SAMPLE_96000 AAC_SAMPLING_FREQUENCY = iota
	AAC_SAMPLE_88200
	AAC_SAMPLE_64000
	AAC_SAMPLE_48000
	AAC_SAMPLE_44100
	AAC_SAMPLE_32000
	AAC_SAMPLE_24000
	AAC_SAMPLE_22050
	AAC_SAMPLE_16000
	AAC_SAMPLE_12000
	AAC_SAMPLE_11025
	AAC_SAMPLE_8000
	AAC_SAMPLE_7350
)

type ADTS_Fix_Header

type ADTS_Fix_Header struct {
	ID                       uint8
	Layer                    uint8
	Protection_absent        uint8
	Profile                  uint8
	Sampling_frequency_index uint8
	Private_bit              uint8
	Channel_configuration    uint8
	Originalorcopy           uint8
	Home                     uint8
}

type ADTS_Frame_Header

type ADTS_Frame_Header struct {
	Fix_Header      ADTS_Fix_Header
	Variable_Header ADTS_Variable_Header
}

func ConvertASCToADTS

func ConvertASCToADTS(asc []byte, aacbytes int) (*ADTS_Frame_Header, error)

func NewAdtsFrameHeader

func NewAdtsFrameHeader() *ADTS_Frame_Header

func (*ADTS_Frame_Header) Decode

func (frame *ADTS_Frame_Header) Decode(aac []byte)

func (*ADTS_Frame_Header) Encode

func (frame *ADTS_Frame_Header) Encode() []byte

type ADTS_Variable_Header

type ADTS_Variable_Header struct {
	Copyright_identification_bit uint8

	Frame_length                       uint16
	Adts_buffer_fullness               uint16
	Number_of_raw_data_blocks_in_frame uint8
	// contains filtered or unexported fields
}

type AudioSpecificConfiguration

type AudioSpecificConfiguration struct {
	Audio_object_type        uint8
	Sample_freq_index        uint8
	Channel_configuration    uint8
	GA_framelength_flag      uint8
	GA_depends_on_core_coder uint8
	GA_extension_flag        uint8
}

func ConvertADTSToASC

func ConvertADTSToASC(frame []byte) (*AudioSpecificConfiguration, error)

func NewAudioSpecificConfiguration

func NewAudioSpecificConfiguration() *AudioSpecificConfiguration

func (*AudioSpecificConfiguration) Decode

func (asc *AudioSpecificConfiguration) Decode(buf []byte) error

func (*AudioSpecificConfiguration) Encode

func (asc *AudioSpecificConfiguration) Encode() []byte

type BitStream

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

func NewBitStream

func NewBitStream(buf []byte) *BitStream

func (*BitStream) Bits

func (bs *BitStream) Bits() []byte

func (*BitStream) ByteOffset

func (bs *BitStream) ByteOffset() int

func (*BitStream) DistanceFromMarkDot

func (bs *BitStream) DistanceFromMarkDot() int

func (*BitStream) EOS

func (bs *BitStream) EOS() bool

func (*BitStream) GetBit

func (bs *BitStream) GetBit() uint8

func (*BitStream) GetBits

func (bs *BitStream) GetBits(n int) uint64

n <= 64

func (*BitStream) GetBytes

func (bs *BitStream) GetBytes(n int) []byte

func (*BitStream) Markdot

func (bs *BitStream) Markdot()

func (*BitStream) NextBits

func (bs *BitStream) NextBits(n int) uint64

func (*BitStream) ReadSE

func (bs *BitStream) ReadSE() int64

有符号哥伦布熵编码

func (*BitStream) ReadUE

func (bs *BitStream) ReadUE() uint64

无符号哥伦布熵编码

func (*BitStream) RemainBits

func (bs *BitStream) RemainBits() int

func (*BitStream) RemainBytes

func (bs *BitStream) RemainBytes() int

func (*BitStream) RemainData

func (bs *BitStream) RemainData() []byte

func (*BitStream) SkipBits

func (bs *BitStream) SkipBits(n int)

func (*BitStream) Uint8

func (bs *BitStream) Uint8(n int) uint8

func (*BitStream) Uint16

func (bs *BitStream) Uint16(n int) uint16

func (*BitStream) Uint32

func (bs *BitStream) Uint32(n int) uint32

func (*BitStream) UnRead

func (bs *BitStream) UnRead(n int)

type BitStreamWriter

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

func NewBitStreamWriter

func NewBitStreamWriter(n int) *BitStreamWriter

func (*BitStreamWriter) BitOffset

func (bsw *BitStreamWriter) BitOffset() int

func (*BitStreamWriter) Bits

func (bsw *BitStreamWriter) Bits() []byte

func (*BitStreamWriter) ByteOffset

func (bsw *BitStreamWriter) ByteOffset() int

func (*BitStreamWriter) DistanceFromMarkDot

func (bsw *BitStreamWriter) DistanceFromMarkDot() int

func (*BitStreamWriter) FillRemainData

func (bsw *BitStreamWriter) FillRemainData(v byte)

用v 填充剩余字节

func (*BitStreamWriter) Markdot

func (bsw *BitStreamWriter) Markdot()

func (*BitStreamWriter) PutByte

func (bsw *BitStreamWriter) PutByte(v byte)

func (*BitStreamWriter) PutBytes

func (bsw *BitStreamWriter) PutBytes(v []byte)

func (*BitStreamWriter) PutRepetValue

func (bsw *BitStreamWriter) PutRepetValue(v byte, n int)

func (*BitStreamWriter) PutUint8

func (bsw *BitStreamWriter) PutUint8(v uint8, n int)

func (*BitStreamWriter) PutUint16

func (bsw *BitStreamWriter) PutUint16(v uint16, n int)

func (*BitStreamWriter) PutUint32

func (bsw *BitStreamWriter) PutUint32(v uint32, n int)

func (*BitStreamWriter) PutUint64

func (bsw *BitStreamWriter) PutUint64(v uint64, n int)

func (*BitStreamWriter) Reset

func (bsw *BitStreamWriter) Reset()

func (*BitStreamWriter) SetByte

func (bsw *BitStreamWriter) SetByte(v byte, where int)

func (*BitStreamWriter) SetUint16

func (bsw *BitStreamWriter) SetUint16(v uint16, where int)

type ChannelMap

type ChannelMap struct {
	StreamIdx  int
	ChannelIdx int
	Silence    bool
	Copy       bool
	CopyFrom   int
}

type ChannelOrder

type ChannelOrder func(channels int, idx int) int

type CodecID

type CodecID int
const (
	CODECID_VIDEO_H264 CodecID = iota
	CODECID_VIDEO_H265
	CODECID_VIDEO_VP8

	CODECID_AUDIO_AAC CodecID = iota + 98
	CODECID_AUDIO_G711A
	CODECID_AUDIO_G711U
	CODECID_AUDIO_OPUS
	CODECID_AUDIO_MP3

	CODECID_UNRECOGNIZED = 999
)

type H264NaluHdr

type H264NaluHdr struct {
	Forbidden_zero_bit uint8
	Nal_ref_idc        uint8
	Nal_unit_type      uint8
}

func (*H264NaluHdr) Decode

func (hdr *H264NaluHdr) Decode(bs *BitStream)

type H264_NAL_TYPE

type H264_NAL_TYPE int
const (
	H264_NAL_RESERVED H264_NAL_TYPE = iota
	H264_NAL_P_SLICE
	H264_NAL_SLICE_A
	H264_NAL_SLICE_B
	H264_NAL_SLICE_C
	H264_NAL_I_SLICE
	H264_NAL_SEI
	H264_NAL_SPS
	H264_NAL_PPS
	H264_NAL_AUD
)

func H264NaluType

func H264NaluType(h264 []byte) H264_NAL_TYPE

func H264NaluTypeWithoutStartCode

func H264NaluTypeWithoutStartCode(h264 []byte) H264_NAL_TYPE

type H265NaluHdr

type H265NaluHdr struct {
	Forbidden_zero_bit    uint8
	Nal_unit_type         uint8
	Nuh_layer_id          uint8
	Nuh_temporal_id_plus1 uint8
}

func (*H265NaluHdr) Decode

func (hdr *H265NaluHdr) Decode(bs *BitStream)

type H265RawPPS

type H265RawPPS struct {
	Pps_pic_parameter_set_id                 uint64
	Pps_seq_parameter_set_id                 uint64
	Dependent_slice_segments_enabled_flag    uint8
	Output_flag_present_flag                 uint8
	Num_extra_slice_header_bits              uint8
	Sign_data_hiding_enabled_flag            uint8
	Cabac_init_present_flag                  uint8
	Num_ref_idx_l0_default_active_minus1     uint64
	Num_ref_idx_l1_default_active_minus1     uint64
	Init_qp_minus26                          int64
	Constrained_intra_pred_flag              uint8
	Transform_skip_enabled_flag              uint8
	Cu_qp_delta_enabled_flag                 uint8
	Diff_cu_qp_delta_depth                   uint64
	Pps_cb_qp_offset                         int64
	Pps_cr_qp_offset                         int64
	Pps_slice_chroma_qp_offsets_present_flag uint8
	Weighted_pred_flag                       uint8
	Weighted_bipred_flag                     uint8
	Transquant_bypass_enabled_flag           uint8
	Tiles_enabled_flag                       uint8
	Entropy_coding_sync_enabled_flag         uint8
}

func (*H265RawPPS) Decode

func (pps *H265RawPPS) Decode(nalu []byte)

nalu without startcode

type H265RawSPS

type H265RawSPS struct {
	Sps_video_parameter_set_id               uint8
	Sps_max_sub_layers_minus1                uint8
	Sps_temporal_id_nesting_flag             uint8
	Ptl                                      ProfileTierLevel
	Sps_seq_parameter_set_id                 uint64
	Chroma_format_idc                        uint64
	Pic_width_in_luma_samples                uint64
	Pic_height_in_luma_samples               uint64
	Conformance_window_flag                  uint8
	Conf_win_left_offset                     uint64
	Conf_win_right_offset                    uint64