mpeg2ts

package module
v0.0.0-...-8e04bc5 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: BSD-3-Clause Imports: 8 Imported by: 2

README

go-mpeg2-ts

(very experimental) MPEG2-TS parser in pure Go

example

see under example directory

import mpeg2ts "github.com/misodengaku/go-mpeg2-ts"

func main() {
	mpeg2, err := mpeg2ts.LoadStandardTS("test.ts")
	if err != nil {
		panic(err)
	}

	elementaryPID := uint16(0x0041)
	pesPackets := mpeg2.FilterByPIDs(elementaryPID)
	pesParser := mpeg2ts.NewPESParser(8 * 1048576)
	pesChan := pesParser.StartPESReadLoop()
	go func() {
		i := 0
		for {
			p := <-pesChan
			go func(index int, pes mpeg2ts.PES) {
				fmt.Printf("ES frame: %dbytes\n", len(p.ElementaryStream))
				fname := fmt.Sprintf("es_%04d.bin", i)
				os.WriteFile(fname, p.ElementaryStream, 0644)
			}(i, p)
			i++
		}
	}()
    
	for _, p := range pesPackets.PacketList.All() {
		eop := false
		if len(p.AdaptationField.Stuffing) > 0 {
			eop = true
		}
		err = pesParser.EnqueueTSPacket(p, eop)
		if err != nil {
			panic(err)
		}
	}
}

generate test video

$ timeout -s INT 5 gst-launch-1.0 videotestsrc ! x264enc ! progressreport ! mpegtsmux ! filesink location=test.ts
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Redistribute latency...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
progressreport0 (00:00:05): 74 seconds
handling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:04.884230197
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
$ ffprobe -hide_banner test.ts 
Input #0, mpegts, from 'test.ts':
  Duration: 00:01:27.50, start: 3600.000000, bitrate: 1576 kb/s
  Program 1 
    Stream #0:0[0x41]: Video: h264 (High 4:4:4 Predictive) (HDMV / 0x564D4448), yuv444p(tv, bt470bg/smpte170m/bt709, progressive), 320x240 [SAR 1:1 DAR 4:3], 30 fps, 30 tbr, 90k tbn, 60 tbc

Documentation

Index

Constants

