Documentation
¶
Overview ¶
Package mp4 implements encoding and decoding of ISO Base Media File Format (MP4) boxes.
Index ¶
- Variables
- func Encode(box *Box, buf []byte, offset int) (int, error)
- func EncodeToBuf(box *Box, buf []byte) ([]byte, error)
- func EncodeToBytes(box *Box) ([]byte, error)
- func EncodingLength(box *Box) uint64
- type AudioSampleEntry
- type AvcC
- type Box
- type BoxType
- type CTTSEntry
- type Co64
- type Ctts
- type DrefBox
- type DrefEntry
- type Elst
- type ElstEntry
- type Esds
- type Ftyp
- type Hdlr
- type Headers
- type Mdat
- type Mdhd
- type Mehd
- type Mfhd
- type Mvhd
- type STSCEntry
- type STTSEntry
- type Smhd
- type Stco
- type Stsc
- type Stsd
- type Stsz
- type Stts
- type Tfdt
- type Tfhd
- type Tkhd
- type Trex
- type Trun
- type TrunEntry
- type VisualSampleEntry
- type Vmhd
Constants ¶
This section is empty.
Variables ¶
var ( TypeFtyp = newBoxType("ftyp") TypeMoov = newBoxType("moov") TypeMvhd = newBoxType("mvhd") TypeTrak = newBoxType("trak") TypeTkhd = newBoxType("tkhd") TypeTref = newBoxType("tref") TypeTrgr = newBoxType("trgr") TypeEdts = newBoxType("edts") TypeElst = newBoxType("elst") TypeMdia = newBoxType("mdia") TypeMdhd = newBoxType("mdhd") TypeHdlr = newBoxType("hdlr") TypeElng = newBoxType("elng") TypeMinf = newBoxType("minf") TypeVmhd = newBoxType("vmhd") TypeSmhd = newBoxType("smhd") TypeHmhd = newBoxType("hmhd") TypeSthd = newBoxType("sthd") TypeNmhd = newBoxType("nmhd") TypeDinf = newBoxType("dinf") TypeDref = newBoxType("dref") TypeStbl = newBoxType("stbl") TypeStsd = newBoxType("stsd") TypeStts = newBoxType("stts") TypeCtts = newBoxType("ctts") TypeCslg = newBoxType("cslg") TypeStsc = newBoxType("stsc") TypeStsz = newBoxType("stsz") TypeStz2 = newBoxType("stz2") TypeStco = newBoxType("stco") TypeCo64 = newBoxType("co64") TypeStss = newBoxType("stss") TypeStsh = newBoxType("stsh") TypePadb = newBoxType("padb") TypeStdp = newBoxType("stdp") TypeSdtp = newBoxType("sdtp") TypeSbgp = newBoxType("sbgp") TypeSgpd = newBoxType("sgpd") TypeSubs = newBoxType("subs") TypeSaiz = newBoxType("saiz") TypeSaio = newBoxType("saio") TypeMvex = newBoxType("mvex") TypeMehd = newBoxType("mehd") TypeTrex = newBoxType("trex") TypeLeva = newBoxType("leva") TypeMoof = newBoxType("moof") TypeMfhd = newBoxType("mfhd") TypeTraf = newBoxType("traf") TypeTfhd = newBoxType("tfhd") TypeTfdt = newBoxType("tfdt") TypeTrun = newBoxType("trun") TypeMeta = newBoxType("meta") TypeUdta = newBoxType("udta") TypeMdat = newBoxType("mdat") TypeAvc1 = newBoxType("avc1") TypeAvcC = newBoxType("avcC") TypeMp4a = newBoxType("mp4a") TypeEsds = newBoxType("esds") )
Known box types.
Functions ¶
func Encode ¶
Encode encodes the box into buf starting at offset. Returns the number of bytes written.
func EncodeToBuf ¶
EncodeToBuf encodes the box into the provided buffer slice. The buffer will be grown if needed. Returns the slice containing the encoded data.
func EncodeToBytes ¶
EncodeToBytes is a convenience that allocates a buffer and encodes the box.
func EncodingLength ¶
EncodingLength computes the total encoded size of the box; populates Size fields.
Types ¶
type AudioSampleEntry ¶
type AudioSampleEntry struct {
DataReferenceIndex uint16
ChannelCount uint16
SampleSize uint16
SampleRate uint32
Children []*Box
}
AudioSampleEntry represents an audio sample entry (e.g. mp4a).
type Box ¶
type Box struct {
Type BoxType
Size uint64 // total size including header
Version uint8
Flags uint32
HasFullBox bool
// Container children (keyed by type). For array children, use Children.
Children map[BoxType][]*Box
// OtherBoxes holds children not recognized by the container definition.
OtherBoxes []*Box
// Raw buffer for unknown box types.
Buffer []byte
// Typed payload: only one of these is non-nil for leaf boxes.
Ftyp *Ftyp
Mvhd *Mvhd
Tkhd *Tkhd
Mdhd *Mdhd
Vmhd *Vmhd
Smhd *Smhd
Stsd *Stsd
Stsz *Stsz
Stco *Stco // also used for stss
Co64 *Co64
Stts *Stts
Ctts *Ctts
Stsc *Stsc
Dref *DrefBox
Elst *Elst
Hdlr *Hdlr
Mehd *Mehd
Trex *Trex
Mfhd *Mfhd
Tfhd *Tfhd
Tfdt *Tfdt
Trun *Trun
Mdat *Mdat
AvcC *AvcC
Visual *VisualSampleEntry
Audio *AudioSampleEntry
Esds *Esds
}
Box represents an MP4 box (atom).
type DrefBox ¶
type DrefBox struct {
Entries []DrefEntry
}
DrefBox represents the data reference box.
type Headers ¶
type Headers struct {
Size uint64
HeaderSize int
ContentLen int
Type BoxType
Version uint8
Flags uint32
}
Headers holds parsed box header information.
type Mdhd ¶
type Mdhd struct {
CTime [8]byte // 4 or 8 bytes depending on version
MTime [8]byte
TimeScale uint32
Duration uint64
Language uint16
Quality uint16
V1 bool // true if version 1
}
Mdhd represents the media header box.
type Mehd ¶
type Mehd struct {
FragmentDuration uint32
}
Mehd represents the movie extends header box.
type Mfhd ¶
type Mfhd struct {
SequenceNumber uint32
}
Mfhd represents the movie fragment header box.
type Mvhd ¶
type Mvhd struct {
CTime [4]byte // raw 4-byte date
MTime [4]byte
TimeScale uint32
Duration uint32
PreferredRate [4]byte // raw 16.16 fixed
PreferredVolume [2]byte // raw 8.8 fixed
Matrix [36]byte
PreviewTime uint32
PreviewDuration uint32
PosterTime uint32
SelectionTime uint32
SelectionDuration uint32
CurrentTime uint32
NextTrackId uint32
}
Mvhd represents the movie header box.
type Stco ¶
type Stco struct {
Entries []uint32
}
Stco represents the chunk offset box (also used for stss).
type Tfdt ¶
type Tfdt struct {
BaseMediaDecodeTime uint32
}
Tfdt represents the track fragment decode time box.
type Tkhd ¶
type Tkhd struct {
CTime [4]byte
MTime [4]byte
TrackId uint32
Duration uint32
Layer uint16
AlternateGroup uint16
Volume uint16
Matrix [36]byte
TrackWidth uint32
TrackHeight uint32
}
Tkhd represents the track header box.
type Trex ¶
type Trex struct {
TrackId uint32
DefaultSampleDescriptionIndex uint32
DefaultSampleDuration uint32
DefaultSampleSize uint32
DefaultSampleFlags uint32
}
Trex represents the track extends box.
type TrunEntry ¶
type TrunEntry struct {
SampleDuration uint32
SampleSize uint32
SampleFlags uint32
SampleCompositionTimeOffset int32
}
TrunEntry is a track run entry.