mp4

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: MIT Imports: 9 Imported by: 41

README

go-mp4

GoDoc CircleCI codecov Go Report Card

go-mp4 is Go library for reading and writing MP4.

Integration with your Go application

You can parse MP4 file as follows:

// expand all boxes
_, err := mp4.ReadBoxStructure(file, func(h *mp4.ReadHandle) (interface{}, error) {
	fmt.Println("depth", len(h.Path))

	// Box Type (e.g. "mdhd", "tfdt", "mdat")
	fmt.Println(h.BoxInfo.Type.String())

	// Box Size
	fmt.Println(h.BoxInfo.Size)

	if h.BoxInfo.Type.IsSupported() {
		// Payload
		box, _, _ := h.ReadPayload()
		fmt.Println(mp4.Stringify(box))

		// Expands children
		return h.Expand()
	}
	return nil, nil
})
// extract specific boxes
boxes, err := mp4.ExtractBox(file, nil, mp4.BoxPath{mp4.BoxTypeMoov(), mp4.BoxTypeTrak(), mp4.BoxTypeTkhd()})

You can create additional box definition as follows:

func BoxTypeXxxx() BoxType { return StrToBoxType("xxxx") }

func init() {
	AddBoxDef(&Xxxx{}, 0)
}

type Xxxx struct {
	FullBox  `mp4:"extend"`
	UI32      uint32 `mp4:"size=32"`
	ByteArray []byte `mp4:"size=8,len=dynamic"`
}

func (*Xxxx) GetType() BoxType {
	return BoxTypeXxxx()
}

Command Line Tool

Install mp4tool as follows:

go get github.com/abema/go-mp4/mp4tool

mp4tool -help

For example, mp4tool dump MP4_FILE_NAME command prints MP4 box tree as follows:

[moof] Size=504
  [mfhd] Size=16 Version=0 Flags=0x000000 SequenceNumber=1
  [traf] Size=480
    [tfhd] Size=28 Version=0 Flags=0x020038 TrackID=1 DefaultSampleDuration=9000 DefaultSampleSize=33550 DefaultSampleFlags=0x1010000
    [tfdt] Size=20 Version=1 Flags=0x000000 BaseMediaDecodeTimeV1=0
    [trun] Size=424 ... (use -a option to show all)
[mdat] Size=44569 Data=[...] (use -mdat option to expand)

Documentation

Index

Constants

View Source
const (
	SmallHeaderSize = 8
	LargeHeaderSize = 16
)
View Source
const (
	ESDescrTag            = 0x03
	DecoderConfigDescrTag = 0x04
	DecSpecificInfoTag    = 0x05
	SLConfigDescrTag      = 0x06
)
View Source
const (
	TfhdBaseDataOffsetPresent         = 0x000001
	TfhdSampleDescriptionIndexPresent = 0x000002
	TfhdDefaultSampleDurationPresent  = 0x000008
	TfhdDefaultSampleSizePresent      = 0x000010
	TfhdDefaultSampleFlagsPresent     = 0x000020
	TfhdDurationIsEmpty               = 0x010000
	TfhdDefaultBaseIsMoof             = 0x020000
)
View Source
const UrlSelfContained = 0x000001
View Source
const UrnSelfContained = 0x000001

Variables

View Source
var ErrBoxInfoNotFound = errors.New("box info not found")
View Source
var ErrUnsupportedBoxVersion = errors.New("unsupported box version")

Functions

func AddAnyTypeBoxDef

func AddAnyTypeBoxDef(payload IAnyType, boxType BoxType, versions ...uint8)

func AddBoxDef

func AddBoxDef(payload IBox, versions ...uint8)

func Marshal

func Marshal(w io.Writer, src IImmutableBox) (n uint64, err error)

func ReadBoxStructure

func ReadBoxStructure(r io.ReadSeeker, handler ReadHandler, params ...interface{}) ([]interface{}, error)

func ReadBoxStructureFromInternal

func ReadBoxStructureFromInternal(r io.ReadSeeker, bi *BoxInfo, handler ReadHandler, params ...interface{}) (interface{}, error)

func Stringify

func Stringify(src IImmutableBox) (string, error)

func StringifyWithIndent

func StringifyWithIndent(src IImmutableBox, indent string) (string, error)

func Unmarshal

func Unmarshal(r io.ReadSeeker, payloadSize uint64, dst IBox) (n uint64, err error)

Types

type AVCDecoderConfiguration

type AVCDecoderConfiguration struct {
	AnyTypeBox
	ConfigurationVersion uint8 `mp4:"size=8"`
	Profile              uint8 `mp4:"size=8"`
	ProfileCompatibility uint8 `mp4:"size=8"`
	Level                uint8 `mp4:"size=8"`
	// TODO: Refer to ISO/IEC 14496-15
	Data []byte `mp4:"size=8"`
}

type AnyTypeBox

type AnyTypeBox struct {
	Box
	Type BoxType
}

func (*AnyTypeBox) GetType

func (e *AnyTypeBox) GetType() BoxType

func (*AnyTypeBox) SetType

func (e *AnyTypeBox) SetType(boxType BoxType)

type AudioSampleEntry

type AudioSampleEntry struct {
	SampleEntry  `mp4:"extend"`
	EntryVersion uint16    `mp4:"size=16"`
	Reserved     [3]uint16 `mp4:"size=16,const=0,hidden"`
	ChannelCount uint16    `mp4:"size=16"`
	SampleSize   uint16    `mp4:"size=16"`
	PreDefined   uint16    `mp4:"size=16"`
	Reserved2    uint16    `mp4:"size=16,const=0,hidden"`
	SampleRate   uint32    `mp4:"size=32"`
}

type BaseCustomFieldObject

type BaseCustomFieldObject struct {
}

func (*BaseCustomFieldObject) BeforeUnmarshal

func (*BaseCustomFieldObject) BeforeUnmarshal(r io.ReadSeeker) (uint64, bool, error)

func (*BaseCustomFieldObject) GetFieldLength

func (box *BaseCustomFieldObject) GetFieldLength(string) uint