View Source
const (
	ScrambleControl_NotScrambled = 0
	ScrambleControl_Userdefined1 = 1
	ScrambleControl_Userdefined2 = 2
	ScrambleControl_Userdefined3 = 3

	AdaptationField_Reserved                = 0
	AdaptationField_PayloadOnly             = 1
	AdaptationField_AdaptationFieldOnly     = 2
	AdaptationField_AdaptationFieldFollowed = 3

	// ETSI EN 300 468 V1.17.1 p.24
	TableID_ProgramAssociationSection                                        = 0x00
	TableID_ConditionalAccessSection                                         = 0x01
	TableID_ProgramMapSection                                                = 0x02
	TableID_TransportStreamDescriptionSection                                = 0x03
	TableID_NetworkInformationSection_ActualNetwork                          = 0x40
	TableID_NetworkInformationSection_OtherNetwork                           = 0x41
	TableID_ServiceDescriptionSection_ActualDVBTransportStream               = 0x42
	TableID_ServiceDescriptionSection_OtherDVBTransportStream                = 0x46
	TableID_BouquetAssociationSection                                        = 0x4A
	TableID_UpdateNotificationTableSection                                   = 0x4B
	TableID_IP_MACNotificationSection                                        = 0x4C
	TableID_EventInformationSection_ActualDVBTransportStreamPresentFollowing = 0x4E
	TableID_EventInformationSection_OtherDVBTransportStreamPresentFollowing  = 0x4F
	TableID_EventInformationSection_ActualDVBTransportStreamScheduleMin      = 0x50
	TableID_EventInformationSection_ActualDVBTransportStreamScheduleMax      = 0x5F
	TableID_EventInformationSection_OtherDVBTransportStreamScheduleMin       = 0x60
	TableID_EventInformationSection_OtherDVBTransportStreamScheduleMax       = 0x6F
	TableID_TimeDateSection                                                  = 0x70
	TableID_RunningStatusSection                                             = 0x71
	TableID_StuffingSection                                                  = 0x72
	TableID_TimeOffsetSection                                                = 0x73
	TableID_ApplicationInformationSection                                    = 0x74
	TableID_ContainerSection                                                 = 0x75
	TableID_RelatedContentSection                                            = 0x76
	TableID_ContentIdentifierSection                                         = 0x77
	TableID_MPE_FECSection                                                   = 0x78
	TableID_ResolutionProviderNotificationSection                            = 0x79
	TableID_MPE_IFECSection                                                  = 0x7A
	TableID_ProtectionMessageSection                                         = 0x7B
	TableID_DownloadableFontInfoSection                                      = 0x7C
	TableID_DiscontinuityInformationSection                                  = 0x7E
	TableID_SelectionInformationSection                                      = 0x7F
	TableID_UserDefinedMin                                                   = 0x80
	TableID_UserDefinedMax                                                   = 0xFE
)
View Source
const (
	// Rec. ITU-T H.222.0 (06/2021) pp.42-43
	StreamID_ProgramStreamMap       = 0xbc
	StreamID_PrivateStream1         = 0xbd
	StreamID_PaddingStream          = 0xbe
	StreamID_PrivateStream2         = 0xbf
	StreamID_ECM                    = 0xf0
	StreamID_EMM                    = 0xf1
	StreamID_DSMCC                  = 0xf2
	StreamID_ISO13522               = 0xf3
	StreamID_H222_1_TypeA           = 0xf4
	StreamID_H222_1_TypeB           = 0xf5
	StreamID_H222_1_TypeC           = 0xf6
	StreamID_H222_1_TypeD           = 0xf7
	StreamID_H222_1_TypeE           = 0xf8
	StreamID_AncillaryStream        = 0xf9
	StreamID_SLPacketizedStream     = 0xfa
	StreamID_FlexMuxStream          = 0xfb
	StreamID_MetadataStream         = 0xfc
	StreamID_ExtendedStreamID       = 0xfd
	StreamID_ReservedDataStream     = 0xfe
	StreamID_ProgramStreamDirectory = 0xff

	ScramblingControl_NotScrambled = 0x00
	ScramblingControl_UserDefined1 = 0x01
	ScramblingControl_UserDefined2 = 0x02
	ScramblingControl_UserDefined3 = 0x03
)
View Source
const (
	StateFindPrefix = iota
	StateParseOptPESHeader
	StateReadPacket
	StateReadBytes
	StateReadPaddingBytes
)
View Source
const (
	// based on ISO/IEC 13818-1
	PID_PAT        = PID(0x0000)
	PID_CAT        = PID(0x0001)
	PID_TSDT       = PID(0x0002)
	PID_Reserved1  = PID(0x0003)
	PID_Reserved2  = PID(0x0004)
	PID_Reserved3  = PID(0x0005)
	PID_Reserved4  = PID(0x0006)
	PID_Reserved5  = PID(0x0007)
	PID_Reserved6  = PID(0x0008)
	PID_Reserved7  = PID(0x0009)
	PID_Reserved8  = PID(0x000a)
	PID_Reserved9  = PID(0x000b)
	PID_Reserved10 = PID(0x000c)
	PID_Reserved11 = PID(0x000d)
	PID_Reserved12 = PID(0x000e)
	PID_Reserved13 = PID(0x000f)
	PID_NullPacket = PID(0x1fff)

	// based on ARIB STD-B10
	PID_PMT                            = PID_PAT
	PID_ECM                            = PID_PMT
	PID_ECM_S                          = PID_PMT
	PID_EMM                            = PID_CAT
	PID_EMM_S                          = PID_CAT
	PID_NIT                            = PID(0x0010)
	PID_SDT                            = PID(0x0011)
	PID_BAT                            = PID(0x0011)
	PID_EIT                            = PID(0x0012)
	PID_EIT_Terrestrial1               = PID(0x0012)
	PID_EIT_Terrestrial2               = PID(0x0026)
	PID_EIT_Terrestrial3               = PID(0x0027)
	PID_RST                            = PID(0x0013)
	PID_TDT_TOT                        = PID(0x0014)
	PID_DCT                            = PID(0x0017)
	PID_DLT                            = PID_DCT
	PID_DIT                            = PID(0x001e)
	PID_SIT                            = PID(0x001f)
	PID_LIT1                           = PID_PMT
	PID_LIT2                           = PID(0x0020)
	PID_ERT1                           = PID_PMT
	PID_ERT2                           = PID(0x0021)
	PID_ITT                            = PID_PMT
	PID_PCAT                           = PID(0x0022)
	PID_SDTT                           = PID(0x0023)
	PID_SDTT_Terrestrial1              = PID(0x0023)
	PID_SDTT_Terrestrial2              = PID(0x0028)
	PID_BIT                            = PID(0x0024)
	PID_NBIT                           = PID(0x0025)
	PID_LDT                            = PID(0x0025)
	PID_CDT                            = PID(0x0029)
	PID_MultipleFrameHeaderInformation = PID(0x002f)
	PID_DSM_CC                         = PID_PMT
	PID_AIT                            = PID_PMT
)
View Source
const (
	StreamTypeReserved                   = StreamType(0x00) // ITU-T | ISO/IEC Reserved
	StreamTypeISO11172_2_Video           = StreamType(0x01) // ISO/IEC 11172-2 Video
	StreamTypeISO13818_2_Video           = StreamType(0x02) // Rec. ITU-T H.262 | ISO/IEC 13818-2 Video or ISO/IEC 11172-2 constrained parameter video stream
	StreamTypeISO11172_3_Audio           = StreamType(0x03) // ISO/IEC 11172-3 Audio
	StreamTypeISO13818_3_Audio           = StreamType(0x04) // ISO/IEC 13818-3 Audio
	StreamTypeISO13818_1_PrivateSections = StreamType(0x05) // Rec. ITU-T H.222.0 | ISO/IEC 13818-1 private_sections
	StreamTypeISO13818_1_PES             = StreamType(0x06) // Rec. ITU-T H.222.0 | ISO/IEC 13818-1 PES packets containing private data
	StreamTypeISO13522_MHEG              = StreamType(0x07) // ISO/IEC 13522 MHEG
	StreamTypeISO13818_AnnexA            = StreamType(0x08) // Rec. ITU-T H.222.0 | ISO/IEC 13818-1 Annex A DSM-CC
	StreamTypeH222_1                     = StreamType(0x09) // Rec. ITU-T H.222.1
	StreamTypeISO13818_6_TypeA           = StreamType(0x0A) // ISO/IEC 13818-6 type A
	StreamTypeISO13818_6_TypeB           = StreamType(0x0B) // ISO/IEC 13818-6 type B
	StreamTypeISO13818_6_TypeC           = StreamType(0x0C) // ISO/IEC 13818-6 type C
	StreamTypeISO13818_6_TypeD           = StreamType(0x0D) // ISO/IEC 13818-6 type D
	StreamTypeISO13818_1_Aux             = StreamType(0x0E) // Rec. ITU-T H.222.0 | ISO/IEC 13818-1 auxiliary
	StreamTypeISO13818_7_AudioWithADTS   = StreamType(0x0F) // ISO/IEC 13818-7 Audio with ADTS transport syntax
	StreamTypeISO14496_2_Visual          = StreamType(0x10) // ISO/IEC 14496-2 Visual
	StreamTypeISO14496_3_AudioWithLATM   = StreamType(0x11) // ISO/IEC 14496-3 Audio with the LATM transport syntax as defined in ISO/IEC 14496-3
	StreamTypeISO14496_1_PES             = StreamType(0x12) // ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in PES packets
	StreamTypeISO14496_1_Sections        = StreamType(0x13) // ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in ISO/IEC 14496_sections
	StreamTypeISO13818_6_SDP             = StreamType(0x14) // ISO/IEC 13818-6 Synchronized Download Protocol
	StreamTypeMetadataInPES              = StreamType(0x15) // Metadata carried in PES packets
	StreamTypeMetadataInSections         = StreamType(0x16) // Metadata carried in metadata_sections
	StreamTypeMetadataInDataCarousel     = StreamType(0x17) // Metadata carried in ISO/IEC 13818-6 Data Carousel
	StreamTypeMetadataInObjectCarousel   = StreamType(0x18) // Metadata carried in ISO/IEC 13818-6 Object Carousel
	StreamTypeMetadataInSDP              = StreamType(0x19) // Metadata carried in ISO/IEC 13818-6 Synchronized Download Protocol
	StreamTypeIPMP                       = StreamType(0x1A) // IPMP stream (defined in ISO/IEC 13818-11, MPEG-2 IPMP)
	StreamTypeAVC                        = StreamType(0x1B) // AVC video stream conforming to one or more profiles defined in Annex A of Rec. ITU-T H.264 |
	StreamTypeISO14496_3_Audio           = StreamType(0x1C) // ISO/IEC 14496-3 Audio, without using any additional transport syntax, such as DST, ALS and SLS
	StreamTypeISO14496_17_Text           = StreamType(0x1D) // ISO/IEC 14496-17 Text
	StreamTypeISO23002_3_AuxVideo        = StreamType(0x1E) // Auxiliary video stream as defined in ISO/IEC 23002-3
	StreamTypeISO14496_10_SVC            = StreamType(0x1F) // SVC video sub-bitstream of an AVC video stream conforming to one or more profiles defined in Annex G of Rec. ITU-T H.264 | ISO/IEC 14496-10
	StreamTypeISO14496_10_MVC            = StreamType(0x20) // MVC video sub-bitstream of an AVC video stream conforming to one or more profiles defined in Annex H of Rec. ITU-T H.264 | ISO/IEC 14496-10
	// StreamType       = StreamType(0x21) // Video stream conforming to one or more profiles as defined in Rec. ITU-T T.800 | ISO/IEC 15444-1
	// StreamType       = StreamType(0x22) // Additional view Rec. ITU-T H.262 | ISO/IEC 13818-2 video stream for service-compatible stereoscopic 3D services (see Notes 3 and 4)
	// StreamType       = StreamType(0x23) // Additional view Rec. ITU-T H.264 | ISO/IEC 14496-10 video stream conforming to one or more profiles defined in Annex A for service-compatible stereoscopic 3D services (see Notes 3 and 4)
	// StreamType       = StreamType(0x24) // Rec. ITU-T H.265 | ISO/IEC 23008-2 video stream or an HEVC temporal video sub-bitstream
	// StreamType       = StreamType(0x25) // HEVC temporal video subset of an HEVC video stream conforming to one or more profiles defined in Annex A of Rec. ITU-T H.265 | ISO/IEC 23008-2
	// StreamType       = StreamType(0x26) // MVCD video sub-bitstream of an AVC video stream conforming to one or more profiles defined in Annex I of Rec. ITU-T H.264 | ISO/IEC 14496-10
	// StreamType       = StreamType(0x27) // Timeline and External Media Information Stream (see Annex U)
	// StreamType       = StreamType(0x28) // HEVC enhancement sub-partition which includes TemporalId 0 of an HEVC video stream where all NALs units contained in the stream conform to one or more profiles defined in Annex G of Rec. ITU-T H.265 | ISO/IEC 23008-2
	// StreamType       = StreamType(0x29) // HEVC temporal enhancement sub-partition of an HEVC video stream where all NAL units contained in the stream conform to one or more profiles defined in Annex G of Rec. ITU-T H.265 | ISO/IEC 23008-2
	// StreamType       = StreamType(0x2A) // HEVC enhancement sub-partition which includes TemporalId 0 of an HEVC video stream where all NAL units contained in the stream conform to one or more profiles defined in Annex H of Rec. ITU-T H.265 | ISO/IEC 23008-2
	// StreamType       = StreamType(0x2B) // HEVC temporal enhancement sub-partition of an HEVC video stream where all NAL units contained in the stream conform to one or more profiles defined in Annex H of Rec. ITU-T H.265 | ISO/IEC 23008-2
	// StreamType       = StreamType(0x2C) // Green access units carried in MPEG-2 sections
	// StreamType       = StreamType(0x2D) // ISO/IEC 23008-3 Audio with MHAS transport syntax – main stream
	// StreamType       = StreamType(0x2E) // ISO/IEC 23008-3 Audio with MHAS transport syntax – auxiliary stream
	// StreamType       = StreamType(0x2F) // Quality access units carried in sections
	// StreamType       = StreamType(0x30) // Media Orchestration Access Units carried in sections
	// StreamType       = StreamType(0x31) // Substream of a Rec. ITU-T H.265 | ISO/IEC 23008 2 video stream that contains a Motion Constrained Tile Set, parameter sets, slice headers or a combination thereof. See 2.17.5.1.
	// StreamType       = StreamType(0x32) // JPEG XS video stream conforming to one or more profiles as defined in ISO/IEC 21122-2
	// StreamType       = StreamType(0x33) // VVC video stream or a VVC temporal video sub-bitstream conforming to one or more profiles defined in Annex A of Rec. ITU-T H.266 | ISO/IEC 23090-3
	// StreamType       = StreamType(0x34) // VVC temporal video subset of a VVC video stream conforming to one or more profiles defined in Annex A of Rec. ITU-T H.266 | ISO/IEC 23090-3
	// StreamType       = StreamType(0x35) // EVC video stream or an EVC temporal video sub-bitstream conforming to one or more profiles defined in ISO/IEC 23094-1
	// StreamType       = StreamType(0x36) // .. 0x7E Rec. ITU-T H.222.0 | ISO/IEC 13818-1 reserved
	// StreamType       = StreamType(0x7F) // IPMP stream
	StreamTypeUserPrivateMin = StreamType(0x80)
	StreamTypeUserPrivateMax = StreamType(0xFF)
)
View Source
const PacketSizeDefault = 188
View Source
const PacketSizeWithFEC = 204

