m2ts

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package m2ts demultiplexes the video elementary streams of an MPEG-2 transport stream (including Blu-ray .m2ts with 192-byte packets) and pairs the base view (AVC) and dependent view (MVC) access units.

Index

Constants

View Source
const (
	PIDBaseView = 0x1011
	PIDDepView  = 0x1012
)

Blu-ray PIDs of the primary video and its MVC dependent view.

View Source
const (
	TypeMPEG2Video = 0x02
	TypeAVC        = 0x1b
	TypeMVC        = 0x20
	TypeHEVC       = 0x24
	TypeVC1        = 0xea
	TypeLPCM       = 0x80
	TypeAC3        = 0x81
	TypeDTS        = 0x82
	TypeTrueHD     = 0x83
	TypeEAC3       = 0x84
	TypeDTSHDHR    = 0x85
	TypeDTSHDMA    = 0x86
	TypeEAC3Sec    = 0xa1
	TypeDTSSec     = 0xa2
	TypePGS        = 0x90
	TypeIGS        = 0x91
	TypeText       = 0x92
)

Stream types of a Blu-ray program (stream_type in the PMT).

Variables

View Source
var ErrEncrypted = errors.New("m2ts: the stream is encrypted (AACS): only a decrypted disc can be read")

ErrEncrypted is a Blu-ray stream still under AACS: its aligned units' copy permission bits are set and all but their first 16 bytes scrambled. Only decrypted discs can be read.

Functions

func PATBody

func PATBody(program, pmtPID uint16) []byte

PATBody is the body of a PAT listing one program.

func PMTBody

func PMTBody(prog *Program) []byte

PMTBody is the body of a PMT for prog's streams.

func Section

func Section(tableID byte, ext uint16, version byte, body []byte) []byte

Section builds a PSI section: the header, the body, and the CRC.

Types

type AccessUnit

type AccessUnit struct {
	Base []byte // base view NAL units (AVC)
	Dep  []byte // dependent view NAL units (MVC), may be empty
	PTS  int64  // presentation time stamp (90 kHz), -1 if absent
	DTS  int64
}

AccessUnit is one paired access unit in Annex B format.

type Demuxer

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

Demuxer extracts paired access units from a transport stream.

func NewDemuxer

func NewDemuxer(r io.Reader) *Demuxer

NewDemuxer returns a demuxer for the Blu-ray video PIDs.

func NewDemuxerPIDs

func NewDemuxerPIDs(r io.Reader, base, dep uint16) *Demuxer

NewDemuxerPIDs returns a demuxer for the given base and dependent PIDs.

func (*Demuxer) Next

func (d *Demuxer) Next() (AccessUnit, error)

Next returns the next access unit. The returned buffers may be passed to Recycle once consumed.

func (*Demuxer) Recycle

func (d *Demuxer) Recycle(au *AccessUnit)

Recycle returns the buffers of an access unit for reuse.

type PES

type PES struct {
	PID      uint16
	StreamID byte
	PTS, DTS int64 // 90 kHz, -1 when absent
	Payload  []byte
}

PES is one packetised elementary stream packet, with its header removed.

type Program

type Program struct {
	Number  uint16
	PCRPID  uint16
	Version byte
	// Info is the raw program_info descriptor loop.
	Info    []byte
	Streams []ProgramStream
}

Program is the content of the PMT.

func (*Program) Stream

func (p *Program) Stream(pid uint16) (ProgramStream, bool)

Stream returns the program's entry for a PID, if any.

type ProgramStream

type ProgramStream struct {
	PID  uint16
	Type byte
	// Lang is the ISO 639-2 code from the language descriptor, if any.
	Lang string
	// Descriptors is the stream's raw descriptor loop, for rewriting a PMT.
	Descriptors []byte
}

ProgramStream is one elementary stream the PMT announces.

type Reader

type Reader struct {

	// Packets counts the transport packets read.
	Packets int64
	// contains filtered or unexported fields
}

Reader splits a transport stream into PES packets, for every PID or a chosen set, and reads the program tables on the way.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader returns a reader over a 188- or 192-byte-packet stream.

func (*Reader) Next

func (r *Reader) Next() (PES, error)

Next returns the next PES packet. Packets of the same PID come in stream order; across PIDs in the order they complete. The payload is owned by the caller.

func (*Reader) PMTPIDs

func (r *Reader) PMTPIDs() []uint16

PMTPIDs returns the PIDs the PAT announced PMTs on.

func (*Reader) Program

func (r *Reader) Program() *Program

Program returns the PMT once it has been read, else nil.

func (*Reader) ReadProgram

func (r *Reader) ReadProgram() (*Program, error)

ReadProgram reads packets until a PMT has been seen, keeping any PES packets completed meanwhile for Next. A file interleaving two clips (an SSIF) carries a PMT per clip; the program grows as later ones are read, so a caller wanting every stream reads on and asks Program again.

func (*Reader) Select

func (r *Reader) Select(pids ...uint16)

Select limits the PES packets returned to these PIDs. The program tables are read regardless.

Jump to

Keyboard shortcuts

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