GetFieldLength returns length of dynamic field

func (*BaseCustomFieldObject) GetFieldSize

func (box *BaseCustomFieldObject) GetFieldSize(string) uint

GetFieldSize returns size of dynamic field

func (*BaseCustomFieldObject) IsOptFieldEnabled

func (box *BaseCustomFieldObject) IsOptFieldEnabled(string) bool

IsOptFieldEnabled check whether if the optional field is enabled

func (*BaseCustomFieldObject) IsPString

func (*BaseCustomFieldObject) IsPString(name string, bytes []byte, remainingSize uint64) bool

func (*BaseCustomFieldObject) StringifyField

func (box *BaseCustomFieldObject) StringifyField(string, string, int) (string, bool)

StringifyField returns field value as string

type Box

type Box struct {
	BaseCustomFieldObject
}

func (*Box) AddFlag

func (box *Box) AddFlag(flag uint32)

AddFlag adds the flag

func (*Box) CheckFlag

func (box *Box) CheckFlag(flag uint32) bool

CheckFlag checks the flag status

func (*Box) GetFlags

func (box *Box) GetFlags() uint32

GetFlags returns the flags

func (*Box) GetVersion

func (box *Box) GetVersion() uint8

GetVersion returns the box version

func (*Box) RemoveFlag

func (box *Box) RemoveFlag(flag uint32)

RemoveFlag removes the flag

func (*Box) SetFlags

func (box *Box) SetFlags(uint32)

SetFlags sets the flags

func (*Box) SetVersion

func (box *Box) SetVersion(uint8)

SetVersion sets the box version

type BoxInfo

type BoxInfo struct {
	// Offset specifies an offset of the box in a file.
	Offset uint64

	// Size specifies size(bytes) of box.
	Size uint64

	// HeaderSize specifies size(bytes) of common fields which are defined as "Box" class member at ISO/IEC 14496-12.
	HeaderSize uint64

	// Type specifies box type which is represented by 4 characters.
	Type BoxType

	// ExtendToEOF is set true when Box.size is zero. It means that end of box equals to end of file.
	ExtendToEOF bool
}

BoxInfo has common infomations of box

func ExtractBox

func ExtractBox(r io.ReadSeeker, parent *BoxInfo, path BoxPath) ([]*BoxInfo, error)

func ExtractBoxes

func ExtractBoxes(r io.ReadSeeker, parent *BoxInfo, paths []BoxPath) ([]*BoxInfo, error)

func ReadBoxInfo

func ReadBoxInfo(r io.ReadSeeker) (*BoxInfo, error)

ReadBoxInfo reads common fields which are defined as "Box" class member at ISO/IEC 14496-12.

func WriteBoxInfo

func WriteBoxInfo(w io.WriteSeeker, bi *BoxInfo) (*BoxInfo, error)

WriteBoxInfo writes common fields which are defined as "Box" class member at ISO/IEC 14496-12. This function ignores bi.Offset and returns BoxInfo which contains real Offset and recalculated Size/HeaderSize.

func (*BoxInfo) SeekToEnd

func (bi *BoxInfo) SeekToEnd(s io.Seeker) (int64, error)

func (*BoxInfo) SeekToPayload

func (bi *BoxInfo) SeekToPayload(s io.Seeker) (int64, error)

func (*BoxInfo) SeekToStart

func (bi *BoxInfo) SeekToStart(s io.Seeker) (int64, error)

type BoxInfoWithPayload

type BoxInfoWithPayload struct {
	Info    BoxInfo
	Payload IBox
}

func ExtractBoxWithPayload

func ExtractBoxWithPayload(r io.ReadSeeker, parent *BoxInfo, path BoxPath) ([]*BoxInfoWithPayload, error)

func ExtractBoxesWithPayload

func ExtractBoxesWithPayload(r io.ReadSeeker, parent *BoxInfo, paths []BoxPath) ([]*BoxInfoWithPayload, error)

type BoxPath

type BoxPath []BoxType

type BoxType

type BoxType [4]byte

BoxType is mpeg box type

func BoxTypeAny added in v0.2.0

func BoxTypeAny() BoxType

func BoxTypeCtts

func BoxTypeCtts() BoxType

func BoxTypeDinf

func BoxTypeDinf() BoxType

func BoxTypeDref

func BoxTypeDref() BoxType

func BoxTypeEdts

func BoxTypeEdts() BoxType

func BoxTypeElst

func BoxTypeElst() BoxType

func BoxTypeEmsg

func BoxTypeEmsg() BoxType

func BoxTypeEsds

func BoxTypeEsds() BoxType

func BoxTypeFree

func BoxTypeFree() BoxType

func BoxTypeFtyp

func BoxTypeFtyp() BoxType

func BoxTypeHdlr

func BoxTypeHdlr() BoxType

func BoxTypeMdat

func BoxTypeMdat() BoxType

func BoxTypeMdhd

func BoxTypeMdhd() BoxType

func BoxTypeMdia

func BoxTypeMdia() BoxType

func BoxTypeMehd

func BoxTypeMehd() BoxType

func BoxTypeMeta

func BoxTypeMeta() BoxType

func BoxTypeMfhd

func BoxTypeMfhd() BoxType

func BoxTypeMfra

func BoxTypeMfra() BoxType

func BoxTypeMfro

func BoxTypeMfro() BoxType

func BoxTypeMinf

func BoxTypeMinf() BoxType

func BoxTypeMoof

func BoxTypeMoof() BoxType

func BoxTypeMoov

func BoxTypeMoov() BoxType

func BoxTypeMvex

func BoxTypeMvex() BoxType

func BoxTypeMvhd

func BoxTypeMvhd() BoxType

func BoxTypePssh

func BoxTypePssh() BoxType

func BoxTypeSbgp

func BoxTypeSbgp() BoxType

func BoxTypeSgpd

func BoxTypeSgpd() BoxType

func BoxTypeSidx added in v0.2.0

func BoxTypeSidx() BoxType

func BoxTypeSkip

func BoxTypeSkip() BoxType