Variables

View Source
var (
	ErrAlreadyClosed          = errors.New("PESParser is already closed")
	ErrByteIncomingChanClosed = errors.New("byteIncomingChan is closed")
	ErrCanceled               = errors.New("canceled")
)
View Source
var ErrPacketIsTDT = errors.New("This packet is TDT. Use ParseTDT")

Functions

This section is empty.

Types

type AVCVideoDescriptor

type AVCVideoDescriptor struct {
	// Rec. ITU-T H.222.0 (06-2021) pp.105-106
	ProfileIDC                    uint8
	ConstraintSet0Flag            bool
	ConstraintSet1Flag            bool
	ConstraintSet2Flag            bool
	ConstraintSet3Flag            bool
	ConstraintSet4Flag            bool
	ConstraintSet5Flag            bool
	AVCCompatibleFlags            uint8
	LevelIDC                      uint8
	AVCStillPresent               bool
	AVC24HourPictureFlag          bool
	FramePackingSEINotPresentFlag bool
	Reserved                      uint8
}

type AdaptationField

type AdaptationField struct {
	Length                        byte
	DiscontinuityIndicator        bool
	RandomAccessIndicator         bool
	ESPriorityIndicator           bool
	PCRFlag                       bool
	OPCRFlag                      bool
	SplicingPointFlag             bool
	TransportPrivateDataFlag      bool
	ExtensionFlag                 bool
	ProgramClockReference         ProgramClockReference
	OriginalProgramClockReference ProgramClockReference
	SpliceCountdown               byte
	TransportPrivateData          TransportPrivateData
	ExtensionLength               byte
	Stuffing                      []byte
}

