sofia

package module
v1.13.9 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: OSL-3.0 Imports: 6 Imported by: 2

README

sofia

And, in the dream, I knew that he was, going on ahead. He was fixin' to make a fire somewhere out there in all that dark and cold. And I knew that whenever I got there, he'd be there. And then I woke up.

No Country for Old Men (2007)

features

  • delete edts box
  • delete pssh box
  • delete sinf box
  • read enca box
  • read encv box
  • read frma box
  • read mdat box
  • read mdhd box
  • read mdia box
  • read moof box
  • read moov box
  • read pssh box
  • read senc box
  • read sidx box
  • read sinf box
  • read tfhd box
  • read traf box
  • read trak box
  • read trun box
  • update enca box
  • update encv box
  • write mdat box
  • write moov box

prior art

  1. https://github.com/mozilla/mp4parse-rust/issues/415
  2. https://github.com/Eyevinn/mp4ff/issues/311
  3. https://github.com/alfg/mp4-rust/issues/132
  4. https://github.com/yapingcat/gomedia/issues/115
  5. https://github.com/alfg/mp4/issues/27
  6. https://github.com/abema/go-mp4/issues/13
  7. https://github.com/garden4hu/fmp4parser-go/issues/4
  8. https://github.com/eswarantg/mp4box/issues/3
  9. https://github.com/miquels/mp4/issues/2

standard

ISO/IEC 14496-12: https://wikipedia.org/wiki/ISO_base_media_file_format

ISO/IEC 14496-14: https://wikipedia.org/wiki/MP4_file_format

ISO/IEC 23001-7: https://wikipedia.org/wiki/MPEG_Common_Encryption

Discord

https://discord.com/invite/rMFzDRQhSx

Documentation

Overview

config.go

core.go

encryption.go

fragment.go

movie.go

remuxer.go

tables.go

track.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt added in v1.9.7

func Decrypt(data []byte, sample *SencSample, block cipher.Block)

--- Logic ---

Types

type Box

type Box struct {
	Moov *MoovBox
	Moof *MoofBox
	Mdat *MdatBox
	Sidx *SidxBox
	Pssh *PsshBox
	Raw  []byte
}

--- Box ---

func DecodeBoxes added in v1.13.9

func DecodeBoxes(data []byte) ([]Box, error)

func (*Box) Encode added in v1.8.4

func (b *Box) Encode() []byte

type BoxHeader

type BoxHeader struct {
	Size uint32
	Type [4]byte
}

--- BoxHeader ---

func DecodeBoxHeader added in v1.13.9

func DecodeBoxHeader(data []byte) (*BoxHeader, error)

func (*BoxHeader) Put added in v1.11.2

func (h *BoxHeader) Put(buffer []byte)

type Co64Box added in v1.13.3

type Co64Box struct {
	Header  *BoxHeader
	Offsets []uint64
}

--- CO64 ---

func (*Co64Box) Encode added in v1.13.3

func (b *Co64Box) Encode() []byte

type CttsBox added in v1.13.3

type CttsBox struct {
	Header  *BoxHeader
	Entries []CttsEntry
}

func (*CttsBox) Encode added in v1.13.3

func (b *CttsBox) Encode() []byte

type CttsEntry added in v1.13.3

type CttsEntry struct {
	SampleCount  uint32
	SampleOffset int32
}

--- CTTS ---

type EncBox added in v1.11.2

type EncBox struct {
	Header      *BoxHeader
	EntryHeader []byte
	Sinf        *SinfBox
	RawChildren [][]byte
}

--- ENC (Encrypted Sample Entry) ---

func DecodeEncBox added in v1.13.9

func DecodeEncBox(data []byte) (*EncBox, error)

func (*EncBox) Encode added in v1.11.2

func (b *EncBox) Encode() []byte

type FrmaBox added in v1.8.4

type FrmaBox struct {
	Header     *BoxHeader
	DataFormat [4]byte
}

--- FRMA ---

func DecodeFrmaBox added in v1.13.9

func DecodeFrmaBox(data []byte) (*FrmaBox, error)