func BoxTypeSmhd

func BoxTypeSmhd() BoxType

func BoxTypeStbl

func BoxTypeStbl() BoxType

func BoxTypeStco

func BoxTypeStco() BoxType

func BoxTypeStsc

func BoxTypeStsc() BoxType

func BoxTypeStsd

func BoxTypeStsd() BoxType

func BoxTypeStss

func BoxTypeStss() BoxType

func BoxTypeStsz

func BoxTypeStsz() BoxType

func BoxTypeStts

func BoxTypeStts() BoxType

func BoxTypeStyp added in v0.2.0

func BoxTypeStyp() BoxType

func BoxTypeTfdt

func BoxTypeTfdt() BoxType

func BoxTypeTfhd

func BoxTypeTfhd() BoxType

func BoxTypeTfra

func BoxTypeTfra() BoxType

func BoxTypeTkhd

func BoxTypeTkhd() BoxType

func BoxTypeTraf

func BoxTypeTraf() BoxType

func BoxTypeTrak

func BoxTypeTrak() BoxType

func BoxTypeTrex

func BoxTypeTrex() BoxType

func BoxTypeTrun

func BoxTypeTrun() BoxType

func BoxTypeUdta

func BoxTypeUdta() BoxType

func BoxTypeUrl

func BoxTypeUrl() BoxType

func BoxTypeUrn

func BoxTypeUrn() BoxType

func BoxTypeVmhd

func BoxTypeVmhd() BoxType

func StrToBoxType

func StrToBoxType(code string) BoxType

func (BoxType) GetSupportedVersions

func (boxType BoxType) GetSupportedVersions() ([]uint8, error)

func (BoxType) IsSupported

func (boxType BoxType) IsSupported() bool

func (BoxType) IsSupportedVersion

func (boxType BoxType) IsSupportedVersion(ver uint8) bool

func (BoxType) MatchWith added in v0.2.0

func (lhs BoxType) MatchWith(rhs BoxType) bool

func (BoxType) New

func (boxType BoxType) New() (IBox, error)

func (BoxType) String

func (boxType BoxType) String() string

type CompatibleBrandElem

type CompatibleBrandElem struct {
	CompatibleBrand [4]byte `mp4:"size=8,string"`
}

type Ctts

type Ctts struct {
	FullBox    `mp4:"extend"`
	EntryCount uint32      `mp4:"size=32"`
	Entries    []CttsEntry `mp4:"len=dynamic,size=64"`
}

func (*Ctts) GetFieldLength

func (ctts *Ctts) GetFieldLength(name string) uint

GetFieldLength returns length of dynamic field

func (*Ctts) GetType

func (*Ctts) GetType() BoxType

GetType returns the BoxType

type CttsEntry

type CttsEntry struct {
	SampleCount    uint32 `mp4:"size=32"`
	SampleOffsetV0 uint32 `mp4:"size=32,ver=0"`
	SampleOffsetV1 int32  `mp4:"size=32,ver=1"`
}

type DecoderConfigDescriptor

type DecoderConfigDescriptor struct {
	BaseCustomFieldObject
	ObjectTypeIndication byte   `mp4:"size=8"`
	StreamType           int8   `mp4:"size=6"`
	UpStream             bool   `mp4:"size=1"`
	Reserved             bool   `mp4:"size=1"`
	BufferSizeDB         uint32 `mp4:"size=24"`
	MaxBitrate           uint32 `mp4:"size=32"`
	AvgBitrate           uint32 `mp4:"size=32"`
}

type Descriptor

type Descriptor struct {
	BaseCustomFieldObject
	Tag                     int8                     `mp4:"size=8"` // must be 0x03
	Size                    uint32                   `mp4:"varint"`
	ESDescriptor            *ESDescriptor            `mp4:"extend,opt=dynamic"`
	DecoderConfigDescriptor *DecoderConfigDescriptor `mp4:"extend,opt=dynamic"`
	Data                    []byte                   `mp4:"size=8,opt=dynamic,len=dynamic"`
}

func (*Descriptor) GetFieldLength

func (ds *Descriptor) GetFieldLength(name string) uint

GetFieldLength returns length of dynamic field

func (*Descriptor) IsOptFieldEnabled

func (ds *Descriptor) IsOptFieldEnabled(name string) bool

func (*Descriptor) StringifyField

func (ds *Descriptor) StringifyField(name string, indent string, depth int) (string, bool)

StringifyField returns field value as string

type Dinf

type Dinf struct {
	Box
}

Dinf is ISOBMFF dinf box type

func (*Dinf) GetType

func (*Dinf) GetType() BoxType

GetType returns the BoxType

type Dref

type Dref struct {
	FullBox    `mp4:"extend"`
	EntryCount uint32 `mp4:"size=32"`
}

Dref is ISOBMFF dref box type

func (*Dref) GetType

func (*Dref) GetType() BoxType

GetType returns the BoxType

type ESDescriptor

type ESDescriptor struct {
	BaseCustomFieldObject
	ESID                 uint16 `mp4:"size=16"`
	StreamDependenceFlag bool   `mp4:"size=1"`
	UrlFlag              bool   `mp4:"size=1"`
	OcrStreamFlag        bool   `mp4:"size=1"`
	StreamPriority       int8   `mp4:"size=5"`
	DependsOnESID        uint16 `mp4:"size=16,opt=dynamic"`
	URLLength            uint8  `mp4:"size=8,opt=dynamic"`
	URLString            []byte `mp4:"size=8,len=dynamic,opt=dynamic,string"`
	OCRESID              uint16 `mp4:"size=16,opt=dynamic"`
}

func (*ESDescriptor) GetFieldLength

func (esds *ESDescriptor) GetFieldLength(name string) uint

func (*ESDescriptor) IsOptFieldEnabled

func (esds *ESDescriptor) IsOptFieldEnabled(name string) bool

type Edts

type Edts struct {
	Box
}

Edts is ISOBMFF edts box type

func (*Edts) GetType

func (*Edts) GetType() BoxType

GetType returns the BoxType

