Categorygithub.com/up-stream/go-astits
modulepackage
0.0.0-20180225134227-3bec246caf60
Repository: https://github.com/up-stream/go-astits.git
Documentation: pkg.go.dev

# README

GoReportCard GoDoc Travis Coveralls

This is a Golang library to natively parse and demux MPEG Transport Streams (ts) in GO.

WARNING: this library is not yet production ready. For instance, while parsing a slice of bytes, it doesn't check whether the length of the slice is sufficient and rather panic on purpose. Use at your own risks!

Installation

To install the library use the following:

go get -u github.com/asticode/go-astits/...

Before looking at the code...

The transport stream is made of packets.
Each packet has a header, an optional adaptation field and a payload.
Several payloads can be appended and parsed as a data.

                                           TRANSPORT STREAM
 +--------------------------------------------------------------------------------------------------+
 |                                                                                                  |
 
                       PACKET                                         PACKET
 +----------------------------------------------+----------------------------------------------+----
 |                                              |                                              |
 
 +--------+---------------------------+---------+--------+---------------------------+---------+
 | HEADER | OPTIONAL ADAPTATION FIELD | PAYLOAD | HEADER | OPTIONAL ADAPTATION FIELD | PAYLOAD | ...
 +--------+---------------------------+---------+--------+---------------------------+---------+
 
                                      |         |                                    |         |
                                      +---------+                                    +---------+
                                           |                                              |
                                           +----------------------------------------------+
                                                                DATA

Using the library in your code

WARNING: the code below doesn't handle errors for readability purposes. However you SHOULD!

// Create a cancellable context in case you want to stop reading packets/data any time you want
ctx, cancel := context.WithCancel(context.Background())

// Handle SIGTERM signal
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM)
go func() {
    <-ch
    cancel()
}()

// Open your file or initialize any kind of io.Reader
f, _ := os.Open("/path/to/file.ts")
defer f.Close()

// Create the demuxer
dmx := astits.New(ctx, f)
for {
    // Get the next data
    d, _ := dmx.NextData()
    
    // Data is a PMT data
    if d.PMT != nil {
        // Loop through elementary streams
        for _, es := range d.PMT.ElementaryStreams {
                fmt.Printf("Stream detected: %d\n", es.ElementaryPID)
        }
        return
    }
}

Options

In order to pass options to the demuxer, look for the methods prefixed with Opt and add them upon calling New:

// This is your custom packets parser
p := func(ps []*astits.Packet) (ds []*astits.Data, skip bool, err error) {
        // This is your logic
        skip = true
        return
}

// Now you can create a demuxer with the proper options
dmx := New(ctx, f, OptPacketSize(192), OptPacketsParser(p))

CLI

This library provides a CLI that will automatically get installed in GOPATH/bin on go get execution.

List streams

$ astits -i <path to your file> -f <format: text|json (default: text)>

List data

$ astits data -i <path to your file> -d <data type: eit|nit|... (repeatable argument | if empty, all data types are shown)>

Features and roadmap

  • Parse PES packets
  • Parse PAT packets
  • Parse PMT packets
  • Parse EIT packets
  • Parse NIT packets
  • Parse SDT packets
  • Parse TOT packets
  • Parse BAT packets
  • Parse DIT packets
  • Parse RST packets
  • Parse SIT packets
  • Parse ST packets
  • Parse TDT packets
  • Parse TSDT packets

# Packages

No description provided by the author

# Functions

New creates a new transport stream based on a reader.
OptPacketSize returns the option to set the packet size.
OptPacketsParser returns the option to set the packets parser.

# Constants