type MdatBox added in v1.8.4

type MdatBox struct {
	Header  *BoxHeader
	Payload []byte
}

--- MDAT ---

func DecodeMdatBox added in v1.13.9

func DecodeMdatBox(data []byte) (*MdatBox, error)

type MdhdBox added in v1.8.4

type MdhdBox struct {
	Header           *BoxHeader
	Version          byte
	Flags            [3]byte
	CreationTime     uint64
	ModificationTime uint64
	Timescale        uint32
	Duration         uint64
	Language         [2]byte
	Quality          [2]byte
}

--- MDHD ---

func DecodeMdhdBox added in v1.13.9

func DecodeMdhdBox(data []byte) (*MdhdBox, error)

func (*MdhdBox) Encode added in v1.8.4

func (b *MdhdBox) Encode() []byte

func (*MdhdBox) SetDuration added in v1.11.2

func (b *MdhdBox) SetDuration(duration uint64)

type MdiaBox added in v1.8.4

type MdiaBox struct {
	Header      *BoxHeader
	Mdhd        *MdhdBox
	Minf        *MinfBox
	RawChildren [][]byte
}

--- MDIA ---

func DecodeMdiaBox added in v1.13.9

func DecodeMdiaBox(data []byte) (*MdiaBox, error)

func (*MdiaBox) Encode added in v1.8.4

func (b *MdiaBox) Encode() []byte

type MinfBox added in v1.8.4

type MinfBox struct {
	Header      *BoxHeader
	Stbl        *StblBox
	RawChildren [][]byte
}

--- MINF ---

func DecodeMinfBox added in v1.13.9

func DecodeMinfBox(data []byte) (*MinfBox, error)

func (*MinfBox) Encode added in v1.8.4

func (b *MinfBox) Encode() []byte

type MoofBox added in v1.8.4

type MoofBox struct {
	Header      *BoxHeader
	Traf        *TrafBox
	Pssh        []*PsshBox
	RawChildren [][]byte
}

--- MOOF ---

func DecodeMoofBox added in v1.13.9

func DecodeMoofBox(data []byte) (*MoofBox, error)

type MoovBox added in v1.8.4

type MoovBox struct {
	Header      *BoxHeader
	Mvhd        *MvhdBox
	Trak        []*TrakBox
	Pssh        []*PsshBox
	RawChildren [][]byte
}

--- MOOV ---

func DecodeMoovBox added in v1.13.9

func DecodeMoovBox(data []byte) (*MoovBox, error)

func FindMoov added in v1.8.6

func FindMoov(boxes []Box) (*MoovBox, bool)

--- Finders ---

func (*MoovBox) Encode added in v1.8.4

func (b *MoovBox) Encode() []byte

func (*MoovBox) FindPssh added in v1.9.9

func (b *MoovBox) FindPssh(systemID []byte) (*PsshBox, bool)

func (*MoovBox) RemoveMvex added in v1.11.2

func (b *MoovBox) RemoveMvex()

func (*MoovBox) RemovePssh added in v1.11.2

func (b *MoovBox) RemovePssh()

type MvhdBox added in v1.12.5

type MvhdBox struct {
	Header           *BoxHeader
	Version          byte
	Flags            [3]byte
	CreationTime     uint64
	ModificationTime uint64
	Timescale        uint32
	Duration         uint64
	RemainingData    []byte
}

--- MVHD ---

func DecodeMvhdBox added in v1.13.9

func DecodeMvhdBox(data []byte) (*MvhdBox, error)

func (*MvhdBox) Encode added in v1.12.5

func (b *MvhdBox) Encode() []byte

func (*MvhdBox) SetDuration added in v1.12.5

func (b *MvhdBox) SetDuration(duration uint64)

type PsshBox added in v1.8.4

type PsshBox struct {
	Header   *BoxHeader
	Version  byte
	Flags    [3]byte
	SystemID [16]byte
	KIDs     [][16]byte
	Data     []byte
}

--- PSSH ---

func DecodePsshBox added in v1.13.9

func DecodePsshBox(data []byte) (*PsshBox, error)