type Elst

type Elst struct {
	FullBox    `mp4:"extend"`
	EntryCount uint32      `mp4:"size=32"`
	Entries    []ElstEntry `mp4:"len=dynamic,size=dynamic"`
}

Elst is ISOBMFF elst box type

func (*Elst) GetFieldLength

func (elst *Elst) GetFieldLength(name string) uint

GetFieldLength returns length of dynamic field

func (*Elst) GetFieldSize

func (elst *Elst) GetFieldSize(name string) uint

GetFieldSize returns size of dynamic field

func (*Elst) GetType

func (*Elst) GetType() BoxType

GetType returns the BoxType

type ElstEntry

type ElstEntry struct {
	SegmentDurationV0 uint32 `mp4:"size=32,ver=0"`
	MediaTimeV0       int32  `mp4:"size=32,ver=0"`
	SegmentDurationV1 uint64 `mp4:"size=64,ver=1"`
	MediaTimeV1       int64  `mp4:"size=64,ver=1"`
	MediaRateInteger  int16  `mp4:"size=16"`
	MediaRateFraction int16  `mp4:"size=16,const=0"`
}

type Emsg

type Emsg struct {
	FullBox               `mp4:"extend"`
	SchemeIdUri           string `mp4:"string"`
	Value                 string `mp4:"string"`
	Timescale             uint32 `mp4:"size=32"`
	PresentationTimeDelta uint32 `mp4:"size=32"`
	EventDuration         uint32 `mp4:"size=32"`
	Id                    uint32 `mp4:"size=32"`
	MessageData           []byte `mp4:"size=8,string"`
}

Emsg is ISOBMFF emsg box type

func (*Emsg) GetType

func (*Emsg) GetType() BoxType

GetType returns the BoxType

type Esds

type Esds struct {
	FullBox     `mp4:"extend"`
	Descriptors []Descriptor `mp4:"array"`
}

Esds is ES descripter box

func (*Esds) GetType

func (*Esds) GetType() BoxType

GetType returns the BoxType

type FraProbeInfo

type FraProbeInfo struct {
	Tracks   []TrackInfo
	Segments []SegmentInfo
}

func ProbeFra

func ProbeFra(r io.ReadSeeker) (FraProbeInfo, error)

ProbeFra probes fragmented MP4 file

type Free

type Free FreeSpace

func (*Free) GetType

func (*Free) GetType() BoxType

type FreeSpace

type FreeSpace struct {
	Box
	Data []uint8 `mp4:"size=8"`
}

type Ftyp

type Ftyp struct {
	Box
	MajorBrand       [4]byte               `mp4:"size=8,string"`
	MinorVersion     uint32                `mp4:"size=32"`
	CompatibleBrands []CompatibleBrandElem `mp4:"size=32"` // reach to end of the box
}

Ftyp is ISOBMFF ftyp box type

func (*Ftyp) GetType

func (*Ftyp) GetType() BoxType

GetType returns the BoxType

type FullBox

type FullBox struct {
	BaseCustomFieldObject
	Version uint8   `mp4:"size=8"`
	Flags   [3]byte `mp4:"size=8"`
}

FullBox is ISOBMFF FullBox

func (*FullBox) AddFlag

func (box *FullBox) AddFlag(flag uint32)

AddFlag adds the flag

func (*FullBox) CheckFlag

func (box *FullBox) CheckFlag(flag uint32) bool

CheckFlag checks the flag status

func (*FullBox) GetFlags

func (box *FullBox) GetFlags() uint32

GetFlags returns the flags

func (*FullBox) GetVersion

func (box *FullBox) GetVersion() uint8

GetVersion returns the box version

func (*FullBox) RemoveFlag

func (box *FullBox) RemoveFlag(flag uint32)

RemoveFlag removes the flag

func (*FullBox) SetFlags

func (box *FullBox) SetFlags(flags uint32)

SetFlags sets the flags

func (*FullBox) SetVersion

func (box *FullBox) SetVersion(version uint8)

SetVersion sets the box version

type Hdlr

type Hdlr struct {
	FullBox `mp4:"extend"`
	// Predefined corresponds to component_type of QuickTime.
	// pre_defined of ISO-14496 has always zero,
	// however component_type has "mhlr" or "dhlr".
	PreDefined  uint32    `mp4:"size=32"`
	HandlerType [4]byte   `mp4:"size=8,string"`
	Reserved    [3]uint32 `mp4:"size=32,const=0"`
	Name        string    `mp4:"string=c_p"`
	Padding     []byte    `mp4:"size=8,const=0"`
}

Hdlr is ISOBMFF hdlr box type

func (*Hdlr) GetType

func (*Hdlr) GetType() BoxType

GetType returns the BoxType

func (*Hdlr) IsPString

func (hdlr *Hdlr) IsPString(name string, bytes []byte, remainingSize uint64) bool

type IAnyType

type IAnyType interface {
	IBox
	SetType(BoxType)
}

type IBox

type IBox interface {
	IImmutableBox

	// SetVersion sets the box version
	SetVersion(uint8)

	// SetFlags sets the flags
	SetFlags(uint32)

	// AddFlag adds the flag
	AddFlag(uint32)

	// RemoveFlag removes the flag
	RemoveFlag(uint32)
}

IBox is common interface of box

func UnmarshalAny

func UnmarshalAny(r io.ReadSeeker, boxType BoxType, payloadSize uint64) (box IBox, n uint64, err error)

type ICustomFieldObject

type ICustomFieldObject interface {
	// GetFieldSize returns size of dynamic field
	GetFieldSize(string) uint

	// GetFieldLength returns length of dynamic field
	GetFieldLength(string) uint

	// IsOptFieldEnabled check whether if the optional field is enabled
	IsOptFieldEnabled(string) bool

	// StringifyField returns field value as string
	StringifyField(string, string, int) (string, bool)

	IsPString(name string, bytes []byte, remainingSize uint64) bool

	BeforeUnmarshal(r io.ReadSeeker) (n uint64, override bool, err error)
}

type IImmutableBox

