Documentation ¶
Index ¶
Constants ¶
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
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 ¶
var FixedFragmentHeader = []byte{}/* 376 elements not displayed */
每个TS文件都以固定的PAT,PMT开始
Functions ¶
func PackTSPacket ¶
func PackTSPacket(frame *Frame, onTSPacket OnTSPacket)
@param frame: 各字段含义见mpegts.Frame结构体定义
frame.CC 注意,内部会修改frame.CC的值,外部在调用结束后,可保存CC的值,供下次调用时使用 frame.Raw 函数调用结束后,内部不会持有该内存块
@param onTSPacket: 注意,一次函数调用,可能对应多次回调
Types ¶
type Frame ¶
type Frame struct { PTS uint64 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 ¶
type OnTSPacket func(packet []byte)
@param packet: 188字节大小的TS包,注意,一次Pack对应的多个TSPacket,复用的是一块内存
type PAT ¶
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] **** ---------------------------------------------------------------------------------------------------
type PATProgramElement ¶
type PATProgramElement struct {
// contains filtered or unexported fields
}
type PES ¶
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] * -----------------------------------------------------------
type PMT ¶
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 (*PMT) SearchPID ¶
func (pmt *PMT) SearchPID(pid uint16) *PMTProgramElement
type PMTProgramElement ¶
type TSPacketAdaptation ¶
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 ¶
func ParseTSPacketAdaptation(b []byte) (f TSPacketAdaptation)
TODO chef
type TSPacketHeader ¶
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 ¶
func ParseTSPacketHeader(b []byte) (h TSPacketHeader)
解析4字节TS Packet header