Documentation
¶
Overview ¶
Package mp4 provides support for the ISO base media file format and fragmented MP4 streams.
Index ¶
- Constants
- Variables
- func IsContainerBox(t BoxType) bool
- func IsFullBox(t BoxType) bool
- func ReadAvcC(data []byte) string
- func ReadEsdsCodec(data []byte) string
- type AudioSampleEntry
- type BoxType
- type Co64Iter
- type CttsEntry
- type CttsIter
- type ElstEntry
- type ElstIter
- type FtypInfo
- type Reader
- func (r *Reader) Data() []byte
- func (r *Reader) DataOffset() int
- func (r *Reader) Depth() int
- func (r *Reader) Enter()
- func (r *Reader) EntryCount() uint32
- func (r *Reader) Exit()
- func (r *Reader) Flags() uint32
- func (r *Reader) HeaderSize() int
- func (r *Reader) Next() bool
- func (r *Reader) Offset() int
- func (r *Reader) RawBox() []byte
- func (r *Reader) ReadElst() (mediaTime int64, ok bool)
- func (r *Reader) ReadHdlr() [4]byte
- func (r *Reader) ReadHdlrName() string
- func (r *Reader) ReadMdhd() (timescale uint32, duration uint64, language uint16)
- func (r *Reader) ReadMehd() (fragmentDuration uint64)
- func (r *Reader) ReadMfhd() (sequenceNumber uint32)
- func (r *Reader) ReadMvhd() (timescale uint32, duration uint64, nextTrackId uint32)
- func (r *Reader) ReadTfdt() (baseMediaDecodeTime uint64)
- func (r *Reader) ReadTfhd() (trackId uint32)
- func (r *Reader) ReadTkhd() (trackId uint32, duration uint64, width, height uint32)
- func (r *Reader) ReadTrex() (...)
- func (r *Reader) Size() uint64
- func (r *Reader) Skip(n int)
- func (r *Reader) Type() BoxType
- func (r *Reader) Version() uint8
- type ScanEntry
- type Scanner
- type SidxEntry
- type StscEntry
- type StscIter
- type StszIter
- type SttsEntry
- type SttsIter
- type TrunEntry
- type TrunIter
- type Uint32Iter
- type VisualSampleEntry
- type Writer
- func (w *Writer) Bytes() []byte
- func (w *Writer) EndBox()
- func (w *Writer) Err() error
- func (w *Writer) Len() int
- func (w *Writer) Reset()
- func (w *Writer) StartBox(t BoxType)
- func (w *Writer) StartFullBox(t BoxType, version uint8, flags uint32)
- func (w *Writer) Write(p []byte) (int, error)
- func (w *Writer) WriteAudioSampleEntry(dataRefIdx, channelCount, sampleSize uint16, sampleRate uint32)
- func (w *Writer) WriteCo64(entries []uint64)
- func (w *Writer) WriteCtts(entries []CttsEntry)
- func (w *Writer) WriteDref()
- func (w *Writer) WriteElst(entries []ElstEntry)
- func (w *Writer) WriteFtyp(brand [4]byte, brandVersion uint32, compat [][4]byte)
- func (w *Writer) WriteHdlr(handlerType [4]byte, name string)
- func (w *Writer) WriteMdhd(timescale uint32, duration uint64, language uint16)
- func (w *Writer) WriteMehd(fragmentDuration uint64)
- func (w *Writer) WriteMfhd(sequenceNumber uint32)
- func (w *Writer) WriteMvhd(timescale uint32, duration uint64, nextTrackId uint32)
- func (w *Writer) WriteSidx(trackID uint32, timescale uint32, earliestPTS uint64, firstOffset uint64, ...)
- func (w *Writer) WriteSmhd()
- func (w *Writer) WriteStco(entries []uint32)
- func (w *Writer) WriteStsc(entries []StscEntry)
- func (w *Writer) WriteStss(entries []uint32)
- func (w *Writer) WriteStsz(sampleSize uint32, entries []uint32)
- func (w *Writer) WriteStts(entries []SttsEntry)
- func (w *Writer) WriteStyp(brand [4]byte, brandVersion uint32, compat [][4]byte)
- func (w *Writer) WriteTfdt(baseMediaDecodeTime uint64)
- func (w *Writer) WriteTfhd(flags, trackId, defaultDuration, defaultSize, defaultFlags uint32)
- func (w *Writer) WriteTkhd(flags uint32, trackId uint32, duration uint64, width, height uint32)
- func (w *Writer) WriteTrex(trackId, descIdx, defDuration, defSize, defFlags uint32)
- func (w *Writer) WriteTrun(flags uint32, dataOffset int32, firstSampleFlags uint32, entries []TrunEntry)
- func (w *Writer) WriteVisualSampleEntry(dataRefIdx, width, height, frameCount, depth uint16, compressor string)
- func (w *Writer) WriteVmhd()
Constants ¶
const ( TrunDataOffsetPresent = 0x000001 TrunFirstSampleFlagsPresent = 0x000004 TrunSampleDurationPresent = 0x000100 TrunSampleSizePresent = 0x000200 TrunSampleFlagsPresent = 0x000400 TrunSampleCompositionTimeOffsetPresent = 0x000800 )
Trun flags.
const ( TfhdBaseDataOffsetPresent = 0x000001 TfhdSampleDescriptionIndexPresent = 0x000002 TfhdDefaultSampleDurationPresent = 0x000008 TfhdDefaultSampleSizePresent = 0x000010 TfhdDefaultSampleFlagsPresent = 0x000020 TfhdDurationIsEmpty = 0x010000 TfhdDefaultBaseIsMoof = 0x020000 )
Tfhd flags (Track Fragment Header Box).
Variables ¶
var ( TypeFtyp = BoxType{'f', 't', 'y', 'p'} // File type and compatibility TypeStyp = BoxType{'s', 't', 'y', 'p'} // Segment type (fragmented MP4) )
Known box types.
var ( TypeMoov = BoxType{'m', 'o', 'o', 'v'} // Movie metadata container TypeMvhd = BoxType{'m', 'v', 'h', 'd'} // Movie header (timescale, duration) TypeTrak = BoxType{'t', 'r', 'a', 'k'} // Track container TypeTkhd = BoxType{'t', 'k', 'h', 'd'} // Track header (ID, dimensions) TypeTref = BoxType{'t', 'r', 'e', 'f'} // Track reference container TypeTrgr = BoxType{'t', 'r', 'g', 'r'} // Track grouping indication TypeEdts = BoxType{'e', 'd', 't', 's'} // Edit list container TypeElst = BoxType{'e', 'l', 's', 't'} // Edit list entries TypeMdia = BoxType{'m', 'd', 'i', 'a'} // Media information container TypeMdhd = BoxType{'m', 'd', 'h', 'd'} // Media header (timescale, duration) TypeHdlr = BoxType{'h', 'd', 'l', 'r'} // Handler reference (vide/soun) TypeElng = BoxType{'e', 'l', 'n', 'g'} // Extended language tag TypeMinf = BoxType{'m', 'i', 'n', 'f'} // Media information container TypeVmhd = BoxType{'v', 'm', 'h', 'd'} // Video media header TypeSmhd = BoxType{'s', 'm', 'h', 'd'} // Sound media header TypeHmhd = BoxType{'h', 'm', 'h', 'd'} // Hint media header TypeSthd = BoxType{'s', 't', 'h', 'd'} // Subtitle media header TypeNmhd = BoxType{'n', 'm', 'h', 'd'} // Null media header TypeDinf = BoxType{'d', 'i', 'n', 'f'} // Data information container TypeDref = BoxType{'d', 'r', 'e', 'f'} // Data reference (URL/URN entries) )
Movie structure boxes (moov and children).
var ( TypeStbl = BoxType{'s', 't', 'b', 'l'} // Sample table container TypeStsd = BoxType{'s', 't', 's', 'd'} // Sample descriptions (codec config) TypeStts = BoxType{'s', 't', 't', 's'} // Decoding time-to-sample TypeCtts = BoxType{'c', 't', 't', 's'} // Composition time-to-sample TypeCslg = BoxType{'c', 's', 'l', 'g'} // Composition to decode timeline mapping TypeStsc = BoxType{'s', 't', 's', 'c'} // Sample-to-chunk mapping TypeStsz = BoxType{'s', 't', 's', 'z'} // Sample sizes TypeStz2 = BoxType{'s', 't', 'z', '2'} // Compact sample sizes TypeStco = BoxType{'s', 't', 'c', 'o'} // Chunk offsets (32-bit) TypeCo64 = BoxType{'c', 'o', '6', '4'} // Chunk offsets (64-bit) TypeStss = BoxType{'s', 't', 's', 's'} // Sync sample table (keyframes) TypeStsh = BoxType{'s', 't', 's', 'h'} // Shadow sync sample table TypePadb = BoxType{'p', 'a', 'd', 'b'} // Padding bits TypeStdp = BoxType{'s', 't', 'd', 'p'} // Sample degradation priority TypeSdtp = BoxType{'s', 'd', 't', 'p'} // Sample dependency type TypeSbgp = BoxType{'s', 'b', 'g', 'p'} // Sample-to-group TypeSgpd = BoxType{'s', 'g', 'p', 'd'} // Sample group description TypeSubs = BoxType{'s', 'u', 'b', 's'} // Sub-sample information TypeSaiz = BoxType{'s', 'a', 'i', 'z'} // Sample auxiliary information sizes TypeSaio = BoxType{'s', 'a', 'i', 'o'} // Sample auxiliary information offsets )
Sample table boxes (stbl children).
var ( TypeMvex = BoxType{'m', 'v', 'e', 'x'} // Movie extends (signals fragmented file) TypeMehd = BoxType{'m', 'e', 'h', 'd'} // Movie extends header (fragment duration) TypeTrex = BoxType{'t', 'r', 'e', 'x'} // Track extends defaults TypeLeva = BoxType{'l', 'e', 'v', 'a'} // Level assignment TypeMoof = BoxType{'m', 'o', 'o', 'f'} // Movie fragment container TypeMfhd = BoxType{'m', 'f', 'h', 'd'} // Movie fragment header (sequence number) TypeTraf = BoxType{'t', 'r', 'a', 'f'} // Track fragment container TypeTfhd = BoxType{'t', 'f', 'h', 'd'} // Track fragment header TypeTfdt = BoxType{'t', 'f', 'd', 't'} // Track fragment decode time TypeTrun = BoxType{'t', 'r', 'u', 'n'} // Track run (per-sample metadata) TypeSidx = BoxType{'s', 'i', 'd', 'x'} // Segment index TypeEmsg = BoxType{'e', 'm', 's', 'g'} // Event message )
Fragment boxes (moof and children, mvex).
var ( TypeMeta = BoxType{'m', 'e', 't', 'a'} // Metadata container TypeUdta = BoxType{'u', 'd', 't', 'a'} // User data container )
Metadata boxes.
var ( TypeMdat = BoxType{'m', 'd', 'a', 't'} // Media data payload TypeFree = BoxType{'f', 'r', 'e', 'e'} // Free space (can be skipped) TypeSkip = BoxType{'s', 'k', 'i', 'p'} // Free space (can be skipped) )
Data boxes.
var ( TypeAvc1 = BoxType{'a', 'v', 'c', '1'} // AVC/H.264 visual sample entry TypeAvcC = BoxType{'a', 'v', 'c', 'C'} // AVC decoder configuration record TypeAv01 = BoxType{'a', 'v', '0', '1'} // AV1 visual sample entry TypeAv1C = BoxType{'a', 'v', '1', 'C'} // AV1 codec configuration record TypeBtrt = BoxType{'b', 't', 'r', 't'} // MPEG-4 bit rate TypePasp = BoxType{'p', 'a', 's', 'p'} // Pixel aspect ratio TypeMp4a = BoxType{'m', 'p', '4', 'a'} // MPEG-4 audio sample entry TypeEsds = BoxType{'e', 's', 'd', 's'} // ES descriptor )
Sample entry boxes (children of stsd).
var ErrBoxTooLarge = errors.New("mp4: box size exceeds 4GB limit")
ErrBoxTooLarge is returned by Writer.Err when a box exceeds the 4 GB limit for standard (32-bit) box sizes.
Functions ¶
func IsContainerBox ¶ added in v0.2.0
IsContainerBox returns true if the box type is a container that holds child boxes.
func IsFullBox ¶ added in v0.2.0
IsFullBox returns true if the box type has version and flags fields.
func ReadAvcC ¶ added in v0.2.0
ReadAvcC extracts the codec profile string from avcC box data. Returns a string like "64001f" for use in MIME type codec parameters.
func ReadEsdsCodec ¶ added in v0.2.0
ReadEsdsCodec extracts the MIME codec string from esds box data. It parses the MPEG-4 descriptor chain to find the OTI (Object Type Indication) and audio configuration. Returns a string like "40.2" for AAC-LC.
Types ¶
type AudioSampleEntry ¶
type AudioSampleEntry struct {
DataReferenceIndex uint16
ChannelCount uint16
SampleSize uint16
SampleRate uint32 // 16.16 fixed point
ChildOffset int // byte offset within data where child boxes begin
}
AudioSampleEntry holds parsed fields from an audio sample entry (e.g. mp4a).
func ReadAudioSampleEntry ¶ added in v0.2.0
func ReadAudioSampleEntry(data []byte) AudioSampleEntry
ReadAudioSampleEntry parses an audio sample entry from box data. Child boxes (e.g. esds) start at ChildOffset within the data.
type Co64Iter ¶ added in v0.2.0
type Co64Iter struct {
// contains filtered or unexported fields
}
Co64Iter iterates over uint64 chunk offsets in a co64 box.
func NewCo64Iter ¶ added in v0.2.0
NewCo64Iter creates an iterator from co64 box data.
type CttsEntry ¶ added in v0.2.0
type CttsEntry struct {
Count uint32
Offset int32 // Signed offset (version 1), or unsigned treated as signed (version 0)
}
CttsEntry is a composition offset entry.
type CttsIter ¶ added in v0.2.0
type CttsIter struct {
// contains filtered or unexported fields
}
CttsIter iterates over ctts entries.
func NewCttsIter ¶ added in v0.2.0
NewCttsIter creates an iterator from ctts box data. version should be 0 or 1 from the ctts box version field. Version 0: offsets are uint32 (but interpreted as composition time offset) Version 1: offsets are int32 (signed composition time offset)
type ElstEntry ¶
type ElstEntry struct {
SegmentDuration uint64
MediaTime int64
MediaRateInt int16
MediaRateFrac int16
}
ElstEntry is an edit list entry.
type ElstIter ¶ added in v0.2.0
type ElstIter struct {
// contains filtered or unexported fields
}
ElstIter iterates over elst entries.
func NewElstIter ¶ added in v0.2.0
NewElstIter creates an iterator from elst box data with the given version.
type Reader ¶ added in v0.2.0
type Reader struct {
// contains filtered or unexported fields
}
Reader provides hierarchical, in-memory parsing of box data. After loading a box's bytes (e.g., from Scanner), create a Reader to iterate children, descend into containers, and extract typed fields.
Iterating over top-level boxes:
r := mp4.NewReader(buf)
for r.Next() {
fmt.Printf("box: %s size: %d\n", r.Type(), r.Size())
}
For container boxes, use Enter/Exit to descend into children:
for r.Next() {
if r.Type() == mp4.TypeMoov {
r.Enter() // descend into moov
for r.Next() { // iterate moov children
// process trak, mvhd, etc.
}
r.Exit() // return to top level
}
}
Some boxes have an entry count before child boxes (stsd, dref). Use Skip(4) after Enter to skip past the count field:
r.Enter()
r.Skip(4) // skip entry count
for r.Next() {
// process entries
}
r.Exit()
Sample entry boxes have fixed-size headers before child boxes. Use Skip with the header size (avc1=78, mp4a=28):
r.Enter()
r.Skip(78) // skip avc1 fixed header
for r.Next() {
// process avcC, pasp, etc.
}
r.Exit()
func (*Reader) Data ¶ added in v0.2.0
Data returns the current box's data (after all headers). Note that, the returned slice points into the original buffer.
func (*Reader) DataOffset ¶ added in v0.2.0
DataOffset returns the byte offset where the current box's data begins.
func (*Reader) Enter ¶ added in v0.2.0
func (r *Reader) Enter()
Enter descends into the current container box to iterate its children. After Enter, call Next to advance to the first child box. Call Exit when done to return to the parent level.
For boxes like stsd or dref that have an entry count before child boxes, call Skip(4) after Enter to skip past the count field.
For sample entry boxes like avc1 (78 bytes) or mp4a (28 bytes), call Skip with the fixed header size after Enter to reach child boxes.
func (*Reader) EntryCount ¶ added in v0.2.0
EntryCount reads the uint32 entry count at the start of box data. Used for boxes like stsd and dref that begin with a count field.
func (*Reader) Exit ¶ added in v0.2.0
func (r *Reader) Exit()
Exit returns to the parent container level. After Exit, the next call to Next will advance to the next sibling.
func (*Reader) HeaderSize ¶ added in v0.2.0
HeaderSize returns the size of the current box's header in bytes.
func (*Reader) Next ¶ added in v0.2.0
Next advances to the next sibling box. Returns false if no more boxes.
func (*Reader) Offset ¶ added in v0.2.0
Offset returns the byte offset of the current box's start in the buffer.
func (*Reader) RawBox ¶ added in v0.2.0
RawBox returns the entire current box including headers. Note that, the returned slice points into the original buffer.
func (*Reader) ReadElst ¶ added in v0.2.0
ReadElst extracts the media time of the first edit list entry, in the media timescale. It returns the media time and whether an entry was present.
func (*Reader) ReadHdlr ¶ added in v0.2.0
ReadHdlr extracts the handler type from an hdlr box. Returns the 4-byte handler type string.
func (*Reader) ReadHdlrName ¶ added in v0.2.0
ReadHdlrName extracts the handler name from an hdlr box.
func (*Reader) ReadMdhd ¶ added in v0.2.0
ReadMdhd extracts key fields from an mdhd box. Returns timescale, duration, and language code.
func (*Reader) ReadMvhd ¶ added in v0.2.0
ReadMvhd extracts key fields from an mvhd box. Returns timescale, duration, and nextTrackId.
func (*Reader) ReadTfdt ¶ added in v0.2.0
ReadTfdt extracts the base media decode time from a tfdt box.
func (*Reader) ReadTkhd ¶ added in v0.2.0
ReadTkhd extracts key fields from a tkhd box. Returns trackId, duration, width, height. Width and height are 16.16 fixed-point values; shift right by 16 for pixels.
func (*Reader) ReadTrex ¶ added in v0.2.0
func (r *Reader) ReadTrex() (trackId, defSampleDescIdx, defSampleDuration, defSampleSize, defSampleFlags uint32)
ReadTrex extracts fields from a trex box. Returns trackId, default sample description index, default sample duration, default sample size, and default sample flags.
func (*Reader) Skip ¶ added in v0.2.0
Skip advances the data position by n bytes within the current container. Use after Enter to skip fixed-size headers before child boxes.
type ScanEntry ¶ added in v0.2.0
type ScanEntry struct {
Type BoxType
Size int64 // total box size including header
Offset int64 // byte offset from start of stream
HeaderSize int // header size (8 or 16 bytes)
}
ScanEntry represents a top-level box discovered by the Scanner.
func (ScanEntry) DataOffset ¶ added in v0.2.0
DataOffset returns the byte offset where the box data begins (after the header). Use it with io.ReaderAt.ReadAt to read box data without seeking.
type Scanner ¶ added in v0.2.0
type Scanner struct {
// contains filtered or unexported fields
}
Scanner reads top-level box headers from an io.ReadSeeker without loading box contents into memory. Use it to discover box positions and sizes, then selectively read only the boxes you need.
Typical usage:
f, _ := os.Open("video.mp4")
sc := mp4.NewScanner(f)
for sc.Next() {
e := sc.Entry()
if e.Type == mp4.TypeMoov {
buf := make([]byte, e.DataSize())
sc.ReadBody(buf)
r := mp4.NewReader(buf)
// parse moov contents...
}
}
if err := sc.Err(); err != nil { ... }
func NewScanner ¶ added in v0.2.0
func NewScanner(rs io.ReadSeeker) Scanner
NewScanner creates a Scanner that reads box headers from rs.
func (*Scanner) Entry ¶ added in v0.2.0
Entry returns the current box entry. Only valid after Next returns true.
func (*Scanner) Err ¶ added in v0.2.0
Err returns the first non-EOF error encountered by the Scanner.
func (*Scanner) Next ¶ added in v0.2.0
Next advances to the next top-level box. Returns false when there are no more boxes or an error occurs. Check Err() after the loop.
func (*Scanner) ReadBody ¶ added in v0.2.0
ReadBody reads the current box's data (excluding header) into buf. buf must be exactly DataSize() bytes. The scanner seeks to the data position, reads, then seeks back so that subsequent Next calls work correctly.
func (*Scanner) ReadBox ¶ added in v0.2.0
ReadBox reads the current box's full data (including header) into buf. buf must be exactly Size bytes.
func (*Scanner) Reset ¶ added in v0.2.0
func (s *Scanner) Reset(rs io.ReadSeeker)
Reset discards all state and prepares the Scanner to read from rs. It lets a single Scanner be reused for multiple streams without reallocating.
type SidxEntry ¶ added in v0.2.0
type SidxEntry struct {
ReferenceType bool // false = media, true = sub-sidx
ReferencedSize uint32 // size in bytes of the referenced material
SubsegDuration uint32 // duration in timescale units
StartsWithSAP bool // starts with a stream access point
SAPType uint8 // SAP type (1-6)
}
SidxEntry represents one reference in a sidx box.
type StscIter ¶ added in v0.2.0
type StscIter struct {
// contains filtered or unexported fields
}
StscIter iterates over stsc entries.
func NewStscIter ¶ added in v0.2.0
NewStscIter creates an iterator from stsc box data.
type StszIter ¶ added in v0.2.0
type StszIter struct {
// contains filtered or unexported fields
}
StszIter iterates over sample sizes in an stsz box.
func NewStszIter ¶ added in v0.2.0
NewStszIter creates an iterator from stsz box data.
type SttsIter ¶ added in v0.2.0
type SttsIter struct {
// contains filtered or unexported fields
}
SttsIter iterates over stts entries.
func NewSttsIter ¶ added in v0.2.0
NewSttsIter creates an iterator from stts box data.
type TrunIter ¶ added in v0.2.0
type TrunIter struct {
// contains filtered or unexported fields
}
TrunIter iterates over trun entries.
func NewTrunIter ¶ added in v0.2.0
NewTrunIter creates an iterator from trun box data with the given flags.
func (*TrunIter) DataOffset ¶ added in v0.2.0
DataOffset returns the trun data offset.
func (*TrunIter) FirstSampleFlags ¶ added in v0.2.0
FirstSampleFlags returns the first sample flags, if present.
type Uint32Iter ¶ added in v0.2.0
type Uint32Iter struct {
// contains filtered or unexported fields
}
Uint32Iter iterates over uint32 entries (stco, stss).
func NewUint32Iter ¶ added in v0.2.0
func NewUint32Iter(data []byte) Uint32Iter
NewUint32Iter creates an iterator from box data containing a count + uint32 entries.
func (*Uint32Iter) Count ¶ added in v0.2.0
func (it *Uint32Iter) Count() uint32
Count returns the total number of entries.
func (*Uint32Iter) Next ¶ added in v0.2.0
func (it *Uint32Iter) Next() (uint32, bool)
Next returns the next entry. Returns (0, false) when done.
type VisualSampleEntry ¶
type VisualSampleEntry struct {
DataReferenceIndex uint16
Width uint16
Height uint16
HResolution uint32 // 16.16 fixed point
VResolution uint32 // 16.16 fixed point
FrameCount uint16
CompressorName string
Depth uint16
ChildOffset int // byte offset within data where child boxes begin
}
VisualSampleEntry holds parsed fields from a visual sample entry (e.g. avc1).
func ReadVisualSampleEntry ¶ added in v0.2.0
func ReadVisualSampleEntry(data []byte) VisualSampleEntry
ReadVisualSampleEntry parses a visual sample entry from box data. Child boxes (e.g. avcC) start at ChildOffset within the data.
type Writer ¶ added in v0.2.0
type Writer struct {
// contains filtered or unexported fields
}
Writer encodes ISOBMFF boxes into the provided buffer.
The buffer must be large enough to hold all written data; writes beyond the buffer boundary will panic.
Use Writer.StartBox and Writer.EndBox to write nested boxes:
w := mp4.NewWriter(buf) w.StartBox(mp4.TypeMoov) w.WriteMvhd(1000, 30000, 3) w.EndBox() output := w.Bytes()
After all writes, check Writer.Err for errors.
func (*Writer) EndBox ¶ added in v0.2.0
func (w *Writer) EndBox()
EndBox finishes the current box by backpatching its size.
func (*Writer) Err ¶ added in v0.2.0
Err returns the first deferred error encountered during writing.
func (*Writer) Reset ¶ added in v0.2.0
func (w *Writer) Reset()
Reset resets the writer position to 0 and clears any error state.
func (*Writer) StartBox ¶ added in v0.2.0
StartBox begins a new box. Write content, then call EndBox.
func (*Writer) StartFullBox ¶ added in v0.2.0
StartFullBox begins a new full box with version and flags.
func (*Writer) WriteAudioSampleEntry ¶ added in v0.2.0
func (w *Writer) WriteAudioSampleEntry(dataRefIdx, channelCount, sampleSize uint16, sampleRate uint32)
WriteAudioSampleEntry writes the 28-byte audio sample entry header. The caller must start the box (e.g. mp4a) and end it after writing children.
func (*Writer) WriteDref ¶ added in v0.2.0
func (w *Writer) WriteDref()
WriteDref writes a dref box with a single self-referencing url entry.
func (*Writer) WriteSidx ¶ added in v0.2.0
func (w *Writer) WriteSidx(trackID uint32, timescale uint32, earliestPTS uint64, firstOffset uint64, entries []SidxEntry)
WriteSidx writes a segment index box (version 1, 64-bit times).
func (*Writer) WriteSmhd ¶ added in v0.2.0
func (w *Writer) WriteSmhd()
WriteSmhd writes a complete smhd box.
func (*Writer) WriteStsz ¶ added in v0.2.0
WriteStsz writes a complete stsz box from an iterator or raw entries.
func (*Writer) WriteStyp ¶ added in v0.2.0
WriteStyp writes a segment type box (same format as ftyp).
func (*Writer) WriteTfhd ¶ added in v0.2.0
WriteTfhd writes a complete tfhd box. WriteTfhd writes a track fragment header. Default sample duration, size, and flags are written when their corresponding flag bits are set.
func (*Writer) WriteTrun ¶ added in v0.2.0
func (w *Writer) WriteTrun(flags uint32, dataOffset int32, firstSampleFlags uint32, entries []TrunEntry)
WriteTrun writes a complete trun box. WriteTrun writes a track run. firstSampleFlags is written when TrunFirstSampleFlagsPresent is set, overriding the default for sample one.
func (*Writer) WriteVisualSampleEntry ¶ added in v0.2.0
func (w *Writer) WriteVisualSampleEntry(dataRefIdx, width, height, frameCount, depth uint16, compressor string)
WriteVisualSampleEntry writes the 78-byte visual sample entry header. The caller must start the box (e.g. avc1) and end it after writing children.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
mp4dump
command
Command mp4dump reads an MP4 file and prints its box structure.
|
Command mp4dump reads an MP4 file and prints its box structure. |
|
mp4probe
command
Command mp4probe displays information about MP4 tracks and keyframes.
|
Command mp4probe displays information about MP4 tracks and keyframes. |
|
mp4remux
command
Command mp4remux converts MP4 files to fragmented MP4 streams.
|
Command mp4remux converts MP4 files to fragmented MP4 streams. |
|
Package fragment provides streaming MP4 fragmentation.
|
Package fragment provides streaming MP4 fragmentation. |