type IImmutableBox interface {
	ICustomFieldObject

	// GetVersion returns the box version
	GetVersion() uint8

	// GetFlags returns the flags
	GetFlags() uint32

	// CheckFlag checks the flag status
	CheckFlag(uint32) bool

	// GetType returns the BoxType
	GetType() BoxType
}

IImmutableBox is common interface of box

type Mdat

type Mdat struct {
	Box
	Data []byte `mp4:"size=8"`
}

Mdat is ISOBMFF mdat box type

func (*Mdat) GetType

func (*Mdat) GetType() BoxType

GetType returns the BoxType

type Mdhd

type Mdhd struct {
	FullBox            `mp4:"extend"`
	CreationTimeV0     uint32 `mp4:"size=32,ver=0"`
	ModificationTimeV0 uint32 `mp4:"size=32,ver=0"`
	CreationTimeV1     uint64 `mp4:"size=64,ver=1"`
	ModificationTimeV1 uint64 `mp4:"size=64,ver=1"`
	Timescale          uint32 `mp4:"size=32"`
	DurationV0         uint32 `mp4:"size=32,ver=0"`
	DurationV1         uint64 `mp4:"size=64,ver=1"`
	//
	Pad        bool    `mp4:"size=1"`
	Language   [3]byte `mp4:"size=5,iso639-2"` // ISO-639-2/T language code
	PreDefined uint16  `mp4:"size=16"`
}

Mdhd is ISOBMFF mdhd box type

func (*Mdhd) GetType

func (*Mdhd) GetType() BoxType

GetType returns the BoxType

type Mdia

type Mdia struct {
	Box
}

Mdia is ISOBMFF mdia box type

func (*Mdia) GetType

func (*Mdia) GetType() BoxType

GetType returns the BoxType

type Mehd

type Mehd struct {
	FullBox            `mp4:"extend"`
	FragmentDurationV0 uint32 `mp4:"size=32,ver=0"`
	FragmentDurationV1 uint64 `mp4:"size=64,ver=1"`
}

Mehd is ISOBMFF mehd box type

func (*Mehd) GetType

func (*Mehd) GetType() BoxType

GetType returns the BoxType

type Meta

type Meta struct {
	FullBox `mp4:"extend"`
}

Meta is ISOBMFF meta box type

func (*Meta) BeforeUnmarshal

func (meta *Meta) BeforeUnmarshal(r io.ReadSeeker) (n uint64, override bool, err error)

func (*Meta) GetType

func (*Meta) GetType() BoxType

GetType returns the BoxType

type Mfhd

type Mfhd struct {
	FullBox        `mp4:"extend"`
	SequenceNumber uint32 `mp4:"size=32"`
}

Mfhd is ISOBMFF mfhd box type

func (*Mfhd) GetType

func (*Mfhd) GetType() BoxType

GetType returns the BoxType

type Mfra

type Mfra struct {
	Box
}

Mfra is ISOBMFF mfra box type

func (*Mfra) GetType

func (*Mfra) GetType() BoxType

GetType returns the BoxType

type Mfro

type Mfro struct {
	FullBox `mp4:"extend"`
	Size    uint32 `mp4:"size=32"`
}

Mfro is ISOBMFF mfro box type

func (*Mfro) GetType

func (*Mfro) GetType() BoxType

GetType returns the BoxType

type Minf

type Minf struct {
	Box
}

Minf is ISOBMFF minf box type

func (*Minf) GetType

func (*Minf) GetType() BoxType

GetType returns the BoxType

type Moof

type Moof struct {
	Box
}

Moof is ISOBMFF moof box type

func (*Moof) GetType

func (*Moof) GetType() BoxType

GetType returns the BoxType

type Moov

type Moov struct {
	Box
}

Moov is ISOBMFF moov box type

func (*Moov) GetType

func (*Moov) GetType() BoxType

GetType returns the BoxType

type Mvex

type Mvex struct {
	Box
}

Mvex is ISOBMFF mvex box type

func (*Mvex) GetType

func (*Mvex) GetType() BoxType

GetType returns the BoxType

type Mvhd

type Mvhd struct {
	FullBox            `mp4:"extend"`
	CreationTimeV0     uint32    `mp4:"size=32,ver=0"`
	ModificationTimeV0 uint32    `mp4:"size=32,ver=0"`
	CreationTimeV1     uint64    `mp4:"size=64,ver=1"`
	ModificationTimeV1 uint64    `mp4:"size=64,ver=1"`
	Timescale          uint32    `mp4:"size=32"`
	DurationV0         uint32    `mp4:"size=32,ver=0"`
	DurationV1         uint64    `mp4:"size=64,ver=1"`
	Rate               int32     `mp4:"size=32"` // template=0x00010000
	Volume             int16     `mp4:"size=16"` // template=0x0100
	Reserved           int16     `mp4:"size=16,const=0"`
	Reserved2          [2]uint32 `mp4:"size=32,const=0"`
	Matrix             [9]int32  `mp4:"size=32,hex"` // template={ 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 }
	PreDefined         [6]int32  `mp4:"size=32"`
	NextTrackID        uint32    `mp4:"size=32"`
}

Mvhd is ISOBMFF mvhd box type

func (*Mvhd) GetType

func (*Mvhd) GetType() BoxType

GetType returns the BoxType

type PixelAspectRatioBox

type PixelAspectRatioBox struct {
	AnyTypeBox
	HSpacing uint32 `mp4:"size=32"`
	VSpacing uint32 `mp4:"size=32"`
}

type Pssh

type Pssh struct {
	FullBox  `mp4:"extend"`
	SystemID [16]byte  `mp4:"size=8"`
	KIDCount uint32    `mp4:"size=32,nver=0"`
	KIDs     []PsshKID `mp4:"nver=0,len=dynamic,size=128"`
	DataSize int32     `mp4:"size=32"`
	Data     []byte    `mp4:"size=8,len=dynamic"`
}

Pssh is ISOBMFF pssh box type

func (*Pssh) GetFieldLength

func (pssh *Pssh) GetFieldLength(name string) uint