type EITDescriptor

type EITDescriptor struct {
}

type EITEvent

type EITEvent struct {
	EventID           int
	StartTime         int
	Duration          int
	RunningStatus     int
	FreeCAMode        int
	DescriptorsLength int
	Descriptors       []EITDescriptor
}

type EITTable

type EITTable struct {
	TableID                  byte
	SectionSyntaxIndicator   bool
	SectionLength            uint16
	ServiceID                uint16
	Version                  byte
	CurrentNextIndicator     bool
	SectionNumber            byte
	LastSectionNumber        byte
	SegmentLastSectionNumber byte
	TransportStreamID        byte
	OriginalNetworkID        byte
	LastTableID              byte
	CRC32                    uint
	Events                   []EITEvent
}

type ISO639LanguageDescriptor

type ISO639LanguageDescriptor struct {
	// Rec. ITU-T H.222.0 (06-2021) pp.86-87
	Languages []ISO639LanguageRelation
}

type ISO639LanguageRelation

type ISO639LanguageRelation struct {
	ISO639LanguageCode int   // 24
	AudioType          uint8 // 8
}

type MPEG2TS

type MPEG2TS struct {
	PacketList
	// contains filtered or unexported fields
}

func LoadStandardTS

func LoadStandardTS(fname string) (*MPEG2TS, error)

