mpegts

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 3 Imported by: 0 modules, 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 mpegts implements MPEG-2 Transport Stream readers and writers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessUnit

type AccessUnit struct {
	Track *Track
	// PTS and DTS are in 90 kHz ticks, unwrapped from the 33-bit wire
	// representation into monotonically increasing values. DTS equals PTS
	// when the stream carries no separate DTS.
	PTS, DTS int64
	// RandomAccess reports the random_access_indicator of the packet that
	// started this access unit (set by muxers on IDR/IRAP pictures).
	RandomAccess bool
	// Data is the access unit in Annex-B format. It is only valid until
	// the next call to NextAccessUnit; copy it to retain it.
	Data []byte
}

AccessUnit is one coded video frame extracted from the transport stream.

type Codec

type Codec int

Codec identifies the codec of an elementary stream.

const (
	CodecUnknown Codec = iota
	CodecH264
	CodecH265
)

Supported codecs.

func (Codec) String

func (c Codec) String() string

String returns the codec name.

type Reader

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

Reader demuxes an MPEG-2 Transport Stream from an io.Reader. It selects the first program advertised in the PAT and exposes its supported video streams as tracks.

func NewReader

func NewReader(src io.Reader, opts ...ReaderOption) (*Reader, error)

NewReader creates a Reader and consumes packets until the PAT and PMT have been parsed, so Tracks is available immediately after it returns.

func (*Reader) NextAccessUnit

func (r *Reader) NextAccessUnit() (*AccessUnit, error)

NextAccessUnit returns the next complete access unit in stream order. It returns io.EOF once the input and all buffered data are exhausted.

func (*Reader) Tracks

func (r *Reader) Tracks() []*Track

Tracks returns the supported video tracks of the selected program.

type ReaderOption

type ReaderOption func(*Reader) error

ReaderOption configures a Reader.

func WithMaxAccessUnitSize

func WithMaxAccessUnitSize(n int) ReaderOption

WithMaxAccessUnitSize bounds the memory used to reassemble one access unit. Larger units are dropped and reading resynchronizes. Default 4 MiB.

type Track

type Track struct {
	PID   uint16
	Codec Codec
}

Track describes one elementary stream inside a transport stream.

type Writer

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

Writer muxes video access units into a single-program MPEG-2 Transport Stream. The PCR is carried on the first configured track's PID.

func NewWriter

func NewWriter(dst io.Writer, opts ...WriterOption) (*Writer, error)

NewWriter creates a Writer emitting to dst. At least one track option is required.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the underlying writer when it implements io.Closer. A transport stream needs no trailer.

func (*Writer) WriteH264

func (w *Writer) WriteH264(pid uint16, pts, dts int64, accessUnit []byte) error

WriteH264 writes one H.264 access unit in Annex-B format. An access unit delimiter NAL is prepended when absent. pts and dts are 90 kHz ticks; pass dts equal to pts when the stream has no B-frames.

func (*Writer) WriteH265

func (w *Writer) WriteH265(pid uint16, pts, dts int64, accessUnit []byte) error

WriteH265 writes one H.265 access unit in Annex-B format. An access unit delimiter NAL is prepended when absent.

type WriterOption

type WriterOption func(*Writer) error

WriterOption configures a Writer.

func WithH264Track

func WithH264Track(pid uint16) WriterOption

WithH264Track adds an H.264 elementary stream on the given PID.

func WithH265Track

func WithH265Track(pid uint16) WriterOption

WithH265Track adds an H.265 elementary stream on the given PID.

Jump to

Keyboard shortcuts

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