mpegts

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PidPat   uint16 = 0
	PidVideo uint16 = 0x100
	PidAudio uint16 = 0x101

	// ------------------------------------------
	// <iso13818-1.pdf> <Table 2-5> <page 38/174>
	// ------------------------------------------
	AdaptationFieldControlReserved uint8 = 0 // Reserved for future use by ISO/IEC
	AdaptationFieldControlNo       uint8 = 1 // No adaptation_field, payload only
	AdaptationFieldControlOnly     uint8 = 2 // Adaptation_field only, no payload
	AdaptationFieldControlFollowed uint8 = 3 // Adaptation_field followed by payload
)

TS Packet Header

View Source
const (
	// -----------------------------------------------------------------
	// <iso13818-1.pdf> <Table 2-18-Stream_id assignments> <page 52/174>
	// -----------------------------------------------------------------
	StreamIdAudio uint8 = 192 // 110x xxxx 0xC0
	StreamIdVideo uint8 = 224 // 1110 xxxx

	// ------------------------------
	// <iso13818-1.pdf> <page 53/174>
	// ------------------------------
	PtsDtsFlags0 uint8 = 0 // no PTS no DTS
	PtsDtsFlags1 uint8 = 1 // forbidden
	PtsDtsFlags2 uint8 = 2 // only PTS
	PtsDtsFlags3 uint8 = 3 // both PTS and DTS
)

PES

Variables

View Source
var ErrMpegts = errors.New("lal.mpegts: fxxk")
View Source
var FixedFragmentHeader = []byte{}/* 376 elements not displayed */

每个TS文件都以固定的PAT,PMT开始

View Source
var FixedFragmentHeaderHevc = []byte{}/* 376 elements not displayed */

每个TS文件都以固定的PAT,PMT开始

Functions

func PackTsPacket added in v0.23.0

func PackTsPacket(frame *Frame, onTsPacket OnTsPacket)

Annexb格式的流转换为mpegts packet

@param frame: 各字段含义见mpegts.Frame结构体定义

frame.CC  注意,内部会修改frame.CC的值,外部在调用结束后,可保存CC的值,供下次调用时使用
frame.Raw 函数调用结束后,内部不会持有该内存块

@param onTsPacket: 注意,一次函数调用,可能对应多次回调

Types

type FileWriter added in v0.22.0

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

func (*FileWriter) Create added in v0.22.0

func (fw *FileWriter) Create(filename string) (err error)

func (*FileWriter) Dispose added in v0.22.0

func (fw *FileWriter) Dispose() error

func (*FileWriter) Name added in v0.22.0

func (fw *FileWriter) Name() string

func (*FileWriter) Write added in v0.22.0

func (fw *FileWriter) Write(b []byte) (err error)

type Frame

type Frame struct {
	Pts uint64 // =(毫秒 * 90)
	Dts uint64
	Cc  uint8 // continuity_counter of TS Header

	// PID of PES Header
	// 音频 mpegts.PidAudio
	// 视频 mpegts.PidVideo
	Pid uint16

	// stream_id of PES Header
	// 音频 mpegts.StreamIdAudio
	// 视频 mpegts.StreamIdVideo
	Sid uint8

	// 音频 全部为false
	// 视频 关键帧为true,非关键帧为false
	Key bool

	// 音频AAC 格式为2字节ADTS头加raw frame
	// 视频AVC 格式为Annexb
	Raw []byte
}

type OnTsPacket added in v0.23.0

type OnTsPacket func(packet []byte)

@param packet: 188字节大小的TS包,注意,一次Pack对应的多个TSPacket,复用的是一块内存

type Pat added in v0.23.0

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

--------------------------------------------------------------------------------------------------- Program association section <iso13818-1.pdf> <2.4.4.3> <page 61/174> table_id [8b] * section_syntax_indicator [1b] '0' [1b] reserved [2b] section_length [12b] ** transport_stream_id [16b] ** reserved [2b] version_number [5b] current_next_indicator [1b] * section_number [8b] * last_section_number [8b] * -----loop----- program_number [16b] ** reserved [3b] program_map_PID [13b] ** if program_number == 0 then network_PID else then program_map_PID -------------- CRC_32 [32b] **** ---------------------------------------------------------------------------------------------------