GetFieldLength returns length of dynamic field

func (*Pssh) GetType

func (*Pssh) GetType() BoxType

GetType returns the BoxType

func (*Pssh) StringifyField

func (pssh *Pssh) StringifyField(name string, indent string, depth int) (string, bool)

StringifyField returns field value as string

type PsshKID

type PsshKID struct {
	KID [16]byte `mp4:"size=8"`
}

type ReadHandle

type ReadHandle struct {
	Params      []interface{}
	BoxInfo     BoxInfo
	Path        BoxPath
	ReadPayload func() (box IBox, n uint64, err error)
	ReadData    func(io.Writer) (n uint64, err error)
	Expand      func(params ...interface{}) (vals []interface{}, err error)
}

type ReadHandler

type ReadHandler func(handle *ReadHandle) (val interface{}, err error)

type SampleEntry

type SampleEntry struct {
	AnyTypeBox
	Reserved           [6]uint8 `mp4:"size=8,const=0"`
	DataReferenceIndex uint16   `mp4:"size=16"`
}

type Sbgp

type Sbgp struct {
	FullBox      `mp4:"extend"`
	GroupingType uint32 `mp4:"size=32"`

	EntryCount uint32      `mp4:"size=32"`
	Entries    []SbgpEntry `mp4:"len=dynamic,size=64"`
	// contains filtered or unexported fields
}

func (*Sbgp) GetFieldLength

func (sbgp *Sbgp) GetFieldLength(name string) uint

func (*Sbgp) GetType

func (*Sbgp) GetType() BoxType

type SbgpEntry

type SbgpEntry struct {
	SampleCount           uint32 `mp4:"size=32"`
	GroupDescriptionIndex uint32 `mp4:"size=32"`
}

type SegmentInfo

type SegmentInfo struct {
	TrackID               uint32
	MoofOffset            uint64
	BaseMediaDecodeTime   uint64
	DefaultSampleDuration uint32
	SampleCount           uint32
	Duration              uint32
}

type Sgpd

type Sgpd struct {
	FullBox                       `mp4:"extend"`
	GroupingType                  [4]byte `mp4:"size=8,string"`
	DefaultLength                 uint32  `mp4:"size=32,ver=1"`
	DefaultSampleDescriptionIndex uint32  `mp4:"size=32,ver=2"`
	EntryCount                    uint32  `mp4:"size=32"`
	RollDistances                 []int16 `mp4:"size=16,opt=dynamic"`
	//AlternativeStartupEntries     []AlternativeStartupEntry `mp4:"size=dynamic,opt=dynamic"`
	VisualRandomAccessEntries []VisualRandomAccessEntry `mp4:"size=dynamic,opt=dynamic"`
	TemporalLevelEntries      []TemporalLevelEntry      `mp4:"size=dynamic,opt=dynamic"`
	Unsupported               []byte                    `mp4:"size=8"`
}

func (*Sgpd) GetFieldSize

func (sgpd *Sgpd) GetFieldSize(name string) uint

func (*Sgpd) GetType

func (*Sgpd) GetType() BoxType

func (*Sgpd) IsOptFieldEnabled

func (sgpd *Sgpd) IsOptFieldEnabled(name string) bool

type Sidx added in v0.2.0

type Sidx struct {
	FullBox                    `mp4:"extend"`
	ReferenceID                uint32          `mp4:"size=32"`
	Timescale                  uint32          `mp4:"size=32"`
	EarliestPresentationTimeV0 uint32          `mp4:"size=32,ver=0"`
	FirstOffsetV0              uint32          `mp4:"size=32,ver=0"`
	EarliestPresentationTimeV1 uint64          `mp4:"size=64,nver=0"`
	FirstOffsetV1              uint64          `mp4:"size=64,nver=0"`
	Reserved                   uint16          `mp4:"size=16,const=0"`
	ReferenceCount             uint16          `mp4:"size=16"`
	References                 []SidxReference `mp4:"size=96,len=dynamic"`
}

func (*Sidx) GetFieldLength added in v0.2.0

func (sidx *Sidx) GetFieldLength(name string) uint

func (*Sidx) GetType added in v0.2.0

func (*Sidx) GetType() BoxType

type SidxReference added in v0.2.0

type SidxReference struct {
	ReferenceType      bool   `mp4:"size=1"`
	ReferencedSize     uint32 `mp4:"size=31"`
	SubsegmentDuration uint32 `mp4:"size=32"`
	StartsWithSAP      bool   `mp4:"size=1"`
	SAPType            uint32 `mp4:"size=3"`
	SAPDeltaTime       uint32 `mp4:"size=28"`
}

type Skip

type Skip FreeSpace

func (*Skip) GetType

func (*Skip) GetType() BoxType

type Smhd

type Smhd struct {
	FullBox  `mp4:"extend"`
	Balance  int16  `mp4:"size=16"` // template=0
	Reserved uint16 `mp4:"size=16,const=0"`
}

func (*Smhd) GetType

func (*Smhd) GetType() BoxType

type Stbl

type Stbl struct {
	Box
}

Stbl is ISOBMFF stbl box type

func (*Stbl) GetType

func (*Stbl) GetType() BoxType

GetType returns the BoxType

type Stco

type Stco struct {
	FullBox     `mp4:"extend"`
	EntryCount  uint32   `mp4:"size=32"`
	ChunkOffset []uint32 `mp4:"size=32,len=dynamic"`
}

Stco is ISOBMFF stco box type

func (*Stco) GetFieldLength

func (stco *Stco) GetFieldLength(name string) uint

GetFieldLength returns length of dynamic field

func (*Stco) GetType

func (*Stco) GetType() BoxType

GetType returns the BoxType

type StringType

type StringType int
const (
	StringType_C StringType = iota
	StringType_C_P
)

type Stsc

type Stsc struct {
	FullBox    `mp4:"extend"`
	EntryCount uint32      `mp4:"size=32"`
	Entries    []StscEntry `mp4:"len=dynamic,size=96"`
}

Stsc is ISOBMFF stsc box type

