mpegps

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodecUnknown = iota
	CodecH264
	CodecH265
	CodecH266
	CodecMpeg4
)

Variables

View Source
var BitMask [8]byte = [8]byte{0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF}
View Source
var H264AudNalu []byte = []byte{0x00, 0x00, 0x00, 0x01, 0x09, 0xF0} //ffmpeg mpegtsenc.c mpegts_write_packet_internal
View Source
var H265AudNalu []byte = []byte{0x00, 0x00, 0x00, 0x01, 0x46, 0x01, 0x50}

Functions

func CalcCrc32

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

func H264NaluType

func H264NaluType(h264 []byte) uint8

func H265NaluType

func H265NaluType(h265 []byte) uint8

func SplitFrame

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

Types

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) Uint16

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

func (*BitStream) Uint32

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

func (*BitStream) Uint8

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

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) 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) PutUint8

func (bsw *BitStreamWriter) PutUint8(v uint8, 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 CommonPesPacket

type CommonPesPacket struct {
	StreamId        uint8
	PesPacketLength uint16
}

func (*CommonPesPacket) Decode

func (compes *CommonPesPacket) Decode(bs *BitStream) error

type Display

type Display interface {
	PrettyPrint(file *os.File)
}

type ElementaryStream added in v0.3.3

type ElementaryStream struct {
	StreamId             uint8
	PStdBufferBoundScale uint8
	PStdBufferSizeBound  uint16
}

func NewElementaryStream added in v0.3.3

func NewElementaryStream(sid uint8) *ElementaryStream

type ElementaryStreamElem added in v0.3.3

type ElementaryStreamElem struct {
	StreamType                 uint8
	ElementaryStreamId         uint8
	ElementaryStreamInfoLength uint16
}

func NewElementaryStreamElem added in v0.3.3

func NewElementaryStreamElem(stype uint8, esid uint8) *ElementaryStreamElem

type Error

type Error interface {
	NeedMore() bool
	ParserError() bool
	StreamIdNotFound() bool
}

type PesPacket

type PesPacket struct {
	StreamId               uint8
	PesPacketLength        uint16
	PesScramblingControl   uint8
	PesPriority            uint8
	DataAlignmentIndicator uint8
	Copyright              uint8
	OriginalOrCopy         uint8
	PtsDtsFlags            uint8
	EscrFlag               uint8
	EsRateFlag             uint8
	DsmTrickModeFlag       uint8
	AdditionalCopyInfoFlag uint8
	PesCrcFlag             uint8
	PesExtensionFlag       uint8
	PesHeaderDataLength    uint8
	Pts                    uint64
	Dts                    uint64
	EscrBase               uint64
	EscrExtension          uint16
	EsRate                 uint32
	TrickModeControl       uint8
	TrickValue             uint8
	AdditionalCopyInfo     uint8
	PreviousPesPacketCrc   uint16
	PesPayload             []byte
}

func NewPesPacket

func NewPesPacket() *PesPacket

func (*PesPacket) Decode

func (pkg *PesPacket) Decode(bs *BitStream) error

func (*PesPacket) DecodeMpeg1

func (pkg *PesPacket) DecodeMpeg1(bs *BitStream) error

func (*PesPacket) Encode

func (pkg *PesPacket) Encode(bsw *BitStreamWriter)

func (*PesPacket) PrettyPrint

func (pkg *PesPacket) PrettyPrint(file *os.File)

type PesStreamId added in v0.3.3

type PesStreamId int
const (
	PesStreamEnd        PesStreamId = 0xB9
	PesStreamStart      PesStreamId = 0xBA
	PesStreamSystemHead PesStreamId = 0xBB
	PesStreamMap        PesStreamId = 0xBC
	PesStreamPrivate    PesStreamId = 0xBD
	PesStreamAudio      PesStreamId = 0xC0
	PesStreamVideo      PesStreamId = 0xE0
)

type ProgramStreamDirectory added in v0.3.3

type ProgramStreamDirectory struct {
	PesPacketLength uint16
}

func (*ProgramStreamDirectory) Decode added in v0.3.3

func (psd *ProgramStreamDirectory) Decode(bs *BitStream) error

type ProgramStreamMap added in v0.3.3

type ProgramStreamMap struct {
	MapStreamId               uint8
	ProgramStreamMapLength    uint16
	CurrentNextIndicator      uint8
	ProgramStreamMapVersion   uint8
	ProgramStreamInfoLength   uint16
	ElementaryStreamMapLength uint16
	StreamMap                 []*ElementaryStreamElem
}

func (*ProgramStreamMap) Decode added in v0.3.3

func (psm *ProgramStreamMap) Decode(bs *BitStream) error

func (*ProgramStreamMap) Encode added in v0.3.3

func (psm *ProgramStreamMap) Encode(bsw *BitStreamWriter)

func (*ProgramStreamMap) PrettyPrint added in v0.3.3

func (psm *ProgramStreamMap) PrettyPrint(file *os.File)

type PsDemuxer added in v0.3.3

type PsDemuxer struct {
	OnFrame func(frame []byte, cid PsStreamType, pts uint64, dts uint64)
	//解ps包过程中,解码回调psm,system header,pes包等
	//decodeResult 解码ps包时的产生的错误
	//这个回调主要用于debug,查看是否ps包存在问题
	OnPacket func(pkg Display, decodeResult error)
	// contains filtered or unexported fields
}

func NewPsDemuxer added in v0.3.3

func NewPsDemuxer() *PsDemuxer

func (*PsDemuxer) Flush added in v0.3.3

func (psDemuxer *PsDemuxer) Flush()

func (*PsDemuxer) Input added in v0.3.3

func (psDemuxer *PsDemuxer) Input(data []byte) error

type PsMuxer added in v0.3.3

type PsMuxer struct {
	OnPacket func(pkg []byte, pts uint64)
	// contains filtered or unexported fields
}

func NewPsMuxer

func NewPsMuxer() *PsMuxer

func (*PsMuxer) AddStream added in v0.3.3

func (muxer *PsMuxer) AddStream(cid PsStreamType) uint8

func (*PsMuxer) Write added in v0.3.3

func (muxer *PsMuxer) Write(sid uint8, frame []byte, pts uint64, dts uint64) error

type PsPackHeader added in v0.3.3

type PsPackHeader struct {
	IsMpeg1                       bool
	SystemClockReferenceBase      uint64 //33 bits
	SystemClockReferenceExtension uint16 //9 bits
	ProgramMuxRate                uint32 //22 bits
	PackStuffingLength            uint8  //3 bitss
}

func (*PsPackHeader) Decode added in v0.3.3

func (psPackHeader *PsPackHeader) Decode(bs *BitStream) error

func (*PsPackHeader) Encode added in v0.3.3

func (psPackHeader *PsPackHeader) Encode(bsw *BitStreamWriter)

func (*PsPackHeader) PrettyPrint added in v0.3.3

func (psPackHeader *PsPackHeader) PrettyPrint(file *os.File)

type PsPacket added in v0.3.3

type PsPacket struct {
	Header  *PsPackHeader
	System  *SystemHeader
	Psm     *ProgramStreamMap
	Psd     *ProgramStreamDirectory
	CommPes *CommonPesPacket
	Pes     *PesPacket
}

type PsStreamType added in v0.3.3

type PsStreamType int
const (
	PsStreamUnknow PsStreamType = 0xFF
	PsStreamAac    PsStreamType = 0x0F
	PsStreamH264   PsStreamType = 0x1B
	PsStreamH265   PsStreamType = 0x24
	PsStreamG711A  PsStreamType = 0x90
	PsStreamG711U  PsStreamType = 0x91
)

type StartCodeType added in v0.3.3

type StartCodeType int
const (
	StartCode3 StartCodeType = 3
	STartCode4 StartCodeType = 4
)

func FindStartCode

func FindStartCode(nalu []byte, offset int) (int, StartCodeType)

type SystemHeader added in v0.3.3

type SystemHeader struct {
	HeaderLength              uint16
	RateBound                 uint32
	AudioBound                uint8
	FixedFlag                 uint8
	CspsFlag                  uint8
	SystemAudioLockFlag       uint8
	SystemVideoLockFlag       uint8
	VideoBound                uint8
	PacketRateRestrictionFlag uint8
	Streams                   []*ElementaryStream
}

func (*SystemHeader) Decode added in v0.3.3

func (sh *SystemHeader) Decode(bs *BitStream) error

func (*SystemHeader) Encode added in v0.3.3

func (sh *SystemHeader) Encode(bsw *BitStreamWriter)

func (*SystemHeader) PrettyPrint added in v0.3.3

func (sh *SystemHeader) PrettyPrint(file *os.File)

type TsStreamType added in v0.3.3

type TsStreamType int
const (
	TsStreamAudioMpeg1 TsStreamType = 0x03
	TsStreamAudioMpeg2 TsStreamType = 0x04
	TsStreamAac        TsStreamType = 0x0F
	TsStreamH264       TsStreamType = 0x1B
	TsStreamH265       TsStreamType = 0x24
)

Jump to

Keyboard shortcuts

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