func ParsePat added in v0.23.0

func ParsePat(b []byte) (pat Pat)

func (*Pat) SearchPid added in v0.23.0

func (pat *Pat) SearchPid(pid uint16) bool

type PatProgramElement added in v0.23.0

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

type Pes added in v0.23.0

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

----------------------------------------------------------- <iso13818-1.pdf> <2.4.3.6 PES packet> <page 49/174> <Table E.1 - PES packet header example> <page 142/174> <F.0.2 PES packet> <page 144/174> packet_start_code_prefix [24b] *** always 0x00, 0x00, 0x01 stream_id [8b] * PES_packet_length [16b] ** '10' [2b] PES_scrambling_control [2b] PES_priority [1b] data_alignment_indicator [1b] copyright [1b] original_or_copy [1b] * PTS_DTS_flags [2b] ESCR_flag [1b] ES_rate_flag [1b] DSM_trick_mode_flag [1b] additional_copy_info_flag [1b] PES_CRC_flag [1b] PES_extension_flag [1b] * PES_header_data_length [8b] * -----------------------------------------------------------

func ParsePes added in v0.23.0

func ParsePes(b []byte) (pes Pes, length int)

type Pmt added in v0.23.0

type Pmt struct {
	ProgramElements []PmtProgramElement
	// contains filtered or unexported fields
}

---------------------------------------- Program Map Table <iso13818-1.pdf> <2.4.4.8> <page 64/174> table_id [8b] * section_syntax_indicator [1b] 0 [1b] reserved [2b] section_length [12b] ** program_number [16b] ** reserved [2b] version_number [5b] current_next_indicator [1b] * section_number [8b] * last_section_number [8b] * reserved [3b] PCR_PID [13b] ** reserved [4b] program_info_length [12b] ** -----loop----- stream_type [8b] * reserved [3b] elementary_PID [13b] ** reserved [4b] ES_info_length_length [12b] ** -------------- CRC32 [32b] **** ----------------------------------------

func ParsePmt added in v0.23.0

func ParsePmt(b []byte) (pmt Pmt)

func (*Pmt) SearchPid added in v0.23.0

func (pmt *Pmt) SearchPid(pid uint16) *PmtProgramElement

type PmtProgramElement added in v0.23.0

type PmtProgramElement struct {
	StreamType uint8
	Pid        uint16
	Length     uint16
}

type TsPacketAdaptation added in v0.23.0

type TsPacketAdaptation struct {
	Length uint8
}

---------------------------------------------------------- <iso13818-1.pdf> <Table 2-6> <page 40/174> adaptation_field_length [8b] * 不包括自己这1字节 discontinuity_indicator [1b] random_access_indicator [1b] elementary_stream_priority_indicator [1b] PCR_flag [1b] OPCR_flag [1b] splicing_point_flag [1b] transport_private_data_flag [1b] adaptation_field_extension_flag [1b] * -----if PCR_flag == 1----- program_clock_reference_base [33b] reserved [6b] program_clock_reference_extension [9b] ****** ----------------------------------------------------------

func ParseTsPacketAdaptation added in v0.23.0

func ParseTsPacketAdaptation(b []byte) (f TsPacketAdaptation)

TODO chef

type TsPacketHeader added in v0.23.0

type TsPacketHeader struct {
	Sync             uint8
	Err              uint8
	PayloadUnitStart uint8
	Prio             uint8
	Pid              uint16
	Scra             uint8
	Adaptation       uint8
	Cc               uint8
}

------------------------------------------------ <iso13818-1.pdf> <2.4.3.2> <page 36/174> sync_byte [8b] * always 0x47 transport_error_indicator [1b] payload_unit_start_indicator [1b] transport_priority [1b] PID [13b] ** transport_scrambling_control [2b] adaptation_field_control [2b] continuity_counter [4b] * ------------------------------------------------

func ParseTsPacketHeader added in v0.23.0

func ParseTsPacketHeader(b []byte) (h TsPacketHeader)

解析4字节TS Packet header

Jump to

Keyboard shortcuts

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