func LoadStandardTSWithFEC

func LoadStandardTSWithFEC(fname string) (*MPEG2TS, error)

func New

func New(chunkSize int) *MPEG2TS

func (MPEG2TS) CheckStream

func (m MPEG2TS) CheckStream() StreamCheckResult

func (*MPEG2TS) FilterByPIDs

func (m *MPEG2TS) FilterByPIDs(pids ...PID) *MPEG2TS

type MPEG4AudioDescriptor

type MPEG4AudioDescriptor struct {
	// Rec. ITU-T H.222.0 (06-2021) p.92
	AudioProfileAndLevel uint8
}

type MPEG4VideoDescriptor

type MPEG4VideoDescriptor struct {
	// Rec. ITU-T H.222.0 (06-2021) p.92
	VisualProfileAndLevel uint8
}

type PAT

type PAT struct {
	Pointer                byte
	TableID                byte
	SectionSyntaxIndicator bool
	Reserved1              byte
	SectionLength          uint16
	TransportStreamID      uint16
	Reserved2              int
	Version                byte
	CurrentNextIndicator   bool
	SectionNumber          byte
	LastSectionNumber      byte
	CRC32                  uint
	Programs               []PATProgram
}

Program Association Table

type PATProgram

type PATProgram struct {
	ProgramNumber uint16
	Reserved      int
	NetworkPID    PID
	ProgramMapPID PID
}

