tsmux

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrainTS188Aligned

func DrainTS188Aligned(carry *[]byte, chunk []byte, emit func([]byte))

DrainTS188Aligned appends chunk to carry, then calls emit once per aligned 188-byte MPEG-TS packet (sync 0x47). Used so FFmpeg stdin receives transport-aligned writes.

func FeedWirePacket

func FeedWirePacket(ts []byte, av *domain.AVPacket, mux **FromAV, onTS func([]byte))

FeedWirePacket forwards raw TS chunks or muxes one AVPacket to TS via mux (lazily allocated).

func FindH264ParameterSets added in v0.0.103

func FindH264ParameterSets(raw []byte) (sps, pps []byte)

FindH264ParameterSets scans raw bytes for the first NAL units of type 7 (SPS) and type 8 (PPS) and returns their bodies (without start codes). Detects both 4-byte (00 00 00 01) and 3-byte (00 00 01) Annex-B start codes. Returns nil for any NAL not present.

Use case: the publisher's serve_rtmp pipeline needs SPS/PPS to build the AVCDecoderConfigurationRecord seq header tag, but receives raw TS from the buffer hub (no AV packets). gomedia's TSDemuxer should preserve SPS/PPS in OnFrame access-unit bytes per its source, but some upstream code paths or stream variations have produced frames without parameter sets. Scanning raw TS bytes is a defensive fallback that does NOT depend on the demuxer's frame-splitting behaviour.

SPS validation: every candidate (byte after a start code with low-5 bits == 7) is parsed via mp4ff's avc.ParseSPSNALUnit. False positives — random payload bytes that look like an Annex-B start code followed by a byte whose nal_unit_type bits equal 7 — fail parsing, so we keep scanning forward. Without this validation we returned ~1KB blobs of payload as "SPS" and pushed garbage AVC sequence headers to RTMP clients (observed: width=16, height=16, ProfileIdc=1 — impossible for real video).

This is a best-effort scan: NAL units split across TS-packet boundaries (with adaptation-field stuffing) may be missed. For SPS (~30 bytes for typical 1080p H264) this is unlikely since the whole NAL fits within a single 184-byte TS payload. PPS is even smaller.

Caller should retain the returned slices (do not reference into the input — we copy out so subsequent buffer reuse cannot corrupt the cached parameter sets).

func KeyFrameH264

func KeyFrameH264(annexB []byte) bool

KeyFrameH264 reports whether Annex-B H.264 payload contains an IDR slice.

func KeyFrameH265

func KeyFrameH265(annexB []byte) bool

KeyFrameH265 reports whether Annex-B H.265 payload contains an IRAP slice.

Types

type FromAV

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

FromAV wraps a gomedia TSMuxer and converts AVPackets into 188-byte MPEG-TS packets. One instance per output pipeline (segmenter, publisher pump, transcoder stdin feeder, …).

func NewFromAV

func NewFromAV() *FromAV

NewFromAV creates an empty muxer; streams are added on first packet per codec.

func (*FromAV) Write

func (f *FromAV) Write(p *domain.AVPacket, onPacket func([]byte))

Write converts one AVPacket to TS transport packets via OnPacket callback.

Jump to

Keyboard shortcuts

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