mp4

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: OSL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const TrunDataOffsetPresentFlag uint32 = 0x01
View Source
const TrunFirstSampleFlagsPresentFlag uint32 = 0x04
View Source
const TrunSampleCompositionTimeOffsetPresentFlag uint32 = 0x800
View Source
const TrunSampleDurationPresentFlag uint32 = 0x100
View Source
const TrunSampleFlagsPresentFlag uint32 = 0x400
View Source
const TrunSampleSizePresentFlag uint32 = 0x200

Variables

This section is empty.

Functions

func DecodeTfhd

func DecodeTfhd(hdr *boxHeader, startPos uint64, r io.Reader) (box, error)

DecodeTfhd - box-specific decode

func DecodeTfhdSR

func DecodeTfhdSR(hdr *boxHeader, startPos uint64, sr mp4ff.SliceReader) (box, error)

DecodeTfhdSR - box-specific decode

func DecodeTrafSR

func DecodeTrafSR(hdr *boxHeader, startPos uint64, sr mp4ff.SliceReader) (box, error)

DecodeTrafSR - box-specific decode

func DecodeTrunSR

func DecodeTrunSR(hdr *boxHeader, startPos uint64, sr mp4ff.SliceReader) (box, error)

DecodeTrun - box-specific decode

func DecryptSampleCenc

func DecryptSampleCenc(sample []byte, key []byte, iv []byte, subSamplePatterns []SubSamplePattern) ([]byte, error)

DecryptSampleCenc - decrypt cenc-mode encrypted sample

Types

type File

type File struct {
	Segments     []*MediaSegment // Media segments
	IsFragmented bool
}

func DecodeFile

func DecodeFile(r io.Reader) (*File, error)

type Fragment

type Fragment struct {
	Moof     *moofBox
	Mdat     *mdatBox
	Children []box // All top-level boxes in order
	// contains filtered or unexported fields
}

Fragment - MP4 Fragment ([prft] + moof + mdat)

func (*Fragment) Encode

func (f *Fragment) Encode(w io.Writer) error

Encode - write fragment via writer

func (*Fragment) GetFullSamples

func (f *Fragment) GetFullSamples() ([]FullSample, error)

GetFullSamples - Get full samples including media and accumulated time

type FullSample

type FullSample struct {
	DecodeTime uint64 // Absolute decode time (offset + accumulated sample Dur)
	Data       []byte // Sample data
	// contains filtered or unexported fields
}

FullSample - include accumulated time and data. Times in mdhd timescale

type MediaSegment

type MediaSegment struct {
	Fragments []*Fragment
	// contains filtered or unexported fields
}

MediaSegment - MP4 Media Segment

func (*MediaSegment) Encode

func (s *MediaSegment) Encode(w io.Writer) error

Encode - Write MediaSegment via writer

type SampleGroupEntry

type SampleGroupEntry interface {

	// Encode SampleGroupEntry to SliceWriter
	Encode(sw mp4ff.SliceWriter)
	// contains filtered or unexported methods
}

SampleGroupEntry - like a box, but size and type are not in a header

type SampleGroupEntryDecoder

type SampleGroupEntryDecoder func(name string, length uint32, sr mp4ff.SliceReader) (SampleGroupEntry, error)

SampleGroupEntryDecoder is function signature of the SampleGroupEntry Decode method

type SencBox

type SencBox struct {
	Version byte

	Flags       uint32
	SampleCount uint32
	StartPos    uint64

	IVs        []initializationVector // 8 or 16 bytes if present
	SubSamples [][]SubSamplePattern
	// contains filtered or unexported fields
}

SencBox - Sample Encryption Box (senc) (in trak or traf box) Should only be decoded after saio and saiz provide relevant offset and sizes Here we make a two-step decode, with first step reading, and other parsing. See ISO/IEC 23001-7 Section 7.2 and CMAF specification Full Box + SampleCount

func (*SencBox) Encode

func (s *SencBox) Encode(w io.Writer) error

Encode - write box to w

type SubSamplePattern

type SubSamplePattern struct {
	BytesOfClearData     uint16
	BytesOfProtectedData uint32
}

SubSamplePattern - pattern of subsample encryption

type TfhdBox

type TfhdBox struct {
	Version                byte
	Flags                  uint32
	TrackID                uint32
	BaseDataOffset         uint64
	SampleDescriptionIndex uint32
	DefaultSampleDuration  uint32
	DefaultSampleSize      uint32
	DefaultSampleFlags     uint32
}

TfhdBox - Track Fragment Header Box (tfhd)

Contained in : Track Fragment box (traf))

func CreateTfhd

func CreateTfhd(trackID uint32) *TfhdBox

