Documentation ¶
Overview ¶
Package mp4 implements encoding/decoding of MP4 media.
Index ¶
- Variables
- func AddHeaderSize(size uint64) uint64
- func AppendError(err1 error, err2 error) error
- func EncodeHeader(b Box, w io.Writer) error
- func HeaderSizeFor(size uint64) uint64
- func RemoveHeaderSize(size uint64) uint64
- type BadFormatErr
- type Box
- func DecodeBox(h BoxHeader, r io.Reader) (Box, error)
- func DecodeChpl(r io.Reader, size uint64) (Box, error)
- func DecodeCo64(r io.Reader, size uint64) (Box, error)
- func DecodeContainer(r io.Reader, size uint64) ([]Box, error)
- func DecodeCtts(r io.Reader, size uint64) (Box, error)
- func DecodeDinf(r io.Reader, size uint64) (Box, error)
- func DecodeDref(r io.Reader, size uint64) (Box, error)
- func DecodeEdts(r io.Reader, size uint64) (Box, error)
- func DecodeElst(r io.Reader, size uint64) (Box, error)
- func DecodeFree(r io.Reader, size uint64) (Box, error)
- func DecodeFtyp(r io.Reader, size uint64) (Box, error)
- func DecodeGmhd(r io.Reader, size uint64) (Box, error)
- func DecodeHdlr(r io.Reader, size uint64) (Box, error)
- func DecodeIods(r io.Reader, size uint64) (Box, error)
- func DecodeMdat(r io.Reader, size uint64) (Box, error)
- func DecodeMdhd(r io.Reader, size uint64) (Box, error)
- func DecodeMdia(r io.Reader, size uint64) (Box, error)
- func DecodeMeta(r io.Reader, size uint64) (Box, error)
- func DecodeMinf(r io.Reader, size uint64) (Box, error)
- func DecodeMoov(r io.Reader, size uint64) (Box, error)
- func DecodeMvhd(r io.Reader, size uint64) (Box, error)
- func DecodeName(r io.Reader, size uint64) (Box, error)
- func DecodeSbgp(r io.Reader, size uint64) (Box, error)
- func DecodeSdtp(r io.Reader, size uint64) (Box, error)
- func DecodeSgpd(r io.Reader, size uint64) (Box, error)
- func DecodeSmhd(r io.Reader, size uint64) (Box, error)
- func DecodeStbl(r io.Reader, size uint64) (Box, error)
- func DecodeStco(r io.Reader, size uint64) (Box, error)
- func DecodeStsc(r io.Reader, size uint64) (Box, error)
- func DecodeStsd(r io.Reader, size uint64) (Box, error)
- func DecodeStss(r io.Reader, size uint64) (Box, error)
- func DecodeStsz(r io.Reader, size uint64) (Box, error)
- func DecodeStts(r io.Reader, size uint64) (Box, error)
- func DecodeTkhd(r io.Reader, size uint64) (Box, error)
- func DecodeTrak(r io.Reader, size uint64) (Box, error)
- func DecodeTref(r io.Reader, size uint64) (Box, error)
- func DecodeUdta(r io.Reader, size uint64) (Box, error)
- func DecodeVmhd(r io.Reader, size uint64) (Box, error)
- type BoxHeader
- type ChplBox
- type Co64Box
- type CttsBox
- type DinfBox
- type DrefBox
- type EdtsBox
- type ElstBox
- type Fixed16
- type Fixed32
- type FreeBox
- type FtypBox
- type GmhdBox
- type HdlrBox
- type IodsBox
- type MP4
- type MdatBox
- type MdhdBox
- type MdiaBox
- type MetaBox
- type MinfBox
- type MoovBox
- type MvhdBox
- type NameBox
- type RangeReader
- type SbgpBox
- type SdtpBox
- type SgpdBox
- type SmhdBox
- type StblBox
- type StcoBox
- type StscBox
- type StsdBox
- type StssBox
- type StszBox
- type SttsBox
- type TkhdBox
- type TrakBox
- type TrefBox
- type UdtaBox
- type UniBox
- type VmhdBox
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownBoxType is for unknown box types ErrUnknownBoxType = errors.New("unknown box type") // ErrTruncatedHeader is when a head gets truncated ErrTruncatedHeader = errors.New("truncated header") )
Functions ¶
func AddHeaderSize ¶
func AppendError ¶
AppendError appends one error to the other and doing the right thing if one or more of them are nil
func EncodeHeader ¶
EncodeHeader encodes a box header to a writer
func HeaderSizeFor ¶
func RemoveHeaderSize ¶
Types ¶
type BadFormatErr ¶ added in v0.1.2
type BadFormatErr struct {
// contains filtered or unexported fields
}
BadFormatErr is type of error when an unexpected box appears in unexpected places
func (*BadFormatErr) Error ¶ added in v0.1.2
func (b *BadFormatErr) Error() string
type Box ¶
Box an atom
func DecodeCo64 ¶
DecodeCo64 does what it says on the tin
func DecodeContainer ¶
DecodeContainer decodes a container box
func DecodeFtyp ¶
Decode decodes the ftyp box
func DecodeStco ¶
DecodeStco does what it says on the tin
type ChplBox ¶
type ChplBox struct {
// contains filtered or unexported fields
}
Chpl Box (apple)
Status: not decoded
type Co64Box ¶
Co64Box is Chunk Offset Box (co64 - mandatory)
Contained in : Sample Table box (stbl)
Status: 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 CttsBox ¶
type CttsBox struct { Version byte Flags [3]byte SampleCount []uint32 SampleOffset []uint32 // int32 for version 1 }
CttsBox - 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 }
ElstBox - 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 GmhdBox ¶
type GmhdBox struct {
// contains filtered or unexported fields
}
Gmhd Box (apple)
Status: not 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 }
MP4 -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.
func (*MP4) AudioVolume ¶
AudioVolume returns the audio volume of the first audio trak
func (*MP4) VideoDimensions ¶
VideoDimensions returns the dimesnions of the first video trak
type MdatBox ¶
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 uint64 ModificationTime uint64 Timescale uint32 Duration uint64 Language uint16 }
MdhdBox - 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 ¶
type MinfBox struct { Vmhd *VmhdBox Smhd *SmhdBox Stbl *StblBox Dinf *DinfBox Hdlr *HdlrBox Gmhd *GmhdBox }
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 uint64 ModificationTime uint64 Timescale uint32 Duration uint64 NextTrackID uint32 Rate Fixed32 Volume Fixed16 Matrix []byte }
MvhdBox - 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 NameBox ¶
type NameBox struct {
// contains filtered or unexported fields
}
Name Box
Status: not decoded
type RangeReader ¶
type RangeReader interface {
RangeRead(start, length uint64) (io.ReadCloser, error)
}
RangeReader can be used to get ReadClose for a given range
type SbgpBox ¶
type SbgpBox struct {
// contains filtered or unexported fields
}
Sbgp Box
Status: not decoded
type SdtpBox ¶
type SdtpBox struct {
// contains filtered or unexported fields
}
Sdtp Box
Status: not decoded
type SgpdBox ¶
type SgpdBox struct {
// contains filtered or unexported fields
}
Sgpd Box
Status: not 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 Co64 *Co64Box Ctts *CttsBox }
StblBox - 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 ¶
StcoBox is 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 }
StszBox - 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 uint64 ModificationTime uint64 TrackID uint32 Duration uint64 Layer uint16 AlternateGroup uint16 // should be int16 Volume Fixed16 Matrix []byte Width, Height Fixed32 }
TkhdBox - Track Header Box (tkhd - mandatory)
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 TrefBox ¶
type TrefBox struct {
// contains filtered or unexported fields
}
Tref Box (apple)
Status: not decoded
type UdtaBox ¶
type UdtaBox struct { Meta *MetaBox Name *NameBox Chpl *ChplBox // contains filtered or unexported fields }
User Data Box (udta - optional)
Contained in: Movie Box (moov) or Track Box (trak)
type UniBox ¶
type UniBox struct { BoxHeader // contains filtered or unexported fields }
UniBox - Universal not decoded Box
Source Files ¶
- box.go
- chpl.go
- co64.go
- ctts.go
- dinf.go
- doc.go
- dref.go
- edts.go
- elst.go
- free.go
- ftyp.go
- gmhd.go
- hdlr.go
- header.go
- iods.go
- mdat.go
- mdhd.go
- mdia.go
- meta.go
- minf.go
- moov.go
- mp4.go
- multi_read_closer.go
- mvhd.go
- name.go
- rangeReader.go
- sbgp.go
- sdtp.go
- sgpd.go
- smhd.go
- stbl.go
- stco.go
- stsc.go
- stsd.go
- stss.go
- stsz.go
- stts.go
- tkhd.go
- trak.go
- tref.go
- udta.go
- uni.go
- uni_container.go
- vmhd.go