type RemuxSample added in v1.12.9

type RemuxSample struct {
	Size                  uint32
	Duration              uint32
	IsSync                bool
	CompositionTimeOffset int32
}

type Remuxer added in v1.12.9

type Remuxer struct {
	Writer io.WriteSeeker
	Moov   *MoovBox

	OnSample func(data []byte, sample *SencSample)
	// contains filtered or unexported fields
}

func (*Remuxer) AddSegment added in v1.12.9

func (r *Remuxer) AddSegment(segmentData []byte) error

func (*Remuxer) Finish added in v1.12.9

func (r *Remuxer) Finish() error

func (*Remuxer) Initialize added in v1.12.9

func (r *Remuxer) Initialize(initSegment []byte) error

type SchiBox added in v1.8.4

type SchiBox struct {
	Header      *BoxHeader
	Tenc        *TencBox
	RawChildren [][]byte
}

--- SCHI (Scheme Information) ---

func DecodeSchiBox added in v1.13.9

func DecodeSchiBox(data []byte) (*SchiBox, error)

type SencBox added in v1.8.4

type SencBox struct {
	Header  *BoxHeader
	Flags   uint32
	Samples []SencSample
}

func DecodeSencBox added in v1.13.9

func DecodeSencBox(data []byte) (*SencBox, error)

type SencSample added in v1.13.9

type SencSample struct {
	IV         []byte
	Subsamples []Subsample
}

type SidxBox added in v1.8.4

type SidxBox struct {
	Header                   *BoxHeader
	Version                  byte
	Flags                    uint32
	ReferenceID              uint32
	Timescale                uint32
	EarliestPresentationTime uint64
	FirstOffset              uint64
	References               []SidxReference
}

func DecodeSidxBox added in v1.13.9

func DecodeSidxBox(data []byte) (*SidxBox, error)

func FindSidx added in v1.8.6

func FindSidx(boxes []Box) (*SidxBox, bool)

type SidxReference added in v1.8.4

type SidxReference struct {
	ReferenceType      bool
	ReferencedSize     uint32
	SubsegmentDuration uint32
	StartsWithSAP      bool
	SAPType            uint8
	SAPDeltaTime       uint32
}

--- SIDX ---

type SinfBox added in v1.8.4

type SinfBox struct {
	Header      *BoxHeader
	Frma        *FrmaBox
	Schi        *SchiBox
	RawChildren [][]byte
}

--- SINF ---

func DecodeSinfBox added in v1.13.9

func DecodeSinfBox(data []byte) (*SinfBox, error)

type StblBox added in v1.8.4

type StblBox struct {
	Header      *BoxHeader
	Stsd        *StsdBox
	RawChildren [][]byte
}

--- STBL ---

func DecodeStblBox added in v1.13.9

func DecodeStblBox(data []byte) (*StblBox, error)

func (*StblBox) Encode added in v1.8.4

func (b *StblBox) Encode() []byte

type StcoBox added in v1.11.2

type StcoBox struct {
	Header  *BoxHeader
	Offsets []uint32
}

--- STCO ---

func (*StcoBox) Encode added in v1.11.2

func (b *StcoBox) Encode() []byte

type StscBox added in v1.11.2

type StscBox struct {
	Header  *BoxHeader
	Entries []StscEntry
}

func (*StscBox) Encode added in v1.11.2

func (b *StscBox) Encode() []byte

type StscEntry added in v1.11.2

type StscEntry struct {
	FirstChunk             uint32
	SamplesPerChunk        uint32
	SampleDescriptionIndex uint32
}

--- STSC ---

type StsdBox added in v1.8.4

type StsdBox struct {
	Header       *BoxHeader
	HeaderFields [8]byte // Ver(1)+Flags(3)+EntryCount(4)
	EncChildren  []*EncBox
	RawChildren  [][]byte
}

--- STSD ---

func DecodeStsdBox added in v1.13.9

func DecodeStsdBox(data []byte) (*StsdBox, error)

func (*StsdBox) Encode added in v1.8.4

func (b *StsdBox) Encode() []byte

