mpegts

package
v0.37.4 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

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

	// AdaptationFieldControlReserved ------------------------------------------
	// <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-29 Stream type assignments> <page 66/174>
	// 0x0F AAC  (ISO/IEC 13818-7 Audio with ADTS transport syntax)
	// 0x1B AVC  (video stream as defined in ITU-T Rec. H.264 | ISO/IEC 14496-10 Video)
	// 0x24 HEVC (HEVC video stream as defined in Rec. ITU-T H.265 | ISO/IEC 23008-2  MPEG-H Part 2)
	// -----------------------------------------------------------------------------
	StreamTypeUnknown uint8 = 0x00
	StreamTypePrivate uint8 = 0x06
	StreamTypeAac     uint8 = 0x0F
	StreamTypeAvc     uint8 = 0x1B
	StreamTypeHevc    uint8 = 0x24
)

PMT

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

	// PtsDtsFlags0 ------------------------------
	// <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

View Source
const (
	TsPsiIdPas            = 0x00 // program_association_section
	TsPsiIdCas            = 0x01 // conditional_access_section (CA_section)
	TsPsiIdPms            = 0x02 // TS_program_map_section
	TsPsiIdDs             = 0x03 // TS_description_section
	TsPsiIdSds            = 0x04 // ISO_IEC_14496_scene_description_section
	TsPsiIdOds            = 0x05 // ISO_IEC_14496_object_descriptor_section
	TsPsiIdIso138181Start = 0x06 // ITU-T Rec. H.222.0 | ISO/IEC 13818-1 reserved
	TsPsiIdIso138181End   = 0x37
	TsPsiIdIso138186Start = 0x38 // Defined in ISO/IEC 13818-6
	TsPsiIdIso138186End   = 0x3F
	TsPsiIdUserStart      = 0x40 // User private
	TsPsiIdUserEnd        = 0xFE
	TsPsiIdForbidden      = 0xFF // forbidden
)

PsiId

View Source
const (
	DescriptorTagAC3                        = 0x6a
	DescriptorTagAVCVideo                   = 0x28
	DescriptorTagComponent                  = 0x50
	DescriptorTagContent                    = 0x54
	DescriptorTagDataStreamAlignment        = 0x6
	DescriptorTagEnhancedAC3                = 0x7a
	DescriptorTagExtendedEvent              = 0x4e
	DescriptorTagExtension                  = 0x7f
	DescriptorTagISO639LanguageAndAudioType = 0xa
	DescriptorTagLocalTimeOffset            = 0x58
	DescriptorTagMaximumBitrate             = 0xe
	DescriptorTagNetworkName                = 0x40
	DescriptorTagParentalRating             = 0x55
	DescriptorTagPrivateDataIndicator       = 0xf
	DescriptorTagPrivateDataSpecifier       = 0x5f
	DescriptorTagRegistration               = 0x5
	DescriptorTagService                    = 0x48
	DescriptorTagShortEvent                 = 0x4d
	DescriptorTagStreamIdentifier           = 0x52
	DescriptorTagSubtitling                 = 0x59
	DescriptorTagTeletext                   = 0x56
	DescriptorTagVBIData                    = 0x45
	DescriptorTagVBITeletext                = 0x46
)

Variables

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

FixedFragmentHeader 每个TS文件都以固定的PAT,PMT开始 TODO(chef): [refactor] 考虑去掉这个fixed变量,目前只在测试中使用 [202303]

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

FixedFragmentHeaderHevc 每个TS文件都以固定的PAT,PMT开始 TODO(chef): [refactor] 考虑去掉这个fixed变量,目前只在测试中使用 [202303]

Functions

func CalcCrc32 added in v0.35.4

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

func PackPat added in v0.35.4

func PackPat() []byte

func PackPmt added in v0.35.4

func PackPmt(videoCodecId, audioCodecId int) []byte

Types

type Descriptor added in v0.37.4

type Descriptor struct {
	Length       uint8
	Tag          uint8
	Registration DescriptorRegistration
	Extension    DescriptorExtension
}

type DescriptorExtension added in v0.37.4

type DescriptorExtension struct {
	SupplementaryAudio DescriptorExtensionSupplementaryAudio
	Tag                uint8
	Unknown            []byte
}

type DescriptorExtensionSupplementaryAudio added in v0.37.4

type DescriptorExtensionSupplementaryAudio struct {
	EditorialClassification uint8
	HasLanguageCode         bool
	LanguageCode            []byte
	MixType                 bool
	PrivateData             []byte
}

type DescriptorRegistration added in v0.37.4

type DescriptorRegistration struct {
	AdditionalIdentificationInfo []byte
	FormatIdentifier             uint32
}

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)
	Cts uint32
	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
}

Frame 帧数据,用于打包成mpegts格式的数据

func (*Frame) DebugString added in v0.31.0

func (frame *Frame) DebugString() string

func (*Frame) Pack added in v0.28.0

func (frame *Frame) Pack() []byte

Pack annexb格式的流转换为mpegts流

注意,内部会增加 Frame.Cc 的值.

@return: 内存块为独立申请,调度结束后,内部不再持有

type Pat added in v0.23.0

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

Pat --------------------------------------------------------------------------------------------------- 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 PatSpecificData added in v0.35.4

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

type Pes added in v0.23.0

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

Pes ----------------------------------------------------------- <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
}

Pmt

---------------------------------------- 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
	Descriptors []Descriptor
}

type PmtSpecificData added in v0.35.4

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

type PsiSection added in v0.35.4

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

func NewPsi added in v0.35.4

func NewPsi() *PsiSection

func (*PsiSection) Pack added in v0.35.4

func (psi *PsiSection) Pack() (int, []byte)

type PsiSectionData added in v0.35.4

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

type PsiTableHeader added in v0.35.4

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

type PsiTableSyntaxSection added in v0.35.4

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

type TsPacketAdaptation added in v0.23.0

type TsPacketAdaptation struct {
	Length uint8
}

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

ParseTsPacketAdaptation 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
}

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

ParseTsPacketHeader 解析4字节TS Packet header

Jump to

Keyboard shortcuts

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