CreateTfhd - Create a new TfdtBox with baseMediaDecodeTime

func (*TfhdBox) DefaultBaseIfMoof

func (t *TfhdBox) DefaultBaseIfMoof() bool

DefaultBaseIfMoof - interpreted flags value

func (*TfhdBox) DurationIsEmpty

func (t *TfhdBox) DurationIsEmpty() bool

DurationIsEmpty - interpreted flags value

func (*TfhdBox) Encode

func (t *TfhdBox) Encode(w io.Writer) error

Encode - write box to w

func (*TfhdBox) HasBaseDataOffset

func (t *TfhdBox) HasBaseDataOffset() bool

HasBaseDataOffset - interpreted flags value

func (*TfhdBox) HasDefaultSampleDuration

func (t *TfhdBox) HasDefaultSampleDuration() bool

HasDefaultSampleDuration - interpreted flags value

func (*TfhdBox) HasDefaultSampleFlags

func (t *TfhdBox) HasDefaultSampleFlags() bool

HasDefaultSampleFlags - interpreted flags value

func (*TfhdBox) HasDefaultSampleSize

func (t *TfhdBox) HasDefaultSampleSize() bool

HasDefaultSampleSize - interpreted flags value

func (*TfhdBox) HasSampleDescriptionIndex

func (t *TfhdBox) HasSampleDescriptionIndex() bool

HasSampleDescriptionIndex - interpreted flags value

type TrafBox

type TrafBox struct {
	Children []box
	Senc     *SencBox
	//Sgpd     *SgpdBox
	Tfdt  *tfdtBox
	Tfhd  *TfhdBox
	Trun  *TrunBox // The first TrunBox
	Truns []*TrunBox
}

TrafBox - Track Fragment Box (traf)

Contained in : Movie Fragment Box (moof)

func (*TrafBox) ContainsSencBox

func (t *TrafBox) ContainsSencBox() (ok, parsed bool)

ContainsSencBox - is there a senc box in traf and is it parsed If not parsed, call ParseReadSenc to parse it

func (*TrafBox) Encode

func (t *TrafBox) Encode(w io.Writer) error

Encode - write box to w

func (*TrafBox) ParseReadSenc

func (t *TrafBox) ParseReadSenc(defaultIVSize byte, moofStartPos uint64) error

func (*TrafBox) RemoveEncryptionBoxes

func (t *TrafBox) RemoveEncryptionBoxes() uint64

RemoveEncryptionBoxes - remove encryption boxes and return number of bytes removed

type TrunBox

type TrunBox struct {
	Version byte
	Flags   uint32

	DataOffset int32

	Samples []sample
	// contains filtered or unexported fields
}

TrunBox - Track Fragment Run Box (trun)

Contained in : Track Fragmnet Box (traf)

func (*TrunBox) AddSampleDefaultValues

func (t *TrunBox) AddSampleDefaultValues(tfhd *TfhdBox) (totalDur uint64)

AddSampleDefaultValues - add values from tfhd and trex boxes if needed Return total duration

func (*TrunBox) Encode

func (t *TrunBox) Encode(w io.Writer) error

Encode - write box to w

func (*TrunBox) HasDataOffset

func (t *TrunBox) HasDataOffset() bool

HasDataOffset - interpreted dataOffsetPresent flag

func (*TrunBox) HasFirstSampleFlags

func (t *TrunBox) HasFirstSampleFlags() bool

HasFirstSampleFlags - interpreted firstSampleFlagsPresent flag

func (*TrunBox) HasSampleCompositionTimeOffset

func (t *TrunBox) HasSampleCompositionTimeOffset() bool

HasSampleCompositionTimeOffset - interpreted sampleCompositionTimeOffset flag

func (*TrunBox) HasSampleDuration

func (t *TrunBox) HasSampleDuration() bool

HasSampleDuration - interpreted sampleDurationPresent flag

func (*TrunBox) HasSampleFlags

func (t *TrunBox) HasSampleFlags() bool

HasSampleFlags - interpreted sampleFlagsPresent flag

func (*TrunBox) HasSampleSize

func (t *TrunBox) HasSampleSize() bool

HasSampleSize - interpreted sampleSizePresent flag

func (*TrunBox) SampleCount

func (t *TrunBox) SampleCount() uint32

SampleCount - return how many samples are defined

func (*TrunBox) SetFirstSampleFlags

func (t *TrunBox) SetFirstSampleFlags(flags uint32)

SetFirstSampleFlags - set firstSampleFlags and bit indicating its presence

func (*TrunBox) SizeOfData

func (t *TrunBox) SizeOfData() (totalSize uint64)

SizeOfData - size of mediasamples in bytes

Jump to

Keyboard shortcuts

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