Audio types Page: 683 | https://books.google.fr/books?id=6dgWB3-rChYC&printsec=frontcover&hl=fr.
Audio types Page: 683 | https://books.google.fr/books?id=6dgWB3-rChYC&printsec=frontcover&hl=fr.
Audio types Page: 683 | https://books.google.fr/books?id=6dgWB3-rChYC&printsec=frontcover&hl=fr.
Data stream alignments Page: 85 | Chapter:2.6.11 | Link: http://ecee.colorado.edu/~ecen5653/ecen5653/papers/iso13818-1.pdf.
Data stream alignments Page: 85 | Chapter:2.6.11 | Link: http://ecee.colorado.edu/~ecen5653/ecen5653/papers/iso13818-1.pdf.
Data stream alignments Page: 85 | Chapter:2.6.11 | Link: http://ecee.colorado.edu/~ecen5653/ecen5653/papers/iso13818-1.pdf.
Data stream alignments Page: 85 | Chapter:2.6.11 | Link: http://ecee.colorado.edu/~ecen5653/ecen5653/papers/iso13818-1.pdf.
Data stream alignments Page: 85 | Chapter:2.6.11 | Link: http://ecee.colorado.edu/~ecen5653/ecen5653/papers/iso13818-1.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor extension tags Page: 111 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Descriptor tags Page: 42 | Chapter: 6.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Conditional Access Table (CAT) contains a directory listing of all ITU-T Rec.
Null Packet (used for fixed bandwidth padding).
Program Association Table (PAT) contains a directory listing of all Program Map Tables.
Transport Stream Description Table (TSDT) contains descriptors related to the overall transport stream.
PSI table IDs.
PSI table IDs.
PSI table IDs.
PSI table IDs.
PSI table IDs.
PSI table IDs.
PSI table IDs.
PSI table IDs.
PSI table IDs.
PSI table IDs.
PSI table IDs.
PSI table IDs.
PSI table IDs.
PSI table IDs.
P-STD buffer scales.
P-STD buffer scales.
PTS DTS indicator.
PTS DTS indicator.
PTS DTS indicator.
PTS DTS indicator.
Running statuses.
Running statuses.
Running statuses.
Running statuses.
Running statuses.
Running statuses.
Scrambling Controls.
Scrambling Controls.
Scrambling Controls.
Scrambling Controls.
Service types Page: 97 | Chapter: 6.2.33 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf / page 97.
Stream IDs.
Stream IDs.
Stream IDs.
ITU-T Rec.
ISO/IEC 11172-3.
ISO/IEC 13818-3.
ITU-T Rec.
Teletext types Page: 106 | Chapter: 6.2.43 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Teletext types Page: 106 | Chapter: 6.2.43 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Teletext types Page: 106 | Chapter: 6.2.43 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Teletext types Page: 106 | Chapter: 6.2.43 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Teletext types Page: 106 | Chapter: 6.2.43 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
Trick mode controls.
Trick mode controls.
Trick mode controls.
Trick mode controls.
Trick mode controls.
VBI data service id Page: 109 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
VBI data service id Page: 109 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
VBI data service id Page: 109 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
VBI data service id Page: 109 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
VBI data service id Page: 109 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
VBI data service id Page: 109 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.

# Variables

# Structs

