Documentation ¶
Overview ¶
Package mp4 implements encoding/decoding of MP4 media.
Index ¶
- Constants
- Variables
- func EncodeHeader(b Box, w io.Writer) error
- type Box
- func DecodeBox(h BoxHeader, r io.Reader) (Box, error)
- func DecodeContainer(r io.Reader) ([]Box, error)
- func DecodeCtts(r io.Reader) (Box, error)
- func DecodeDinf(r io.Reader) (Box, error)
- func DecodeDref(r io.Reader) (Box, error)
- func DecodeEdts(r io.Reader) (Box, error)
- func DecodeElst(r io.Reader) (Box, error)
- func DecodeFree(r io.Reader) (Box, error)
- func DecodeFtyp(r io.Reader) (Box, error)
- func DecodeHdlr(r io.Reader) (Box, error)
- func DecodeIods(r io.Reader) (Box, error)
- func DecodeMdat(r io.Reader) (Box, error)
- func DecodeMdhd(r io.Reader) (Box, error)
- func DecodeMdia(r io.Reader) (Box, error)
- func DecodeMeta(r io.Reader) (Box, error)
- func DecodeMinf(r io.Reader) (Box, error)
- func DecodeMoov(r io.Reader) (Box, error)
- func DecodeMvhd(r io.Reader) (Box, error)
- func DecodeSmhd(r io.Reader) (Box, error)
- func DecodeStbl(r io.Reader) (Box, error)
- func DecodeStco(r io.Reader) (Box, error)
- func DecodeStsc(r io.Reader) (Box, error)
- func DecodeStsd(r io.Reader) (Box, error)
- func DecodeStss(r io.Reader) (Box, error)
- func DecodeStsz(r io.Reader) (Box, error)
- func DecodeStts(r io.Reader) (Box, error)
- func DecodeTkhd(r io.Reader) (Box, error)
- func DecodeTrak(r io.Reader) (Box, error)
- func DecodeUdta(r io.Reader) (Box, error)
- func DecodeVmhd(r io.Reader) (Box, error)
- type BoxDecoder
- type BoxHeader
- type CttsBox
- type DinfBox
- type DrefBox
- type EdtsBox
- type ElstBox
- type Fixed16
- type Fixed32
- type FreeBox
- type FtypBox
- type HdlrBox
- type IodsBox
- type MP4
- type MdatBox
- type MdhdBox
- type MdiaBox
- type MetaBox
- type MinfBox
- type MoovBox
- type MvhdBox
- type SmhdBox
- type StblBox
- type StcoBox
- type StscBox
- type StsdBox
- type StssBox
- type StszBox
- type SttsBox
- type TkhdBox
- type TrakBox
- type UdtaBox
- type VmhdBox
Constants ¶
const (
BoxHeaderSize = 8
)
Variables ¶
Functions ¶
Types ¶
type CttsBox ¶
type CttsBox struct { Version byte Flags [3]byte SampleCount []uint32 SampleOffset []uint32 // int32 for version 1 }
Composition Time to Sample Box (ctts - optional)
Contained in: Sample Table Box (stbl)
Status: version 0 decoded. version 1 uses int32 for offsets
type DinfBox ¶
type DinfBox struct {
Dref *DrefBox
}
Data Information Box (dinf - mandatory)
Contained in : Media Information Box (minf) or Meta Box (meta)
Status : decoded
type DrefBox ¶
Data Reference Box (dref - mandatory)
Contained id: Data Information Box (dinf)
Status: not decoded
Defines the location of the media data. If the data for the track is located in the same file it contains nothing useful.
type EdtsBox ¶
type EdtsBox struct {
Elst *ElstBox
}
Edit Box (edts - optional)
Contained in: Track Box ("trak")
Status: decoded
The edit box maps the presentation timeline to the media-time line
type ElstBox ¶
type ElstBox struct { Version byte Flags [3]byte SegmentDuration, MediaTime []uint32 // should be uint32/int32 for version 0 and uint64/int32 for version 1 MediaRateInteger, MediaRateFraction []uint16 // should be int16 }
Edit List Box (elst - optional)
Contained in : Edit Box (edts)
Status: version 0 decoded. version 1 not supported
type FreeBox ¶
type FreeBox struct {
// contains filtered or unexported fields
}
File Type Box (ftyp - mandatory)
Status: decoded
type HdlrBox ¶
Handler Reference Box (hdlr - mandatory)
Contained in: Media Box (mdia) or Meta Box (meta)
Status: decoded
This box describes the type of data contained in the trak.
HandlerType can be : "vide" (video track), "soun" (audio track), "hint" (hint track), "meta" (timed Metadata track), "auxv" (auxiliary video track).
type IodsBox ¶
type IodsBox struct {
// contains filtered or unexported fields
}
Object Descriptor Container Box (iods - optional)
Contained in : Movie Box (‘moov’)
Status: not decoded
type MP4 ¶
type MP4 struct { Ftyp *FtypBox Moov *MoovBox Mdat *MdatBox // contains filtered or unexported fields }
A MPEG-4 media
A MPEG-4 media contains three main boxes :
ftyp : the file type box moov : the movie box (meta-data) mdat : the media data (chunks and samples)
Other boxes can also be present (pdin, moof, mfra, free, ...), but are not decoded.
type MdatBox ¶
type MdatBox struct { ContentSize uint32 // contains filtered or unexported fields }
Media Data Box (mdat - optional)
Status: not decoded
The mdat box contains media chunks/samples.
It is not read, only the io.Reader is stored, and will be used to Encode (io.Copy) the box to a io.Writer.
type MdhdBox ¶
type MdhdBox struct { Version byte Flags [3]byte CreationTime uint32 ModificationTime uint32 Timescale uint32 Duration uint32 Language uint16 }
Media Header Box (mdhd - mandatory)
Contained in : Media Box (mdia)
Status : only version 0 is decoded. version 1 is not supported
Timescale defines the timescale used for tracks. Language is a ISO-639-2/T language code stored as 1bit padding + [3]int5
type MdiaBox ¶
Media Box (mdia - mandatory)
Contained in : Track Box (trak)
Status: decoded
Contains all information about the media data.
type MinfBox ¶
Media Information Box (minf - mandatory)
Contained in : Media Box (mdia)
Status: partially decoded (hmhd - hint tracks - and nmhd - null media - are ignored)
type MoovBox ¶
Movie Box (moov - mandatory)
Status: partially decoded (anything other than mvhd, iods, trak or udta is ignored)
Contains all meta-data. To be able to stream a file, the moov box should be placed before the mdat box.
type MvhdBox ¶
type MvhdBox struct { Version byte Flags [3]byte CreationTime uint32 ModificationTime uint32 Timescale uint32 Duration uint32 NextTrackId uint32 Rate Fixed32 Volume Fixed16 // contains filtered or unexported fields }
Movie Header Box (mvhd - mandatory)
Contained in : Movie Box (‘moov’)
Status: version 0 is partially decoded. version 1 is not supported
Contains all media information (duration, ...).
Duration is measured in "time units", and timescale defines the number of time units per second.
Only version 0 is decoded.
type SmhdBox ¶
Sound Media Header Box (smhd - mandatory for sound tracks)
Contained in : Media Information Box (minf)
Status: decoded
type StblBox ¶
type StblBox struct { Stsd *StsdBox Stts *SttsBox Stss *StssBox Stsc *StscBox Stsz *StszBox Stco *StcoBox Ctts *CttsBox }
Sample Table Box (stbl - mandatory)
Contained in : Media Information Box (minf)
Status: partially decoded (anything other than stsd, stts, stsc, stss, stsz, stco, ctts is ignored)
The table contains all information relevant to data samples (times, chunks, sizes, ...)
type StcoBox ¶
Chunk Offset Box (stco - mandatory)
Contained in : Sample Table box (stbl)
Status: decoded
This is the 32bits version of the box, the 64bits version (co64) is not decoded.
The table contains the offsets (starting at the beginning of the file) for each chunk of data for the current track. A chunk contains samples, the table defining the allocation of samples to each chunk is stsc.
type StscBox ¶
type StscBox struct { Version byte Flags [3]byte FirstChunk []uint32 SamplesPerChunk []uint32 SampleDescriptionID []uint32 }
Sample To Chunk Box (stsc - mandatory)
Contained in : Sample Table box (stbl)
Status: decoded
A chunk contains samples. This table defines to which chunk a sample is associated. Each entry is defined by :
- first chunk : all chunks starting at this index up to the next first chunk have the same sample count/description
- samples per chunk : number of samples in the chunk
- description id : description (see the sample description box - stsd)
type StsdBox ¶
Sample Description Box (stsd - manatory)
Contained in : Sample Table box (stbl)
Status: not decoded
This box contains information that describes how the data can be decoded.
type StssBox ¶
Sync Sample Box (stss - optional)
Contained in : Sample Table box (stbl)
Status: decoded
This lists all sync samples (key frames for video tracks) in the data. If absent, all samples are sync samples.
type StszBox ¶
type StszBox struct { Version byte Flags [3]byte SampleUniformSize uint32 SampleNumber uint32 SampleSize []uint32 }
Sample Size Box (stsz - mandatory)
Contained in : Sample Table box (stbl)
Status : decoded
For each track, either stsz of the more compact stz2 must be present. stz2 variant is not supported.
This table lists the size of each sample. If all samples have the same size, it can be defined in the SampleUniformSize attribute.
func (*StszBox) GetSampleSize ¶
GetSampleSize returns the size (in bytes) of a sample
type SttsBox ¶
Decoding Time to Sample Box (stts - mandatory)
Contained in : Sample Table box (stbl)
Status: decoded
This table contains the duration in time units for each sample.
- sample count : the number of consecutive samples having the same duration
- time delta : duration in time units
func (*SttsBox) GetTimeCode ¶
GetTimeCode returns the timecode (duration since the beginning of the media) of the beginning of a sample
type TkhdBox ¶
type TkhdBox struct { Version byte Flags [3]byte CreationTime uint32 ModificationTime uint32 TrackId uint32 Duration uint32 Layer uint16 AlternateGroup uint16 // should be int16 Volume Fixed16 Matrix []byte Width, Height Fixed32 }
Track Header Box (tkhd - mandatory)
Status : only version 0 is decoded. version 1 is not supported
This box describes the track. Duration is measured in time units (according to the time scale defined in the movie header box).
Volume (relevant for audio tracks) is a fixed point number (8 bits + 8 bits). Full volume is 1.0. Width and Height (relevant for video tracks) are fixed point numbers (16 bits + 16 bits). Video pixels are not necessarily square.
type TrakBox ¶
Track Box (tkhd - mandatory)
Contained in : Movie Box (moov)
A media file can contain one or more tracks.
type UdtaBox ¶
type UdtaBox struct {
Meta *MetaBox
}
User Data Box (udta - optional)
Contained in: Movie Box (moov) or Track Box (trak)