type PES

type PES struct {
	Prefix       uint32
	StreamID     byte
	PacketLength uint16
	ProgramClockReference

	// stream_id != program_stream_map && stream_id != padding_stream && stream_id != private_stream_2 && stream_id != ECM && stream_id != EMM && stream_id != program_stream_directory && stream_id != DSMCC_stream && stream_id != ITU-T Rec. H.222.1 type E stream
	ScramblingControl      byte
	Priority               bool
	DataAlignment          bool
	Copyright              bool
	Original               bool
	PTSFlag                bool
	DTSFlag                bool
	ESCRFlag               bool
	ESRateFlag             bool
	DSMTrickModeFlag       bool
	AdditionalCopyInfoFlag bool
	CRCFlag                bool
	ExtensionFlag          bool
	HeaderDataLength       byte

	PTS              float64
	DTS              float64
	ESCRBase         uint32
	ESCRExtension    uint16
	ESRate           uint32
	ElementaryStream []byte
	PacketDataStream []byte
	Padding          []byte
	// contains filtered or unexported fields
}

Packetized Elementary Stream Rec. ITU-T H.222.0 (06/2021) pp.39-52

func (PES) DeepCopy

func (o PES) DeepCopy() PES

DeepCopy generates a deep copy of PES

type PESByte

type PESByte struct {
	Datum         byte
	StartOfPacket bool
	EndOfStream   bool
}

type PESParser

type PESParser struct {
	PES
	// contains filtered or unexported fields
}

func NewPESParser

func NewPESParser(bufferSize int) PESParser

func (*PESParser) Close

func (pp *PESParser) Close()

func (*PESParser) EnqueueLastTSPacket

func (pp *PESParser) EnqueueLastTSPacket(tsPacket Packet) error

func (*PESParser) EnqueueTSPacket

func (pp *PESParser) EnqueueTSPacket(tsPacket Packet) error

func (*PESParser) StartPESReadLoop

func (pp *PESParser) StartPESReadLoop(ctx context.Context) <-chan PES

func (*PESParser) WriteBytes

func (pp *PESParser) WriteBytes(p []byte, sop, eos bool) (n int, err error)

type PID

type PID uint16

type PMT

type PMT struct {
	Pointer                byte
	TableID                byte
	SectionSyntaxIndicator bool
	Reserved1              byte
	SectionLength          uint16
	ProgramNumber          uint16
	Reserved2              byte
	Version                byte
	CurrentNextIndicator   bool
	SectionNumber          byte
	LastSectionNumber      byte
	Reserved3              byte
	PCR_PID                PID
	Reserved4              byte
	ProgramInfoLength      uint16
	Descriptors            []ProgramElementDescriptor
	Streams                []StreamInfo
	CRC32                  uint
}

Program Map Table Rec. ITU-T H.222.0 (06/2021) p.57

type Packet