ClockReference represents a clock reference Base is based on a 90 kHz clock and extension is based on a 27 MHz clock.
Data represents a data.
Demuxer represents a demuxer https://en.wikipedia.org/wiki/MPEG_transport_stream http://seidl.cs.vsb.cz/download/dvb/DVB_Poster.pdf http://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.13.01_40/en_300468v011301o.pdf.
Descriptor represents a descriptor TODO Handle UTF8.
DescriptorAC3 represents an AC3 descriptor Page: 165 | https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorAVCVideo represents an AVC video descriptor No doc found unfortunately, basing the implementation on https://github.com/gfto/bitstream/blob/master/mpeg/psi/desc_28.h.
DescriptorComponent represents a component descriptor Page: 51 | https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorContent represents a content descriptor Page: 58 | https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorContentItem represents a content item descriptor Check page 59 of https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf for content nibble levels associations.
DescriptorDataStreamAlignment represents a data stream alignment descriptor.
DescriptorEnhancedAC3 represents an enhanced AC3 descriptor Page: 166 | https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorExtendedEvent represents an extended event descriptor.
DescriptorExtendedEventItem represents an extended event item descriptor.
DescriptorExtension represents an extension descriptor Page: 72 | https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorExtensionSupplementaryAudio represents a supplementary audio extension descriptor Page: 130 | https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorISO639LanguageAndAudioType represents an ISO639 language descriptor.
DescriptorLocalTimeOffset represents a local time offset descriptor Page: 84 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorLocalTimeOffsetItem represents a local time offset item descriptor.
DescriptorMaximumBitrate represents a maximum bitrate descriptor.
DescriptorNetworkName represents a network name descriptor Page: 93 | Chapter: 6.2.27 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorParentalRating represents a parental rating descriptor Page: 93 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorParentalRatingItem represents a parental rating item descriptor.
DescriptorPrivateDataIndicator represents a private data Indicator descriptor.
DescriptorPrivateDataSpecifier represents a private data specifier descriptor.
DescriptorRegistration represents a registration descriptor Page: 84 | http://ecee.colorado.edu/~ecen5653/ecen5653/papers/iso13818-1.pdf.
DescriptorService represents a service descriptor Page: 96 | Chapter: 6.2.33 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorShortEvent represents a short event descriptor Page: 99 | Chapter: 6.2.37 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorStreamIdentifier represents a stream identifier descriptor Page: 102 | Chapter: 6.2.39 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorSubtitling represents a subtitling descriptor Page: 103 | Chapter: 6.2.41 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorSubtitlingItem represents subtitling descriptor item.
DescriptorTeletext represents a teletext descriptor Page: 105 | Chapter: 6.2.43 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorTeletextItem represents a teletext descriptor item.
DescriptorVBIData represents a VBI data descriptor Page: 108 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
DescriptorVBIDataItem represents a vbi data descriptor item.
DescriptorVBIDataService represents a vbi data service descriptor.
DSMTrickMode represents a DSM trick mode https://books.google.fr/books?id=vwUrAwAAQBAJ&pg=PT501&lpg=PT501&dq=dsm+trick+mode+control&source=bl&ots=fI-9IHXMRL&sig=PWnhxrsoMWNQcl1rMCPmJGNO9Ds&hl=fr&sa=X&ved=0ahUKEwjogafD8bjXAhVQ3KQKHeHKD5oQ6AEINDAB#v=onepage&q=dsm%20trick%20mode%20control&f=false.
EITData represents an EIT data Page: 36 | Chapter: 5.2.4 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
EITDataEvent represents an EIT data event.
NITData represents a NIT data Page: 29 | Chapter: 5.2.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
NITDataTransportStream represents a NIT data transport stream.
Packet represents a packet https://en.wikipedia.org/wiki/MPEG_transport_stream.
PacketAdaptationExtensionField represents a packet adaptation extension field.
PacketAdaptationField represents a packet adaptation field.
PacketHeader represents a packet header.
PATData represents a PAT data https://en.wikipedia.org/wiki/Program-specific_information.
PATProgram represents a PAT program.
PESData represents a PES data https://en.wikipedia.org/wiki/Packetized_elementary_stream http://dvd.sourceforge.net/dvdinfo/pes-hdr.html http://happy.emu.id.au/lab/tut/dttb/dtbtut4b.htm.
PESHeader represents a packet PES header.
PESOptionalHeader represents a PES optional header.
PMTData represents a PMT data https://en.wikipedia.org/wiki/Program-specific_information.
PMTElementaryStream represents a PMT elementary stream.
PSIData represents a PSI data https://en.wikipedia.org/wiki/Program-specific_information.
PSISection represents a PSI section.
PSISectionHeader represents a PSI section header.
PSISectionSyntax represents a PSI section syntax.
PSISectionSyntaxData represents a PSI section syntax data.
PSISectionSyntaxHeader represents a PSI section syntax header.
SDTData represents an SDT data Page: 33 | Chapter: 5.2.3 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.
SDTDataService represents an SDT data service.
TOTData represents a TOT data Page: 39 | Chapter: 5.2.6 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf.

# Type aliases

PacketsParser represents an object capable of parsing a set of packets containing a unique payload spanning over those packets Use the skip returned argument to indicate whether the default process should still be executed on the set of packets.