func (*Stsc) GetFieldLength

func (stsc *Stsc) GetFieldLength(name string) uint

GetFieldLength returns length of dynamic field

func (*Stsc) GetType

func (*Stsc) GetType() BoxType

GetType returns the BoxType

type StscEntry

type StscEntry struct {
	FirstChunk             uint32 `mp4:"size=32"`
	SamplesPerChunk        uint32 `mp4:"size=32"`
	SampleDescriptionIndex uint32 `mp4:"size=32"`
}

type Stsd

type Stsd struct {
	FullBox    `mp4:"extend"`
	EntryCount uint32 `mp4:"size=32"`
}

Stsd is ISOBMFF stsd box type

func (*Stsd) GetType

func (*Stsd) GetType() BoxType

GetType returns the BoxType

type Stss

type Stss struct {
	FullBox      `mp4:"extend"`
	EntryCount   uint32   `mp4:"size=32"`
	SampleNumber []uint32 `mp4:"len=dynamic,size=32"`
}

func (*Stss) GetFieldLength

func (stss *Stss) GetFieldLength(name string) uint

GetFieldLength returns length of dynamic field

func (*Stss) GetType

func (*Stss) GetType() BoxType

GetType returns the BoxType

type Stsz

type Stsz struct {
	FullBox     `mp4:"extend"`
	SampleSize  uint32   `mp4:"size=32"`
	SampleCount uint32   `mp4:"size=32"`
	EntrySize   []uint32 `mp4:"size=32,len=dynamic"`
}

Stsz is ISOBMFF stsz box type

func (*Stsz) GetFieldLength

func (stsz *Stsz) GetFieldLength(name string) uint

GetFieldLength returns length of dynamic field

func (*Stsz) GetType

func (*Stsz) GetType() BoxType

GetType returns the BoxType

type Stts

type Stts struct {
	FullBox    `mp4:"extend"`
	EntryCount uint32      `mp4:"size=32"`
	Entries    []SttsEntry `mp4:"len=dynamic,size=64"`
}

Stts is ISOBMFF stts box type

func (*Stts) GetFieldLength

func (stts *Stts) GetFieldLength(name string) uint

GetFieldLength returns length of dynamic field

func (*Stts) GetType

func (*Stts) GetType() BoxType

GetType returns the BoxType

type SttsEntry

type SttsEntry struct {
	SampleCount uint32 `mp4:"size=32"`
	SampleDelta uint32 `mp4:"size=32"`
}

type Styp added in v0.2.0

type Styp struct {
	Box
	MajorBrand       [4]byte               `mp4:"size=8,string"`
	MinorVersion     uint32                `mp4:"size=32"`
	CompatibleBrands []CompatibleBrandElem `mp4:"size=32"` // reach to end of the box
}

func (*Styp) GetType added in v0.2.0

func (*Styp) GetType() BoxType

type TemporalLevelEntry

type TemporalLevelEntry struct {
	LevelUndependentlyUecodable bool  `mp4:"size=1"`
	Reserved                    uint8 `mp4:"size=7,const=0"`
}

type Tfdt

type Tfdt struct {
	FullBox               `mp4:"extend"`
	BaseMediaDecodeTimeV0 uint32 `mp4:"size=32,ver=0"`
	BaseMediaDecodeTimeV1 uint64 `mp4:"size=64,ver=1"`
}

Tfdt is ISOBMFF tfdt box type

func (*Tfdt) GetType

func (*Tfdt) GetType() BoxType

GetType returns the BoxType

type Tfhd

type Tfhd struct {
	FullBox `mp4:"extend"`
	TrackID uint32 `mp4:"size=32"`

	// optional
	BaseDataOffset         uint64 `mp4:"size=64,opt=0x000001"`
	SampleDescriptionIndex uint32 `mp4:"size=32,opt=0x000002"`
	DefaultSampleDuration  uint32 `mp4:"size=32,opt=0x000008"`
	DefaultSampleSize      uint32 `mp4:"size=32,opt=0x000010"`
	DefaultSampleFlags     uint32 `mp4:"size=32,opt=0x000020,hex"`
}

Tfhd is ISOBMFF tfhd box type

func (*Tfhd) GetType

func (*Tfhd) GetType() BoxType

GetType returns the BoxType

type Tfra

type Tfra struct {
	FullBox               `mp4:"extend"`
	TrackID               uint32      `mp4:"size=32"`
	Reserved              uint32      `mp4:"size=26,const=0"`
	LengthSizeOfTrafNum   byte        `mp4:"size=2"`
	LengthSizeOfTrunNum   byte        `mp4:"size=2"`
	LengthSizeOfSampleNum byte        `mp4:"size=2"`
	NumberOfEntry         uint32      `mp4:"size=32"`
	Entries               []TfraEntry `mp4:"len=dynamic,size=dynamic"`
}

Tfra is ISOBMFF tfra box type

func (*Tfra) GetFieldLength

func (tfra *Tfra) GetFieldLength(name string) uint

GetFieldLength returns length of dynamic field

func (*Tfra) GetFieldSize

func (tfra *Tfra) GetFieldSize(name string) uint

GetFieldSize returns size of dynamic field

func (*Tfra) GetType

func (*Tfra) GetType() BoxType

GetType returns the BoxType

type TfraEntry

type TfraEntry struct {
	TimeV0       uint32 `mp4:"size=32,ver=0"`
	MoofOffsetV0 uint32 `mp4:"size=32,ver=0"`
	TimeV1       uint64 `mp4:"size=64,ver=1"`
	MoofOffsetV1 uint64 `mp4:"size=64,ver=1"`
	TrafNumber   uint32 `mp4:"size=dynamic"`
	TrunNumber   uint32 `mp4:"size=dynamic"`
	SampleNumber uint32 `mp4:"size=dynamic"`
}

type Tkhd