type Packet struct {
	Index                      int
	Data                       []byte
	SyncByte                   byte
	PID                        PID
	TransportScrambleControl   byte
	AdaptationFieldControl     byte
	TransportErrorIndicator    bool
	PayloadUnitStartIndicator  bool
	TransportPriorityIndicator bool
	ContinuityCheckIndex       byte
	AdaptationField            AdaptationField
	// contains filtered or unexported fields
}

MPEG2-TS Packet

func (Packet) DeepCopy

func (o Packet) DeepCopy() Packet

DeepCopy generates a deep copy of Packet

func (*Packet) GetHeader

func (p *Packet) GetHeader() ([]byte, error)

func (*Packet) GetPayload

func (p *Packet) GetPayload() ([]byte, error)

func (*Packet) HasAdaptationField

func (p *Packet) HasAdaptationField() bool

func (*Packet) ParsePAT

func (p *Packet) ParsePAT() (PAT, error)

func (*Packet) ParsePMT

func (p *Packet) ParsePMT(disableCRCcheck bool) (PMT, error)

func (*Packet) ParseTDT

func (p *Packet) ParseTDT(acceptTOT bool) (TDT, error)

func (*Packet) ParseTOT

func (p *Packet) ParseTOT() (TOT, error)

type PacketList

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

func NewPacketList

func NewPacketList(chunkSize int) (PacketList, error)

func (*PacketList) AddBytes

func (ps *PacketList) AddBytes(packetBytes []byte, packetSize int) error

func (*PacketList) AddPacket

func (ps *PacketList) AddPacket(p Packet)

func (*PacketList) All

func (ps *PacketList) All() []Packet

func (*PacketList) DequeuePacket

func (ps *PacketList) DequeuePacket() (Packet, error)

type ProgramClockReference

type ProgramClockReference struct {
	Base      uint64
	Extension uint16
}

type RegistrationDescriptor

type RegistrationDescriptor struct {
	// Rec. ITU-T H.222.0 (06-2021) pp.81-82
	FormatIdentifier             []byte
	AdditionalIdentificationInfo []byte
}

type StreamCheckResult

type StreamCheckResult struct {
	DropCount int
	DropList  []struct {
		Description string
		Index       int
	}
}

type StreamInfo

type StreamInfo struct {
	Type          StreamType
	Reserved1     byte
	ElementaryPID PID
	Reserved2     byte
	ESInfoLength  uint16
	Descriptors   []ProgramElementDescriptor
}

func (*StreamInfo) IsUserPrivateStream

func (s *StreamInfo) IsUserPrivateStream() bool

type StreamType

type StreamType byte

type TDT

type TDT struct {
	TableID                byte   // 8
	SectionSyntaxIndicator byte   // 1
	ReservedFutureUse      byte   // 1
	Reserved1              byte   // 2
	SectionLength          uint16 // 12
	RAWTimestamp           uint64 // 40

	Timestamp time.Time
}

ETSI EN 300 468 V1.17.1 p.34

type TOT

type TOT struct {
	TDT
	Reserved2         byte   // 4
	DescriptorsLength uint16 // 12
	Descriptors       []struct{}
	CRC32             uint //32

	Timestamp time.Time
}

ETSI EN 300 468 V1.17.1 p.35

type TransportPrivateData

type TransportPrivateData struct {
	Length byte
	Data   []byte
}

type TransportStreamEngine

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

func InitTSEngine

func InitTSEngine(chunkSize, bufferSize int) (TransportStreamEngine, error)

func (*TransportStreamEngine) StartPacketReadLoop

func (tse *TransportStreamEngine) StartPacketReadLoop(ctx context.Context) <-chan Packet

func (*TransportStreamEngine) Write

func (tse *TransportStreamEngine) Write(p []byte) (n int, err error)

type UserPrivateDescriptor

type UserPrivateDescriptor struct {
	Data []byte
}

type VideoStreamDescriptor

type VideoStreamDescriptor struct {
	MultipleFrameRateFlag    bool
	FrameRateCode            uint8
	MPEG1OnlyFlag            bool
	ConstrainedParameterFlag bool
	StillPictureFlag         bool

	// MPEG1 Only
	ProfileAndLevelIndication uint8
	ChromaFormat              uint8
	FrameRateExtensionFlag    bool
	Reserved                  uint8
}

Directories

Path Synopsis
example
tsh264parse Module

Jump to

Keyboard shortcuts

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