func (*StsdBox) RemoveSinf added in v1.13.9

func (b *StsdBox) RemoveSinf() error

func (*StsdBox) Sinf added in v1.10.6

func (b *StsdBox) Sinf() (*SinfBox, *BoxHeader, bool)

type StssBox added in v1.12.1

type StssBox struct {
	Header  *BoxHeader
	Indices []uint32
}

--- STSS ---

func (*StssBox) Encode added in v1.12.1

func (b *StssBox) Encode() []byte

type StszBox added in v1.11.2

type StszBox struct {
	Header      *BoxHeader
	SampleSize  uint32
	SampleCount uint32
	EntrySizes  []uint32
}

--- STSZ ---

func (*StszBox) Encode added in v1.11.2

func (b *StszBox) Encode() []byte

type SttsBox added in v1.11.2

type SttsBox struct {
	Header  *BoxHeader
	Entries []SttsEntry
}

func (*SttsBox) Encode added in v1.11.2

func (b *SttsBox) Encode() []byte

type SttsEntry added in v1.11.2

type SttsEntry struct {
	SampleCount    uint32
	SampleDuration uint32
}

--- STTS ---

type Subsample added in v1.13.9

type Subsample struct {
	BytesOfClearData     uint16
	BytesOfProtectedData uint32
}

--- SENC ---

type TencBox added in v1.8.4

type TencBox struct {
	Header                 *BoxHeader
	Version                byte
	Flags                  uint32
	DefaultIsProtected     byte
	DefaultPerSampleIVSize byte
	DefaultKID             [16]byte
	DefaultConstantIVSize  byte   // Present if DefaultIsProtected=1 and DefaultPerSampleIVSize=0
	DefaultConstantIV      []byte // Present if DefaultIsProtected=1 and DefaultPerSampleIVSize=0
}

--- TENC --- TencBox defines the Track Encryption Box ('tenc'), which contains default encryption parameters for a track. Specification: ISO/IEC 23001-7

func DecodeTencBox added in v1.13.9

func DecodeTencBox(data []byte) (*TencBox, error)

type TfhdBox added in v1.8.4

type TfhdBox struct {
	Header                 *BoxHeader
	Flags                  uint32
	TrackID                uint32
	BaseDataOffset         uint64
	SampleDescriptionIndex uint32
	DefaultSampleDuration  uint32
	DefaultSampleSize      uint32
	DefaultSampleFlags     uint32
}

--- TFHD ---

func DecodeTfhdBox added in v1.13.9

func DecodeTfhdBox(data []byte) (*TfhdBox, error)

type TrafBox added in v1.8.4

type TrafBox struct {
	Header      *BoxHeader
	Tfhd        *TfhdBox
	Trun        []*TrunBox
	Senc        *SencBox
	Tenc        *TencBox
	RawChildren [][]byte
}

--- TRAF ---

func DecodeTrafBox added in v1.13.9

func DecodeTrafBox(data []byte) (*TrafBox, error)

type TrakBox added in v1.8.4

type TrakBox struct {
	Header      *BoxHeader
	Mdia        *MdiaBox
	RawChildren [][]byte
}

--- TRAK ---

func DecodeTrakBox added in v1.13.9

func DecodeTrakBox(data []byte) (*TrakBox, error)

func (*TrakBox) Encode added in v1.8.4

func (b *TrakBox) Encode() []byte

func (*TrakBox) RemoveEdts added in v1.8.4

func (b *TrakBox) RemoveEdts()

type TrunBox added in v1.8.4

type TrunBox struct {
	Header           *BoxHeader
	Flags            uint32
	SampleCount      uint32
	DataOffset       int32
	FirstSampleFlags uint32
	Samples          []TrunSample
}

func DecodeTrunBox added in v1.13.9

func DecodeTrunBox(data []byte) (*TrunBox, error)

type TrunSample added in v1.13.9

type TrunSample struct {
	Size                  uint32
	Duration              uint32
	Flags                 uint32
	CompositionTimeOffset int32
}

--- TRUN ---

Jump to

Keyboard shortcuts

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