type Tkhd struct {
	FullBox `mp4:"extend"`
	// Version 0
	CreationTimeV0     uint32 `mp4:"size=32,ver=0"`
	ModificationTimeV0 uint32 `mp4:"size=32,ver=0"`
	TrackIDV0          uint32 `mp4:"size=32,ver=0"`
	ReservedV0         uint32 `mp4:"size=32,ver=0,const=0"`
	DurationV0         uint32 `mp4:"size=32,ver=0"`
	// Version 1
	CreationTimeV1     uint64 `mp4:"size=64,ver=1"`
	ModificationTimeV1 uint64 `mp4:"size=64,ver=1"`
	TrackIDV1          uint32 `mp4:"size=32,ver=1"`
	ReservedV1         uint32 `mp4:"size=32,ver=1,const=0"`
	DurationV1         uint64 `mp4:"size=64,ver=1"`
	//
	Reserved       [2]uint32 `mp4:"size=32,const=0"`
	Layer          int16     `mp4:"size=16"` // template=0
	AlternateGroup int16     `mp4:"size=16"` // template=0
	Volume         int16     `mp4:"size=16"` // template={if track_is_audio 0x0100 else 0}
	Reserved2      uint16    `mp4:"size=16,const=0"`
	Matrix         [9]int32  `mp4:"size=32,hex"` // template={ 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 };
	Width          uint32    `mp4:"size=32"`
	Height         uint32    `mp4:"size=32"`
}

Tkhd is ISOBMFF tkhd box type

func (*Tkhd) GetType

func (*Tkhd) GetType() BoxType

GetType returns the BoxType

type TrackInfo

type TrackInfo struct {
	TrackID   uint32
	Timescale uint32
}

type Traf

type Traf struct {
	Box
}

Traf is ISOBMFF traf box type

func (*Traf) GetType

func (*Traf) GetType() BoxType

GetType returns the BoxType

type Trak

type Trak struct {
	Box
}

Trak is ISOBMFF trak box type

func (*Trak) GetType

func (*Trak) GetType() BoxType

GetType returns the BoxType

type Trex

type Trex struct {
	FullBox                       `mp4:"extend"`
	TrackID                       uint32 `mp4:"size=32"`
	DefaultSampleDescriptionIndex uint32 `mp4:"size=32"`
	DefaultSampleDuration         uint32 `mp4:"size=32"`
	DefaultSampleSize             uint32 `mp4:"size=32"`
	DefaultSampleFlags            uint32 `mp4:"size=32,hex"`
}

Trex is ISOBMFF trex box type

func (*Trex) GetType

func (*Trex) GetType() BoxType

GetType returns the BoxType

type Trun

type Trun struct {
	FullBox     `mp4:"extend"`
	SampleCount uint32 `mp4:"size=32"`

	// optional fields
	DataOffset       int32       `mp4:"size=32,opt=0x000001"`
	FirstSampleFlags uint32      `mp4:"size=32,opt=0x000004,hex"`
	Entries          []TrunEntry `mp4:"len=dynamic,size=dynamic"`
}

Trun is ISOBMFF trun box type

func (*Trun) GetFieldLength

func (trun *Trun) GetFieldLength(name string) uint

GetFieldLength returns length of dynamic field

func (*Trun) GetFieldSize

func (trun *Trun) GetFieldSize(name string) uint

GetFieldSize returns size of dynamic field

func (*Trun) GetType

func (*Trun) GetType() BoxType

GetType returns the BoxType

type TrunEntry

type TrunEntry struct {
	SampleDuration                uint32 `mp4:"size=32,opt=0x000100"`
	SampleSize                    uint32 `mp4:"size=32,opt=0x000200"`
	SampleFlags                   uint32 `mp4:"size=32,opt=0x000400,hex"`
	SampleCompositionTimeOffsetV0 uint32 `mp4:"size=32,opt=0x000800,ver=0"`
	SampleCompositionTimeOffsetV1 int32  `mp4:"size=32,opt=0x000800,nver=0"`
}

type Udta

type Udta struct {
	Box
}

Udta is ISOBMFF udta box type

func (*Udta) GetType

func (*Udta) GetType() BoxType

GetType returns the BoxType

type Url

type Url struct {
	FullBox  `mp4:"extend"`
	Location string `mp4:"string,nopt=0x000001"`
}

func (*Url) GetType

func (*Url) GetType() BoxType

type Urn

type Urn struct {
	FullBox  `mp4:"extend"`
	Name     string `mp4:"string,nopt=0x000001"`
	Location string `mp4:"string,nopt=0x000001"`
}

func (*Urn) GetType

func (*Urn) GetType() BoxType

type VisualRandomAccessEntry

type VisualRandomAccessEntry struct {
	NumLeadingSamplesKnown bool  `mp4:"size=1"`
	NumLeadingSamples      uint8 `mp4:"size=7"`
}

type VisualSampleEntry

type VisualSampleEntry struct {
	SampleEntry     `mp4:"extend"`
	PreDefined      uint16    `mp4:"size=16"`
	Reserved        uint16    `mp4:"size=16,const=0"`
	PreDefined2     [3]uint32 `mp4:"size=32"`
	Width           uint16    `mp4:"size=16"`
	Height          uint16    `mp4:"size=16"`
	Horizresolution uint32    `mp4:"size=32"`
	Vertresolution  uint32    `mp4:"size=32"`
	Reserved2       uint32    `mp4:"size=32,const=0"`
	FrameCount      uint16    `mp4:"size=16"`
	Compressorname  [32]byte  `mp4:"size=8"`
	Depth           uint16    `mp4:"size=16"`
	PreDefined3     int16     `mp4:"size=16"`
}

func (*VisualSampleEntry) StringifyField

func (vse *VisualSampleEntry) StringifyField(name string, indent string, depth int) (string, bool)

StringifyField returns field value as string

type Vmhd

type Vmhd struct {
	FullBox      `mp4:"extend"`
	Graphicsmode uint16    `mp4:"size=16"` // template=0
	Opcolor      [3]uint16 `mp4:"size=16"` // template={0, 0, 0}
}

Vmhd is ISOBMFF vmhd box type

func (*Vmhd) GetType

func (*Vmhd) GetType() BoxType

GetType returns the BoxType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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