m2ts

package
v1.5.47 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package m2ts is parsing M2TS files followings specs: https://en.wikipedia.org/wiki/MPEG_transport_stream https://en.wikipedia.org/wiki/Packetized_elementary_stream https://en.wikipedia.org/wiki/Program-specific_information

Index

Constants

View Source
const (
	MDPMDate         = 0x18
	MDPMTime         = 0x19
	MDPMGPSLatitude  = 0xb2
	MDPMGPSLongitude = 0xb6
	MDPMMake         = 0xe0
	MDPMModel        = 0xe4
)

Variables

This section is empty.

Functions

func NewPacket

func NewPacket() []byte

NewPacket creates a Packet structure to parse M2TS files

func UpdateDetailsFromMDPM

func UpdateDetailsFromMDPM(payload []byte, details *backup.MediaDetails) map[byte][]byte

UpdateDetailsFromMDPM find MDPM UUID followed by 'MDPM' marker, and reads what's following as key-value map inspired by https://metacpan.org/release/EXIFTOOL/Image-ExifTool-8.90/source/lib/Image/ExifTool/H264.pm

Types

type PES

type PES []byte

func (PES) PESLength

func (p PES) PESLength() int

PESLength is the number of bytes the PES header is. The Following bytes are the stream payload. Example:

00000000  00 00 01 e0 00 00 85 c0  0a 31 00 07 13 81 11 00  |.........1......|
00000010  05 bf 21 00 00 00 01 09  10 00 00 00 01 27 64 00  |..!..........'d.|
                   ^ Video Stream starts here

func (PES) Valid

func (p PES) Valid() error

Valid checks if the payload starts with appropriate prefix (0x000001)

type PSI

type PSI []byte

PSI is a wrapper to decode a PSI table

func (PSI) AssociationTable

func (p PSI) AssociationTable() map[uint16]uint16

AssociationTable reads PAT table content to extract association table

func (PSI) UpdateProgramMap

func (p PSI) UpdateProgramMap(programs map[uint16]ProgramNumber) map[uint16]ProgramNumber

UpdateProgramMap reads PMT table to update program map

func (PSI) Valid

func (p PSI) Valid() error

type Packet

type Packet []byte

func (Packet) PCR

func (p Packet) PCR() (uint64, bool)

PCR retrieve PCR value in adaptation field if present, or returns (0, false)

func (Packet) PID

func (p Packet) PID() uint16

PID returns packet PID ; it might panic if packet is not Valid()

func (Packet) Payload

func (p Packet) Payload() []byte

Payload retrieves the payload from the packet or returns nil

func (Packet) PesPsiDvbPayload

func (p Packet) PesPsiDvbPayload() bool

PesPsiDvbPayload returns TRUE when the Payload is PES, PSI, or DVB

func (Packet) Valid

func (p Packet) Valid() error

Valid confirms it's a M2TS packet by looking at the Sync Byte

type Parser

type Parser struct {
	Debug bool // Debug can be set to true to print in the console payload dumps and read metadata.
}

func (*Parser) ReadDetails

func (p *Parser) ReadDetails(reader io.Reader, options backup.DetailsReaderOptions) (*backup.MediaDetails, error)

ReadDetails unmux M2TS (MTS) file, with h264 support, to collect the Make, Model, and DateTime of the video flux. Example: 00 00 00 00 | 47 40 00 10 | 00 00 b0 11 00 00 c1 00 00 00 00 e0 1f 00 01 e1 00 23 5a ab 82 ffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff

M2TS HEADER-- PAT HEADER- SECTION------- #1--------- #2--------- CRC--------

00 00 06 9c | 47 | 41 00 10 | 00 02 b0 3e | 00 01 c1 00 00 | f0 01 f0 0c | 05 04 48 44 | 4d 56 88 04 | 0f ff fc fc | 1b f0 11 f0 0a | 05 08 48 44 4d 56 ff 1b 43 3f | 81 f1 00 f0 0c | 05 04 41 43 2d 33 81 04 04 30 04 00 90 f2 00 f0 00 | 0c d3 f4 dc

M2TS HEADER---  PAT HEADER--  SECTION-------   PMT-------- | Program Descriptors -------------------   #1 1011=>1b-----------------------------------                                                                         CRC--------

func (*Parser) Supports

func (p *Parser) Supports(media backup.FoundMedia, mediaType backup.MediaType) bool

type ProgramNumber

type ProgramNumber uint8

ProgramNumber is the code as defined in https://en.wikipedia.org/wiki/Program-specific_information#Program_and_Elementary_Stream_Descriptor_Tags

const (
	PIDMask                         = 0x1fff // PIDMask can be used to get PID from uint16: last 13 bits
	ProgramNumberH264 ProgramNumber = 0x1b   // ProgramNumberH264 is a H264 video stream

)

Jump to

Keyboard shortcuts

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