mp4

package module
v0.0.0-...-b665efa Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// If the Override TrackEncryptionBox parameters flag is set, then the
	// SampleEncryptionBox specifies the AlgorithmID, IV_size, and KID
	// parameters. If not present, then the default values from the
	// TrackEncryptionBox SHOULD be used for this fragment.
	FLAG_SENC_OVERRIDE_TRACK_ENCRYPTION_BOX_PARAMS uint32 = 0x01

	// If the UseSubSampleEncryption flag is set, then the track fragment that
	// contains this Sample Encryption Box SHALL use Subsample encryption as
	// described in 9.5. When this flag is set, Subsample mapping data follows
	// each InitializationVector. The Subsample mapping data consists of the
	// number of Subsamples for each sample, followed by an array of values
	// describing the number of bytes of clear data and the number of bytes of
	// encrypted data for each Subsample.
	FLAG_SENC_USE_SUBSAMPLE_ENCRYPTION uint32 = 0x02
)
View Source
const (
	// Indicates the presence of the base‐data‐offset field. This provides an
	// explicit anchor for the data offsets in each track run (see below). If
	// not provided and if the default‐base‐is‐moof flag is not set, the
	// base‐data‐offset for the first track in the movie fragment is the
	// position of the first byte of the enclosing Movie Fragment Box, and for
	// second and subsequent track fragments, the default is the end of the data
	// defined by the preceding track fragment. Fragments 'inheriting' their
	// offset in this way must all use the same datareference (i.e., the data
	// for these tracks must be in the same file)
	FLAG_TFHD_BASE_DATA_OFFSET uint32 = 0x01

	// Indicates the presence of this field, which over‐rides, in this fragment,
	// the default set up in the Track Extends Box.
	FLAG_TFHD_SAMPLE_DESCRIPTION_INDEX uint32 = 0x02
	FLAG_TFHD_DEFAULT_SAMPLE_DURATION  uint32 = 0x08
	FLAG_TFHD_DEFAULT_SAMPLE_SIZE      uint32 = 0x10
	FLAG_TFHD_DEFAULT_SAMPLE_FLAGS     uint32 = 0x20

	// This indicates that the duration provided in either
	// default‐sampleduration, or by the default‐duration in the Track Extends
	// Box, is empty, i.e. that there are no samples for this time interval. It
	// is an error to make a presentation that has both edit lists in the Movie
	// Box, and empty‐duration fragments.
	FLAG_TFHD_DURATION_IS_EMPTY uint32 = 0x010000

	// If base‐data‐offset‐present is 1, this flag is ignored. If
	// base‐dataoffset‐ present is zero, this indicates that the
	// base‐data‐offset for this track fragment is the position of the first
	// byte of the enclosing Movie Fragment Box. Support for the
	// default‐base‐ismoof flag is required under the ‘iso5’ brand, and it shall
	// not be used in brands or compatible brands earlier than iso5.
	FLAG_TFHD_DEFAULT_BASE_IS_MOOF uint32 = 0x020000
)
View Source
const (
	// Indicates that the track is enabled. Flag value is 0x000001. A disabled
	// track (the low bit is zero) is treated as if it were not present.
	FLAG_TKHD_TRACK_ENABLED uint32 = 0x000001

	// Indicates that the track is used in the presentation. Flag value is
	// 0x000002.
	FLAG_TKHD_TRACK_IN_MOVIE uint32 = 0x000002

	// Indicates that the track is used when previewing the presentation. Flag
	// value is 0x000004.
	FLAG_TKHD_TRACK_IN_PREVIEW uint32 = 0x000004

	// Indicates that the width and height fields are not expressed in pixel
	// units. The values have the same units but these units are not specified.
	// The values are only an indication of the desired aspect ratio. If the
	// aspect ratios of this track and other related tracks are not identical,
	// then the respective positioning of the tracks is undefined, possibly
	// defined by external contexts. Flag value is 0x000008.
	FLAG_TKHD_TRACK_SIZE_IS_ASPECT_RATIO uint32 = 0x000008
)
View Source
const (
	FLAG_TRUN_DATA_OFFSET uint32 = 0x01

	// this over‐rides the default flags for the first sample only. This makes
	// it possible to record a group of frames where the first is a key and the
	// rest are difference frames, without supplying explicit flags for every
	// sample. If this flag and field are used, sampleflags shall not be
	// present.
	FLAG_TRUN_FIRST_SAMPLE_FLAGS uint32 = 0x04

	// indicates that each sample has its own duration, otherwise the default is
	// used.
	FLAG_TRUN_SAMPLE_DURATION uint32 = 0x100

	// each sample has its own size, otherwise the default is used.
	FLAG_TRUN_SAMPLE_SIZE uint32 = 0x200

	// each sample has its own flags, otherwise the default is used.
	FLAG_TRUN_SAMPLE_FLAGS uint32 = 0x400

	// each sample has a composition time offset (e.g. as used for I/P/B video
	// in MPEG).
	FLAG_TRUN_SAMPLE_COMPOSITION_TIME_OFFSET uint32 = 0x800
)
View Source
const (
	FLAG_DREF_SAME_FILE uint32 = 0x000001
)
View Source
const (
	FLAG_SCHM_SCHEME_URI uint32 = 0x000001
)

Variables

View Source
var (
	AvcCBoxType = BoxType{'a', 'v', 'c', 'C'}
	AvcEBoxType = BoxType{'a', 'v', 'c', 'E'}
	BtrtBoxType = BoxType{'b', 't', 'r', 't'}
	ClapBoxType = BoxType{'c', 'l', 'a', 'p'}
	ColrBoxType = BoxType{'c', 'o', 'l', 'r'}
	CttsBoxType = BoxType{'c', 't', 't', 's'}
	DinfBoxType = BoxType{'d', 'i', 'n', 'f'}
	DrefBoxType = BoxType{'d', 'r', 'e', 'f'}
	DvcCBoxType = BoxType{'d', 'v', 'c', 'C'}
	DvvCBoxType = BoxType{'d', 'v', 'v', 'C'}
	DvwCBoxType = BoxType{'d', 'v', 'w', 'C'}
	ElngBoxType = BoxType{'e', 'l', 'n', 'g'}
	EncaBoxType = BoxType{'e', 'n', 'c', 'a'}
	EncsBoxType = BoxType{'e', 'n', 'c', 's'}
	EnctBoxType = BoxType{'e', 'n', 'c', 't'}
	EncvBoxType = BoxType{'e', 'n', 'c', 'v'}
	FreeBoxType = BoxType{'f', 'r', 'e', 'e'}
	FrmaBoxType = BoxType{'f', 'r', 'm', 'a'}
	FtypBoxType = BoxType{'f', 't', 'y', 'p'}
	HdlrBoxType = BoxType{'h', 'd', 'l', 'r'}
	HvcCBoxType = BoxType{'h', 'v', 'c', 'C'}
	HvcEBoxType = BoxType{'h', 'v', 'c', 'E'}
	MdatBoxType = BoxType{'m', 'd', 'a', 't'}
	MdhdBoxType = BoxType{'m', 'd', 'h', 'd'}
	MdiaBoxType = BoxType{'m', 'd', 'i', 'a'}
	MfhdBoxType = BoxType{'m', 'f', 'h', 'd'}
	MinfBoxType = BoxType{'m', 'i', 'n', 'f'}
	MoofBoxType = BoxType{'m', 'o', 'o', 'f'}
	MoovBoxType = BoxType{'m', 'o', 'o', 'v'}
	MvexBoxType = BoxType{'m', 'v', 'e', 'x'}
	MvhdBoxType = BoxType{'m', 'v', 'h', 'd'}
	NmhdBoxType = BoxType{'n', 'm', 'h', 'd'}
	PaspBoxType = BoxType{'p', 'a', 's', 'p'}
	PsshBoxType = BoxType{'p', 's', 's', 'h'}
	SaioBoxType = BoxType{'s', 'a', 'i', 'o'}
	SaizBoxType = BoxType{'s', 'a', 'i', 'z'}
	SchiBoxType = BoxType{'s', 'c', 'h', 'i'}
	SchmBoxType = BoxType{'s', 'c', 'h', 'm'}
	SencBoxType = BoxType{'s', 'e', 'n', 'c'}
	SinfBoxType = BoxType{'s', 'i', 'n', 'f'}
	SmhdBoxType = BoxType{'s', 'm', 'h', 'd'}
	StblBoxType = BoxType{'s', 't', 'b', 'l'}
	StcoBoxType = BoxType{'s', 't', 'c', 'o'}
	StdpBoxType = BoxType{'s', 't', 'd', 'p'}
	StscBoxType = BoxType{'s', 't', 's', 'c'}
	StsdBoxType = BoxType{'s', 't', 's', 'd'}
	StssBoxType = BoxType{'s', 't', 's', 's'}
	StszBoxType = BoxType{'s', 't', 's', 'z'}
	SttsBoxType = BoxType{'s', 't', 't', 's'}
	TencBoxType = BoxType{'t', 'e', 'n', 'c'}
	TfhdBoxType = BoxType{'t', 'f', 'h', 'd'}
	TkhdBoxType = BoxType{'t', 'k', 'h', 'd'}
	TrakBoxType = BoxType{'t', 'r', 'a', 'k'}
	TrafBoxType = BoxType{'t', 'r', 'a', 'f'}
	TrexBoxType = BoxType{'t', 'r', 'e', 'x'}
	TrunBoxType = BoxType{'t', 'r', 'u', 'n'}
	UuidBoxType = BoxType{'u', 'u', 'i', 'd'}
	UrlBoxType  = BoxType{'u', 'r', 'l', ' '}
	UrnBoxType  = BoxType{'u', 'r', 'n', ' '}
	VmhdBoxType = BoxType{'v', 'm', 'h', 'd'}

	DvavBoxType = BoxType{'d', 'v', 'a', 'v'}
	Dva1BoxType = BoxType{'d', 'v', 'a', '1'}
	DvheBoxType = BoxType{'d', 'v', 'h', 'e'}
	Dvh1BoxType = BoxType{'d', 'v', 'h', '1'}
	Avc1BoxType = BoxType{'a', 'v', 'c', '1'}
	Avc2BoxType = BoxType{'a', 'v', 'c', '2'}
	Avc3BoxType = BoxType{'a', 'v', 'c', '3'}
	Avc4BoxType = BoxType{'a', 'v', 'c', '4'}
	Hev1BoxType = BoxType{'h', 'e', 'v', '1'}
	Hvc1BoxType = BoxType{'h', 'v', 'c', '1'}

	Avc1FourCC = FourCC{'a', 'v', 'c', '1'}
	Avc2FourCC = FourCC{'a', 'v', 'c', '2'}
	Avc3FourCC = FourCC{'a', 'v', 'c', '3'}
	Avc4FourCC = FourCC{'a', 'v', 'c', '4'}
	CencFourCC = FourCC{'c', 'e', 'n', 'c'}
	DashFourCC = FourCC{'d', 'a', 's', 'h'}
	DvavFourCC = FourCC{'d', 'v', 'a', 'v'}
	Dva1FourCC = FourCC{'d', 'v', 'a', '1'}
	DvheFourCC = FourCC{'d', 'v', 'h', 'e'}
	Dvh1FourCC = FourCC{'d', 'v', 'h', '1'}
	Hev1FourCC = FourCC{'h', 'e', 'v', '1'}
	HintFourCC = FourCC{'h', 'i', 'n', 't'}
	Hvc1FourCC = FourCC{'h', 'v', 'c', '1'}
	Iso2FourCC = FourCC{'i', 's', 'o', '2'}
	Iso6FourCC = FourCC{'i', 's', 'o', '6'}
	IsomFourCC = FourCC{'i', 's', 'o', 'm'}
	MetaFourCC = FourCC{'m', 'e', 't', 'a'}
	MsdhFourCC = FourCC{'m', 's', 'd', 'h'}
	SounFourCC = FourCC{'s', 'o', 'u', 'n'}
	VideFourCC = FourCC{'v', 'i', 'd', 'e'}

	NclcFourCC = FourCC{'n', 'c', 'l', 'c'}
	NclxFourCC = FourCC{'n', 'c', 'l', 'x'}
	RiccFourCC = FourCC{'r', 'I', 'C', 'C'}
	ProfFourCC = FourCC{'p', 'r', 'o', 'f'}

	SampleEncryptionBoxUserType = UserType{0xA2, 0x39, 0x4F, 0x52, 0x5A, 0x9B, 0x4F, 0x14, 0xA2, 0x44, 0x6C, 0x42, 0x7C, 0x64, 0x8D, 0xF4}
)
View Source
var BoxRegistry = make(map[BoxType]func() Box)
View Source
var ErrChildBoxNotSupported = errors.New("this box cannot have child boxes")
View Source
var ErrInvalidFormat = errors.New("mp4 format error")
View Source
var ErrUnsupportedSerialization = errors.New("serialization not supported")
View Source
var UUIDBoxRegistry = make(map[UserType]func() Box)

Functions

func NewSampleToNALWriter

func NewSampleToNALWriter(w io.Writer, lengthSizeMinusOne uint32) io.Writer

Types

type AVCConfigurationBox

type AVCConfigurationBox struct {
	Header
	NullContainer
	AVCConfig avc.AVCDecoderConfigurationRecord
}

func (*AVCConfigurationBox) Mp4BoxRead

func (b *AVCConfigurationBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (AVCConfigurationBox) Mp4BoxType

func (b AVCConfigurationBox) Mp4BoxType() BoxType

func (*AVCConfigurationBox) Mp4BoxUpdate

func (b *AVCConfigurationBox) Mp4BoxUpdate() uint32

func (*AVCConfigurationBox) Mp4BoxWrite

func (b *AVCConfigurationBox) Mp4BoxWrite(w io.Writer) (err error)

type BitRateBox

type BitRateBox struct {
	Header
	NullContainer
	BufferSizeDB uint32
	MaxBitrate   uint32
	AvgBitrate   uint32
}

8.5.2 Sample Description Box

func (*BitRateBox) Mp4BoxRead

func (b *BitRateBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (BitRateBox) Mp4BoxType

func (b BitRateBox) Mp4BoxType() BoxType

func (*BitRateBox) Mp4BoxUpdate

func (b *BitRateBox) Mp4BoxUpdate() uint32

func (*BitRateBox) Mp4BoxWrite

func (b *BitRateBox) Mp4BoxWrite(w io.Writer) (err error)

type Box

type Box interface {
	BoxContainer

	// Basic methods
	Mp4BoxSize() uint32
	Mp4BoxType() BoxType
	Mp4BoxSetType(boxType BoxType)
	Mp4BoxUserType() UserType
	Mp4BoxSetUserType(userType UserType)

	// I/O methods
	Mp4BoxUpdate() uint32
	Mp4BoxRead(r io.Reader, header *Header) (err error)
	Mp4BoxWrite(w io.Writer) (err error)
}

func NewBox

func NewBox(boxType BoxType) (box Box)

func NewUUIDBox

func NewUUIDBox(userType UserType) (box Box)

func ReadBox

func ReadBox(r io.Reader) (box Box, err error)

func ReadBoxAfterHeader

func ReadBoxAfterHeader(r io.Reader, header *Header) (box Box, err error)

type BoxContainer

type BoxContainer interface {
	Mp4BoxIsContainer() bool
	Mp4BoxUpdateChildren() uint32
	Mp4BoxReadChildren(r io.Reader, size uint32) (err error)
	Mp4BoxWriteChildren(w io.Writer) (err error)

	Mp4BoxAppend(box Box) (err error)
	Mp4BoxReplaceChildren(boxes []Box) (err error)
	Mp4BoxChildren() []Box
	Mp4BoxFirstChild() Box
	Mp4BoxLastChild() Box
	Mp4BoxFindAll(boxType BoxType) []Box
	Mp4BoxFindFirst(boxType BoxType) Box
	Mp4BoxFindLast(boxType BoxType) Box
	Mp4BoxRecursiveFindAll(boxType BoxType) []Box
	Mp4BoxRecursiveFindFirst(boxType BoxType) Box
}

type BoxType

type BoxType FourCC

type ChunkOffsetBox

type ChunkOffsetBox struct {
	FullHeader
	NullContainer
	Entries []ChunkOffsetEntry
}

The chunk offset table gives the index of each chunk into the containing file. There are two variants, permitting the use of 32‐bit or 64‐bit offsets. The latter is useful when managing very large presentations. At most one of these variants will occur in any single instance of a sample table.

Offsets are file offsets, not the offset into any box within the file (e.g. Media Data Box). This permits referring to media data in files without any box structure. It does also mean that care must be taken when constructing a self‐contained ISO file with its metadata (Movie Box) at the front, as the size of the Movie Box will affect the chunk offsets to the media data.

func (*ChunkOffsetBox) Mp4BoxRead

func (b *ChunkOffsetBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (ChunkOffsetBox) Mp4BoxType

func (b ChunkOffsetBox) Mp4BoxType() BoxType

func (*ChunkOffsetBox) Mp4BoxUpdate

func (b *ChunkOffsetBox) Mp4BoxUpdate() uint32

func (*ChunkOffsetBox) Mp4BoxWrite

func (b *ChunkOffsetBox) Mp4BoxWrite(w io.Writer) (err error)

type ChunkOffsetEntry

type ChunkOffsetEntry struct {
	// is a 32 bit integer that gives the offset of the start of a chunk into
	// its containing media file.
	ChunkOffset uint32
}

type CleanApertureBox

type CleanApertureBox struct {
	Header
	NullContainer

	// a fractional number which defines the exact clean aperture width, in
	// counted pixels, of the video image
	CleanApertureWidthN uint32
	CleanApertureWidthD uint32

	// a fractional number which defines the exact clean aperture height, in
	// counted pixels, of the video image
	CleanApertureHeightN uint32
	CleanApertureHeightD uint32

	// a fractional number which defines the horizontal offset of clean aperture
	// centre minus (width‐1)/2. Typically 0.
	HorizOffN uint32
	HorizOffD uint32

	// a fractional number which defines the vertical offset of clean aperture
	// centre minus (height‐1)/2. Typically 0.
	VertOffN uint32
	VertOffD uint32
}

The pixel aspect ratio and clean aperture of the video may be specified using the ‘pasp’ and ‘clap’ sample entry boxes, respectively. These are both optional; if present, they over‐ride the declarations (if any) in structures specific to the video codec, which structures should be examined if these boxes are absent. For maximum compatibility, these boxes should follow, not precede, any boxes defined in or required by derived specifications.

In the PixelAspectRatioBox, hSpacing and vSpacing have the same units, but those units are unspecified: only the ratio matters. hSpacing and vSpacing may or may not be in reduced terms, and they may reduce to 1/1. Both of them must be positive.

They are defined as the aspect ratio of a pixel, in arbitrary units. If a pixel appears H wide and V tall, then hSpacing/vSpacing is equal to H/V. This means that a square on the display that is n pixels tall needs to be n*vSpacing/hSpacing pixels wide to appear square.

> NOTE When adjusting pixel aspect ratio, normally, the horizontal dimension of the video is scaled, if needed (i.e. if the final display system has a different pixel aspect ratio from the video source).

> NOTE It is recommended that the original pixels, and the composed transform, be carried through the pipeline as far as possible. If the transformation resulting from ‘correcting’ pixel aspect ratio to a square grid, normalizing to the track dimensions, composition or placement (e.g. track and/or movie matrix), and normalizing to the display characteristics, is a unity matrix, then no re‐sampling need be done. In particular, video should not be resampled more than once in the process of rendering, if at all possible.

There are notionally four values in the CleanApertureBox. These parameters are represented as a fraction N/D. The fraction may or may not be in reduced terms. We refer to the pair of parameters fooN and fooD as foo. For horizOff and vertOff, D must be positive and N may be positive or negative. For cleanApertureWidth and cleanApertureHeight, both N and D must be positive.

> NOTE These are fractional numbers for several reasons. First, in some systems the exact width after pixel aspect ratio correction is integral, not the pixel count before that correction. Second, if video is resized in the full aperture, the exact expression for the clean aperture may not be integral. Finally, because this is represented using centre and offset, a division by two is needed, and so half‐values can occur.

Considering the pixel dimensions as defined by the VisualSampleEntry width and height. If picture centre of the image is at pcX and pcY, then horizOff and vertOff are defined as follows:

pcX = horizOff + (width - 1)/2
pcY = vertOff + (height - 1)/2;

Typically, horizOff and vertOff are zero, so the image is centred about the picture centre. The leftmost/rightmost pixel and the topmost/bottommost line of the clean aperture fall at:

pcX ± (cleanApertureWidth - 1)/2
pcY ± (cleanApertureHeight - 1)/2;

func (*CleanApertureBox) Mp4BoxRead

func (b *CleanApertureBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (CleanApertureBox) Mp4BoxType

func (b CleanApertureBox) Mp4BoxType() BoxType

func (*CleanApertureBox) Mp4BoxUpdate

func (b *CleanApertureBox) Mp4BoxUpdate() uint32

func (*CleanApertureBox) Mp4BoxWrite

func (b *CleanApertureBox) Mp4BoxWrite(w io.Writer) (err error)

type ColourInformationBox

type ColourInformationBox struct {
	Header
	NullContainer

	// An indication of the type of colour information supplied. For colour_type
	// ‘nclx’: these fields are exactly the four bytes defined for
	// PTM_COLOR_INFO( ) in A.7.2 of ISO/IEC 29199‐2 but note that the full
	// range flag is here in a different bit position
	ColourType FourCC

	ColourPrimaries         uint16
	TransferCharacteristics uint16
	MatrixCoefficients      uint16
	FullRange               bool

	ICCProfile []byte

	UnknownData []byte
}

12.1.5 Colour information

func (*ColourInformationBox) Mp4BoxRead

func (b *ColourInformationBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (ColourInformationBox) Mp4BoxType

func (b ColourInformationBox) Mp4BoxType() BoxType

func (*ColourInformationBox) Mp4BoxUpdate

func (b *ColourInformationBox) Mp4BoxUpdate() uint32

func (*ColourInformationBox) Mp4BoxWrite

func (b *ColourInformationBox) Mp4BoxWrite(w io.Writer) (err error)

type CompositionOffsetBox

type CompositionOffsetBox struct {
	FullHeader
	NullContainer
	Entries []CompositionOffsetEntry
}

This box provides the offset between decoding time and composition time. In version 0 of this box the decoding time must be less than the composition time, and the offsets are expressed as unsigned numbers such that CT(n) = DT(n) + CTTS(n) where CTTS(n) is the (uncompressed) table entry for sample n. In version 1 of this box, the composition timeline and the decoding timeline are still derived from each other, but the offsets are signed. It is recommended that for the computed composition timestamps, there is exactly one with the value 0 (zero).

For either version of the box, each sample must have a unique composition timestamp value, that is, the timestamp for two samples shall never be the same.

It may be true that there is no frame to compose at time 0; the handling of this is unspecified (systems might display the first frame for longer, or a suitable fill colour).

When version 1 of this box is used, the CompositionToDecodeBox may also be present in the sample table to relate the composition and decoding timelines. When backwards‐compatibility or compatibility with an unknown set of readers is desired, version 0 of this box should be used when possible. In either version of this box, but particularly under version 0, if it is desired that the media start at track time 0, and the first media sample does not have a composition time of 0, an edit list may be used to ‘shift’ the media to time 0.

The composition time to sample table is optional and must only be present if DT and CT differ for any samples.

Hint tracks do not use this box.

func (*CompositionOffsetBox) Mp4BoxRead

func (b *CompositionOffsetBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (CompositionOffsetBox) Mp4BoxType

func (b CompositionOffsetBox) Mp4BoxType() BoxType

func (*CompositionOffsetBox) Mp4BoxUpdate

func (b *CompositionOffsetBox) Mp4BoxUpdate() uint32

func (*CompositionOffsetBox) Mp4BoxWrite

func (b *CompositionOffsetBox) Mp4BoxWrite(w io.Writer) (err error)

type CompositionOffsetEntry

type CompositionOffsetEntry struct {
	// is an integer that counts the number of consecutive samples that have the
	// given offset.
	SampleCount uint32

	// is an integer that gives the offset between CT and DT, such that CT(n) =
	// DT(n) + CTTS(n).
	SampleOffset int64
}

type Container

type Container struct {
	Children        []Box
	TypeChildrenMap map[BoxType][]Box
}

func (*Container) Mp4BoxAppend

func (b *Container) Mp4BoxAppend(box Box) (err error)

func (*Container) Mp4BoxChildren

func (b *Container) Mp4BoxChildren() []Box

func (*Container) Mp4BoxFindAll

func (b *Container) Mp4BoxFindAll(boxType BoxType) []Box

func (*Container) Mp4BoxFindFirst

func (b *Container) Mp4BoxFindFirst(boxType BoxType) Box

func (*Container) Mp4BoxFindLast

func (b *Container) Mp4BoxFindLast(boxType BoxType) Box

func (*Container) Mp4BoxFirstChild

func (b *Container) Mp4BoxFirstChild() Box

func (*Container) Mp4BoxIsContainer

func (b *Container) Mp4BoxIsContainer() bool

func (*Container) Mp4BoxLastChild

func (b *Container) Mp4BoxLastChild() Box

func (*Container) Mp4BoxReadChildren

func (b *Container) Mp4BoxReadChildren(r io.Reader, size uint32) (err error)

func (*Container) Mp4BoxRecursiveFindAll

func (b *Container) Mp4BoxRecursiveFindAll(boxType BoxType) []Box

func (*Container) Mp4BoxRecursiveFindFirst

func (b *Container) Mp4BoxRecursiveFindFirst(boxType BoxType) (box Box)

func (*Container) Mp4BoxReplaceChildren

func (b *Container) Mp4BoxReplaceChildren(boxes []Box) (err error)

func (*Container) Mp4BoxUpdateChildren

func (b *Container) Mp4BoxUpdateChildren() (size uint32)

func (*Container) Mp4BoxWriteChildren

func (b *Container) Mp4BoxWriteChildren(w io.Writer) (err error)

type DOVIConfigurationBox

type DOVIConfigurationBox struct {
	Header
	NullContainer
	DOVIConfig dovi.DOVIDecoderConfigurationRecord
}

func (*DOVIConfigurationBox) Mp4BoxRead

func (b *DOVIConfigurationBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (DOVIConfigurationBox) Mp4BoxType

func (b DOVIConfigurationBox) Mp4BoxType() BoxType

func (*DOVIConfigurationBox) Mp4BoxUpdate

func (b *DOVIConfigurationBox) Mp4BoxUpdate() uint32

func (*DOVIConfigurationBox) Mp4BoxWrite

func (b *DOVIConfigurationBox) Mp4BoxWrite(w io.Writer) (err error)

type DataEntryBox

type DataEntryBox struct {
	FullHeader
	NullContainer

	// Name is a URN, and is required in a URN entry.
	Name NullTerminatedString

	// Location is a URL, and is required in a URL entry and optional in a URN
	// entry, where it gives a location to find the resource with the given
	// name. Each is a null‐terminated string using UTF‐8 characters. If the
	// self‐contained flag is set, the URL form is used and no string is
	// present; the box terminates with the entry‐flags field. The URL type
	// should be of a service that delivers a file (e.g. URLs of type file,
	// http, ftp etc.), and which services ideally also permit random access.
	// Relative URLs are permissible and are relative to the file containing the
	// Movie Box that contains this data reference.
	Location NullTerminatedString
}

The data reference object contains a table of data references (normally URLs) that declare the location(s) of the media data used within the presentation. The data reference index in the sample description ties entries in this table to the samples in the track. A track may be split over several sources in this way.

If the flag is set indicating that the data is in the same file as this box, then no string (not even an empty one) shall be supplied in the entry field.

The entry_count in the DataReferenceBox shall be 1 or greater; each DataEntryBox within the DataReferenceBox shall be either a DataEntryUrnBox or a DataEntryUrlBox.

> NOTE Though the count is 32 bits, the number of items is usually much fewer, and is restricted by the fact that the reference index in the sample table is only 16 bits

When a file that has data entries with the flag set indicating that the media data is in the same file, is split into segments for transport, the value of this flag does not change, as the file is (logically) reassembled after the transport operation.

func (*DataEntryBox) Mp4BoxRead

func (b *DataEntryBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (DataEntryBox) Mp4BoxType

func (b DataEntryBox) Mp4BoxType() BoxType

func (*DataEntryBox) Mp4BoxUpdate

func (b *DataEntryBox) Mp4BoxUpdate() uint32

func (*DataEntryBox) Mp4BoxWrite

func (b *DataEntryBox) Mp4BoxWrite(w io.Writer) (err error)

type DataInformationBox

type DataInformationBox struct {
	Header
	Container
}

The data information box contains objects that declare the location of the media information in a track.

func (*DataInformationBox) Mp4BoxRead

func (b *DataInformationBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (DataInformationBox) Mp4BoxType

func (b DataInformationBox) Mp4BoxType() BoxType

func (*DataInformationBox) Mp4BoxUpdate

func (b *DataInformationBox) Mp4BoxUpdate() uint32

func (*DataInformationBox) Mp4BoxWrite

func (b *DataInformationBox) Mp4BoxWrite(w io.Writer) (err error)

type DataReferenceBox

type DataReferenceBox struct {
	FullHeader
	Container
}

The data reference object contains a table of data references (normally URLs) that declare the location(s) of the media data used within the presentation. The data reference index in the sample description ties entries in this table to the samples in the track. A track may be split over several sources in this way.

If the flag is set indicating that the data is in the same file as this box, then no string (not even an empty one) shall be supplied in the entry field.

The entry_count in the DataReferenceBox shall be 1 or greater; each DataEntryBox within the DataReferenceBox shall be either a DataEntryUrnBox or a DataEntryUrlBox.

> NOTE Though the count is 32 bits, the number of items is usually much fewer, and is restricted by the fact that the reference index in the sample table is only 16 bits

When a file that has data entries with the flag set indicating that the media data is in the same file, is split into segments for transport, the value of this flag does not change, as the file is (logically) reassembled after the transport operation.

func (*DataReferenceBox) Mp4BoxRead

func (b *DataReferenceBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (DataReferenceBox) Mp4BoxType

func (b DataReferenceBox) Mp4BoxType() BoxType

func (*DataReferenceBox) Mp4BoxUpdate

func (b *DataReferenceBox) Mp4BoxUpdate() uint32

func (*DataReferenceBox) Mp4BoxWrite

func (b *DataReferenceBox) Mp4BoxWrite(w io.Writer) (err error)

type DegradationPriorityBox

type DegradationPriorityBox struct {
	FullHeader
	NullContainer

	SamplePriority []uint16
}

This box contains the degradation priority of each sample. The values are stored in the table, one for each sample. The size of the table, sample_count is taken from the sample_count in the Sample Size Box ('stsz'). Specifications derived from this define the exact meaning and acceptable range of the priority field.

func (*DegradationPriorityBox) Mp4BoxRead

func (b *DegradationPriorityBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (DegradationPriorityBox) Mp4BoxType

func (b DegradationPriorityBox) Mp4BoxType() BoxType

func (*DegradationPriorityBox) Mp4BoxUpdate

func (b *DegradationPriorityBox) Mp4BoxUpdate() uint32

func (*DegradationPriorityBox) Mp4BoxWrite

func (b *DegradationPriorityBox) Mp4BoxWrite(w io.Writer) (err error)

type DolbyVisionELAVCConfigurationBox

type DolbyVisionELAVCConfigurationBox struct {
	Header
	NullContainer
	AVCConfig avc.AVCDecoderConfigurationRecord
}

func (*DolbyVisionELAVCConfigurationBox) Mp4BoxRead

func (b *DolbyVisionELAVCConfigurationBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (DolbyVisionELAVCConfigurationBox) Mp4BoxType

func (*DolbyVisionELAVCConfigurationBox) Mp4BoxUpdate

func (b *DolbyVisionELAVCConfigurationBox) Mp4BoxUpdate() uint32

func (*DolbyVisionELAVCConfigurationBox) Mp4BoxWrite

func (b *DolbyVisionELAVCConfigurationBox) Mp4BoxWrite(w io.Writer) (err error)

type DolbyVisionELHEVCConfigurationBox

type DolbyVisionELHEVCConfigurationBox struct {
	Header
	NullContainer
	HEVCConfig hevc.HEVCDecoderConfigurationRecord
}

func (*DolbyVisionELHEVCConfigurationBox) Mp4BoxRead

func (b *DolbyVisionELHEVCConfigurationBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (DolbyVisionELHEVCConfigurationBox) Mp4BoxType

func (*DolbyVisionELHEVCConfigurationBox) Mp4BoxUpdate

func (b *DolbyVisionELHEVCConfigurationBox) Mp4BoxUpdate() uint32

func (*DolbyVisionELHEVCConfigurationBox) Mp4BoxWrite

func (b *DolbyVisionELHEVCConfigurationBox) Mp4BoxWrite(w io.Writer) (err error)

type ExtendedLanguageBox

type ExtendedLanguageBox struct {
	FullHeader
	NullContainer

	// is a NULL‐terminated C string containing an RFC 4646 (BCP 47) compliant
	// language tag string, such as "en‐US", "fr‐FR", or "zh‐CN".
	ExtendedLanguage NullTerminatedString
}

The extended language tag box represents media language information, based on RFC 4646 (Best Common Practices – BCP – 47) industry standard. It is an optional peer of the media header box, and must occur after the media header box.

The extended language tag can provide better language information than the language field in the Media Header, including information such as region, script, variation, and so on, as parts (or subtags). The extended language tag box is optional, and if it is absent the media language should be used. The extended language tag overrides the media language if they are not consistent.

For best compatibility with earlier players, if an extended language tag is specified, the most compatible language code should be specified in the language field of the Media Header box (for example, "eng" if the extended language tag is "en‐UK"). If there is no reasonably compatible tag, the packed form of 'und' can be used.

func (*ExtendedLanguageBox) Mp4BoxRead

func (b *ExtendedLanguageBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (ExtendedLanguageBox) Mp4BoxType

func (b ExtendedLanguageBox) Mp4BoxType() BoxType

func (*ExtendedLanguageBox) Mp4BoxUpdate

func (b *ExtendedLanguageBox) Mp4BoxUpdate() uint32

func (*ExtendedLanguageBox) Mp4BoxWrite

func (b *ExtendedLanguageBox) Mp4BoxWrite(w io.Writer) (err error)

type FileTypeBox

type FileTypeBox struct {
	Header
	NullContainer
	MajorBrand       FourCC   // brand identifier
	MinorVersion     uint32   // an informative integer for the minor version of the major brand
	CompatibleBrands []FourCC // a list of brands
}

Files written to this version of this specification must contain a file‐type box. For compatibility with an earlier version of this specification, files may be conformant to this specification and not contain a filetype box. Files with no file‐type box should be read as if they contained an FTYP box with Major_brand='mp41', minor_version=0, and the single compatible brand 'mp41'.

A media‐file structured to this part of this specification may be compatible with more than one detailed specification, and it is therefore not always possible to speak of a single ‘type’ or ‘brand’ for the file. This means that the utility of the file name extension and Multipurpose Internet Mail Extension (MIME) type are somewhat reduced.

This box must be placed as early as possible in the file (e.g. after any obligatory signature, but before any significant variable‐size boxes such as a Movie Box, Media Data Box, or Free Space). It identifies which specification is the ‘best use’ of the file, and a minor version of that specification; and also a set of other specifications to which the file complies. Readers implementing this format should attempt to read files that are marked as compatible with any of the specifications that the reader implements. Any incompatible change in a specification should therefore register a new ‘brand’ identifier to identify files conformant to the new specification.

The minor version is informative only. It does not appear for compatible‐brands, and must not be used to determine the conformance of a file to a standard. It may allow more precise identification of the major specification, for inspection, debugging, or improved decoding.

Files would normally be externally identified (e.g. with a file extension or mime type) that identifies the‘best use’ (major brand), or the brand that the author believes will provide the greatest compatibility.

func (*FileTypeBox) Mp4BoxRead

func (b *FileTypeBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (FileTypeBox) Mp4BoxType

func (b FileTypeBox) Mp4BoxType() BoxType

func (*FileTypeBox) Mp4BoxUpdate

func (b *FileTypeBox) Mp4BoxUpdate() uint32

func (*FileTypeBox) Mp4BoxWrite

func (b *FileTypeBox) Mp4BoxWrite(w io.Writer) (err error)

type FourCC

type FourCC [4]byte
type FullHeader struct {
	Header
	Version uint8
	Flags   [3]uint8
}

func (FullHeader) Mp4BoxFlags

func (h FullHeader) Mp4BoxFlags() uint32

func (*FullHeader) Mp4BoxSetFlags

func (h *FullHeader) Mp4BoxSetFlags(flags uint32)

func (*FullHeader) ReadHeader

func (h *FullHeader) ReadHeader(r io.Reader, header *Header) (err error)

func (*FullHeader) WriteHeader

func (h *FullHeader) WriteHeader(w io.Writer) (err error)

type HEVCConfigurationBox

type HEVCConfigurationBox struct {
	Header
	NullContainer
	HEVCConfig hevc.HEVCDecoderConfigurationRecord
}

func (*HEVCConfigurationBox) Mp4BoxRead

func (b *HEVCConfigurationBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (HEVCConfigurationBox) Mp4BoxType

func (b HEVCConfigurationBox) Mp4BoxType() BoxType

func (*HEVCConfigurationBox) Mp4BoxUpdate

func (b *HEVCConfigurationBox) Mp4BoxUpdate() uint32

func (*HEVCConfigurationBox) Mp4BoxWrite

func (b *HEVCConfigurationBox) Mp4BoxWrite(w io.Writer) (err error)

type Handler

type Handler struct {
	HandleMp4Box func(box Box) error
}

type HandlerBox

type HandlerBox struct {
	FullHeader
	NullContainer

	// when present in a media box, contains a value as defined in clause 12, or
	// a value from a derived specification, or registration.
	//
	// when present in a meta box, contains an appropriate value to indicate the
	// format of the meta box contents. The value ‘null’ can be used in the
	// primary meta box to indicate that it is merely being used to hold
	// resources.
	HandlerType FourCC

	// is a null‐terminated string in UTF‐8 characters which gives a
	// human‐readable name for the track type (for debugging and inspection
	// purposes).
	Name NullTerminatedString
}

This box within a Media Box declares media type of the track, and thus the process by which the mediadata in the track is presented. For example, a format for which the decoder delivers video would be stored in a video track, identified by being handled by a video handler. The documentation of the storage of a media format identifies the media type which that format uses.

This box when present within a Meta Box, declares the structure or format of the 'meta' box contents.

There is a general handler for metadata streams of any type; the specific format is identified by the sample entry, as for video or audio, for example.

func (*HandlerBox) Mp4BoxRead

func (b *HandlerBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (HandlerBox) Mp4BoxType

func (b HandlerBox) Mp4BoxType() BoxType

func (*HandlerBox) Mp4BoxUpdate

func (b *HandlerBox) Mp4BoxUpdate() uint32

func (*HandlerBox) Mp4BoxWrite

func (b *HandlerBox) Mp4BoxWrite(w io.Writer) (err error)
type Header struct {
	Size     uint32
	Type     BoxType
	UserType UserType
}

func ReadHeader

func ReadHeader(r io.Reader) (header *Header, err error)

func (Header) HeaderSize

func (h Header) HeaderSize() uint32

func (*Header) Mp4BoxSetType

func (h *Header) Mp4BoxSetType(boxType BoxType)

func (*Header) Mp4BoxSetUserType

func (h *Header) Mp4BoxSetUserType(userType UserType)

func (Header) Mp4BoxSize

func (h Header) Mp4BoxSize() uint32

func (Header) Mp4BoxType

func (h Header) Mp4BoxType() BoxType

func (Header) Mp4BoxUserType

func (h Header) Mp4BoxUserType() UserType

func (*Header) ReadHeader

func (h *Header) ReadHeader(r io.Reader, header *Header) (err error)

func (*Header) WriteHeader

func (h *Header) WriteHeader(w io.Writer) (err error)

type MediaBox

type MediaBox struct {
	Header
	Container
}

The media declaration container contains all the objects that declare information about the media data within a track.

func (*MediaBox) Mp4BoxRead

func (b *MediaBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (MediaBox) Mp4BoxType

func (b MediaBox) Mp4BoxType() BoxType

func (*MediaBox) Mp4BoxUpdate

func (b *MediaBox) Mp4BoxUpdate() uint32

func (*MediaBox) Mp4BoxWrite

func (b *MediaBox) Mp4BoxWrite(w io.Writer) (err error)

type MediaHeaderBox

type MediaHeaderBox struct {
	FullHeader
	NullContainer

	// is an integer that declares the creation time of the media in this track
	// (in seconds since midnight, Jan. 1, 1904, in UTC time).
	CreationTime uint64

	// is an integer that declares the most recent time the media in this track was
	// modified (in seconds since midnight, Jan. 1, 1904, in UTC time).
	ModificationTime uint64

	// is an integer that specifies the time‐scale for this media; this is the
	// number of time units that pass in one second. For example, a time
	// coordinate system that measures time in sixtieths of a second has a time
	// scale of 60.
	Timescale uint32

	// is an integer that declares the duration of this media (in the scale of
	// the timescale). If the duration cannot be determined then duration is set
	// to all 1s.
	Duration uint64

	// declares the language code for this media. See ISO 639‐2/T for the set of three
	// character codes. Each character is packed as the difference between its ASCII
	// value and 0x60. Since the code is confined to being three lower‐case letters,
	// these values are strictly positive.
	Language language.Base
}

The media header declares overall information that is media‐independent, and relevant to characteristics of the media in a track.

func (*MediaHeaderBox) Mp4BoxRead

func (b *MediaHeaderBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (MediaHeaderBox) Mp4BoxType

func (b MediaHeaderBox) Mp4BoxType() BoxType

func (*MediaHeaderBox) Mp4BoxUpdate

func (b *MediaHeaderBox) Mp4BoxUpdate() uint32

func (*MediaHeaderBox) Mp4BoxWrite

func (b *MediaHeaderBox) Mp4BoxWrite(w io.Writer) (err error)

type MediaInformationBox

type MediaInformationBox struct {
	Header
	Container
}

This box contains all the objects that declare characteristic information of the media in the track.

func (*MediaInformationBox) Mp4BoxRead

func (b *MediaInformationBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (MediaInformationBox) Mp4BoxType

func (b MediaInformationBox) Mp4BoxType() BoxType

func (*MediaInformationBox) Mp4BoxUpdate

func (b *MediaInformationBox) Mp4BoxUpdate() uint32

func (*MediaInformationBox) Mp4BoxWrite

func (b *MediaInformationBox) Mp4BoxWrite(w io.Writer) (err error)

type MovieBox

type MovieBox struct {
	Header
	Container
}

The metadata for a presentation is stored in the single Movie Box which occurs at the top‐level of a file. Normally this box is close to the beginning or end of the file, though this is not required.

func (*MovieBox) Mp4BoxRead

func (b *MovieBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (MovieBox) Mp4BoxType

func (b MovieBox) Mp4BoxType() BoxType

func (*MovieBox) Mp4BoxUpdate

func (b *MovieBox) Mp4BoxUpdate() uint32

func (*MovieBox) Mp4BoxWrite

func (b *MovieBox) Mp4BoxWrite(w io.Writer) (err error)

type MovieExtendsBox

type MovieExtendsBox struct {
	Header
	Container
}

This box warns readers that there might be Movie Fragment Boxes in this file. To know of all samples in the tracks, these Movie Fragment Boxes must be found and scanned in order, and their information logically added to that found in the Movie Box.

There is a narrative introduction to Movie Fragments in Annex A.

func (*MovieExtendsBox) Mp4BoxRead

func (b *MovieExtendsBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (MovieExtendsBox) Mp4BoxType

func (b MovieExtendsBox) Mp4BoxType() BoxType

func (*MovieExtendsBox) Mp4BoxUpdate

func (b *MovieExtendsBox) Mp4BoxUpdate() uint32

func (*MovieExtendsBox) Mp4BoxWrite

func (b *MovieExtendsBox) Mp4BoxWrite(w io.Writer) (err error)

type MovieFragmentBox

type MovieFragmentBox struct {
	Header
	Container
}

The movie fragments extend the presentation in time. They provide the information that would previously have been in the Movie Box. The actual samples are in Media Data Boxes, as usual, if they are in the same file. The data reference index is in the sample description, so it is possible to build incremental presentations where the media data is in files other than the file containing the Movie Box.

The Movie Fragment Box is a top‐level box, (i.e. a peer to the Movie Box and Media Data boxes). It contains a Movie Fragment Header Box, and then one or more Track Fragment Boxes.

> NOTE There is no requirement that any particular movie fragment extend all tracks present in the movie header, and there is no restriction on the location of the media data referred to by the movie fragments. However, derived specifications may make such restrictions.

func (*MovieFragmentBox) Mp4BoxRead

func (b *MovieFragmentBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (MovieFragmentBox) Mp4BoxType

func (b MovieFragmentBox) Mp4BoxType() BoxType

func (*MovieFragmentBox) Mp4BoxUpdate

func (b *MovieFragmentBox) Mp4BoxUpdate() uint32

func (*MovieFragmentBox) Mp4BoxWrite

func (b *MovieFragmentBox) Mp4BoxWrite(w io.Writer) (err error)

type MovieFragmentHeaderBox

type MovieFragmentHeaderBox struct {
	FullHeader
	NullContainer

	// a number associated with this fragment
	SequenceNumber uint32
}

The movie fragment header contains a sequence number, as a safety check. The sequence number usually starts at 1 and increases for each movie fragment in the file, in the order in which they occur. This allows readers to verify integrity of the sequence in environments where undesired re‐ordering might occur.

func (*MovieFragmentHeaderBox) Mp4BoxRead

func (b *MovieFragmentHeaderBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (MovieFragmentHeaderBox) Mp4BoxType

func (b MovieFragmentHeaderBox) Mp4BoxType() BoxType

func (*MovieFragmentHeaderBox) Mp4BoxUpdate

func (b *MovieFragmentHeaderBox) Mp4BoxUpdate() uint32

func (*MovieFragmentHeaderBox) Mp4BoxWrite

func (b *MovieFragmentHeaderBox) Mp4BoxWrite(w io.Writer) (err error)

type MovieHeaderBox

type MovieHeaderBox struct {
	FullHeader
	NullContainer

	// is an integer that declares the creation time of the presentation (in
	// seconds since midnight, Jan. 1, 1904, in UTC time)
	CreationTime uint64

	// is an integer that declares the most recent time the presentation was
	// modified (in seconds since midnight, Jan. 1, 1904, in UTC time)
	ModificationTime uint64

	// is an integer that specifies the time‐scale for the entire presentation;
	// this is the number of time units that pass in one second. For example, a
	// time coordinate system that measures time in sixtieths of a second has a
	// time scale of 60.
	Timescale uint32

	// is an integer that declares length of the presentation (in the indicated
	// timescale). This property is derived from the presentation’s tracks: the
	// value of this field corresponds to the duration of the longest track in
	// the presentation. If the duration cannot be determined then duration is
	// set to all 1s.
	Duration uint64

	// is a fixed point 16.16 number that indicates the preferred rate to play
	// the presentation; 1.0 (0x00010000) is normal forward playback
	Rate int32

	// is a fixed point 8.8 number that indicates the preferred playback volume.
	// 1.0 (0x0100) is full volume.
	Volume int16

	// provides a transformation matrix for the video; (u,v,w) are restricted
	// here to (0,0,1), hex values (0,0,0x40000000).
	Matrix [9]int32

	// is a non‐zero integer that indicates a value to use for the track ID of
	// the next track to be added to this presentation. Zero is not a valid
	// track ID value. The value of next_track_ID shall be larger than the
	// largest track‐ID in use. If this value is equal to all 1s (32‐bit
	// maxint), and a new media track is to be added, then a search must be made
	// in the file for an unused track identifier.
	NextTrackID uint32
}

This box defines overall information which is media‐independent, and relevant to the entire presentation considered as a whole.

func (*MovieHeaderBox) Mp4BoxRead

func (b *MovieHeaderBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (MovieHeaderBox) Mp4BoxType

func (b MovieHeaderBox) Mp4BoxType() BoxType

func (*MovieHeaderBox) Mp4BoxUpdate

func (b *MovieHeaderBox) Mp4BoxUpdate() uint32

func (*MovieHeaderBox) Mp4BoxWrite

func (b *MovieHeaderBox) Mp4BoxWrite(w io.Writer) (err error)

type NullContainer

type NullContainer struct{}

func (*NullContainer) Mp4BoxAppend

func (b *NullContainer) Mp4BoxAppend(box Box) error

func (*NullContainer) Mp4BoxChildren

func (b *NullContainer) Mp4BoxChildren() []Box

func (*NullContainer) Mp4BoxFindAll

func (b *NullContainer) Mp4BoxFindAll(boxType BoxType) []Box

func (*NullContainer) Mp4BoxFindFirst

func (b *NullContainer) Mp4BoxFindFirst(boxType BoxType) Box

func (*NullContainer) Mp4BoxFindLast

func (b *NullContainer) Mp4BoxFindLast(boxType BoxType) Box

func (*NullContainer) Mp4BoxFirstChild

func (b *NullContainer) Mp4BoxFirstChild() Box

func (*NullContainer) Mp4BoxIsContainer

func (b *NullContainer) Mp4BoxIsContainer() bool

func (*NullContainer) Mp4BoxLastChild

func (b *NullContainer) Mp4BoxLastChild() Box

func (*NullContainer) Mp4BoxReadChildren

func (b *NullContainer) Mp4BoxReadChildren(r io.Reader, size uint32) (err error)

func (*NullContainer) Mp4BoxRecursiveFindAll

func (b *NullContainer) Mp4BoxRecursiveFindAll(boxType BoxType) []Box

func (*NullContainer) Mp4BoxRecursiveFindFirst

func (b *NullContainer) Mp4BoxRecursiveFindFirst(boxType BoxType) (box Box)

func (*NullContainer) Mp4BoxReplaceChildren

func (b *NullContainer) Mp4BoxReplaceChildren(boxes []Box) error

func (*NullContainer) Mp4BoxUpdateChildren

func (b *NullContainer) Mp4BoxUpdateChildren() (size uint32)

func (*NullContainer) Mp4BoxWriteChildren

func (b *NullContainer) Mp4BoxWriteChildren(w io.Writer) (err error)

type NullMediaHeaderBox

type NullMediaHeaderBox struct {
	FullHeader
	NullContainer
}

Streams for which no specific media header is identified use a null Media Header Box, as defined here.

func (*NullMediaHeaderBox) Mp4BoxRead

func (b *NullMediaHeaderBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (NullMediaHeaderBox) Mp4BoxType

func (b NullMediaHeaderBox) Mp4BoxType() BoxType

func (*NullMediaHeaderBox) Mp4BoxUpdate

func (b *NullMediaHeaderBox) Mp4BoxUpdate() uint32

func (*NullMediaHeaderBox) Mp4BoxWrite

func (b *NullMediaHeaderBox) Mp4BoxWrite(w io.Writer) (err error)

type NullTerminatedString

type NullTerminatedString string

func (*NullTerminatedString) ReadOfSize

func (s *NullTerminatedString) ReadOfSize(r io.Reader, size uint32) (err error)

func (NullTerminatedString) Size

func (s NullTerminatedString) Size() uint32

func (NullTerminatedString) Write

func (s NullTerminatedString) Write(w io.Writer) (err error)

type OriginalFormatBox

type OriginalFormatBox struct {
	Header
	NullContainer

	// format of decrypted, encoded data (in case of protection) or
	// un-transformed sample entry (in case of restriction and complete track
	// information)
	DataFormat FourCC
}

The Original Format Box ‘frma’ contains the four‐character‐code of the original un‐transformed sample description:

func (*OriginalFormatBox) Mp4BoxRead

func (b *OriginalFormatBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (OriginalFormatBox) Mp4BoxType

func (b OriginalFormatBox) Mp4BoxType() BoxType

func (*OriginalFormatBox) Mp4BoxUpdate

func (b *OriginalFormatBox) Mp4BoxUpdate() uint32

func (*OriginalFormatBox) Mp4BoxWrite

func (b *OriginalFormatBox) Mp4BoxWrite(w io.Writer) (err error)

type PiffAlgorithmID

type PiffAlgorithmID uint32
const (
	PiffNotEncrypted PiffAlgorithmID = 0x00
	PiffAES128CTR    PiffAlgorithmID = 0x01
	PiffAES128CBC    PiffAlgorithmID = 0x02
)

type PiffIVSize

type PiffIVSize uint8
const (
	PiffIVSize64Bit  PiffIVSize = 8
	PiffIVSize128Bit PiffIVSize = 16
)

type PixelAspectRatioBox

type PixelAspectRatioBox struct {
	Header
	NullContainer

	// define the relative width and height of a pixel
	HSpacing uint32
	VSpacing uint32
}

The pixel aspect ratio and clean aperture of the video may be specified using the ‘pasp’ and ‘clap’ sample entry boxes, respectively. These are both optional; if present, they over‐ride the declarations (if any) in structures specific to the video codec, which structures should be examined if these boxes are absent. For maximum compatibility, these boxes should follow, not precede, any boxes defined in or required by derived specifications.

In the PixelAspectRatioBox, hSpacing and vSpacing have the same units, but those units are unspecified: only the ratio matters. hSpacing and vSpacing may or may not be in reduced terms, and they may reduce to 1/1. Both of them must be positive.

They are defined as the aspect ratio of a pixel, in arbitrary units. If a pixel appears H wide and V tall, then hSpacing/vSpacing is equal to H/V. This means that a square on the display that is n pixels tall needs to be n*vSpacing/hSpacing pixels wide to appear square.

> NOTE When adjusting pixel aspect ratio, normally, the horizontal dimension of the video is scaled, if needed (i.e. if the final display system has a different pixel aspect ratio from the video source).

> NOTE It is recommended that the original pixels, and the composed transform, be carried through the pipeline as far as possible. If the transformation resulting from ‘correcting’ pixel aspect ratio to a square grid, normalizing to the track dimensions, composition or placement (e.g. track and/or movie matrix), and normalizing to the display characteristics, is a unity matrix, then no re‐sampling need be done. In particular, video should not be resampled more than once in the process of rendering, if at all possible.

There are notionally four values in the CleanApertureBox. These parameters are represented as a fraction N/D. The fraction may or may not be in reduced terms. We refer to the pair of parameters fooN and fooD as foo. For horizOff and vertOff, D must be positive and N may be positive or negative. For cleanApertureWidth and cleanApertureHeight, both N and D must be positive.

> NOTE These are fractional numbers for several reasons. First, in some systems the exact width after pixel aspect ratio correction is integral, not the pixel count before that correction. Second, if video is resized in the full aperture, the exact expression for the clean aperture may not be integral. Finally, because this is represented using centre and offset, a division by two is needed, and so half‐values can occur.

Considering the pixel dimensions as defined by the VisualSampleEntry width and height. If picture centre of the image is at pcX and pcY, then horizOff and vertOff are defined as follows:

pcX = horizOff + (width - 1)/2
pcY = vertOff + (height - 1)/2;

Typically, horizOff and vertOff are zero, so the image is centred about the picture centre. The leftmost/rightmost pixel and the topmost/bottommost line of the clean aperture fall at:

pcX ± (cleanApertureWidth - 1)/2
pcY ± (cleanApertureHeight - 1)/2;

func (*PixelAspectRatioBox) Mp4BoxRead

func (b *PixelAspectRatioBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (PixelAspectRatioBox) Mp4BoxType

func (b PixelAspectRatioBox) Mp4BoxType() BoxType

func (*PixelAspectRatioBox) Mp4BoxUpdate

func (b *PixelAspectRatioBox) Mp4BoxUpdate() uint32

func (*PixelAspectRatioBox) Mp4BoxWrite

func (b *PixelAspectRatioBox) Mp4BoxWrite(w io.Writer) (err error)

type ProtectionSchemeInfoBox

type ProtectionSchemeInfoBox struct {
	Header
	Container
}

The Protection Scheme Information Box contains all the information required both to understand the encryption transform applied and its parameters, and also to find other information such as the kind and location of the key management system. It also documents the original (unencrypted) format of the media. The Protection Scheme Information Box is a container Box. It is mandatory in a sample entry that uses a code indicating a protected stream.

When used in a protected sample entry, this box must contain the original format box to document the original format. At least one of the following signalling methods must be used to identify the protection applied:

a) MPEG‐4 systems with IPMP: no other boxes, when IPMP descriptors in
   MPEG‐4 systems streams are used;

b) Scheme signalling: a SchemeTypeBox and SchemeInformationBox, when
   these are used (either both must occur, or neither).

At least one protection scheme information box must occur in a protected sample entry. When more than one occurs, they are equivalent, alternative, descriptions of the same protection. Readers should choose one to process.

func (*ProtectionSchemeInfoBox) Mp4BoxRead

func (b *ProtectionSchemeInfoBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (ProtectionSchemeInfoBox) Mp4BoxType

func (b ProtectionSchemeInfoBox) Mp4BoxType() BoxType

func (*ProtectionSchemeInfoBox) Mp4BoxUpdate

func (b *ProtectionSchemeInfoBox) Mp4BoxUpdate() uint32

func (*ProtectionSchemeInfoBox) Mp4BoxWrite

func (b *ProtectionSchemeInfoBox) Mp4BoxWrite(w io.Writer) (err error)

type ProtectionSystemSpecificHeaderBox

type ProtectionSystemSpecificHeaderBox struct {
	FullHeader
	NullContainer

	// specifies a UUID that uniquely identifies the content protection system
	// that this header belongs to.
	SystemID uuid.UUID

	// identifies a key identifier that the Data field applies to. If not set,
	// then the Data array SHALL apply to all KIDs in the movie or movie
	// fragment containing this box.
	KIDList [][16]byte

	// holds the content protection system specific data.
	Data []byte
}

The Track Encryption Box contains default values for the isProtected flag, Per_Sample_IV_Size, and KID for the entire track. In the case where pattern-based encryption is in effect, it supplies the pattern and when Constant IVs are in use, it supplies the Constant IV. These values are used as the encryption parameters for the samples in this track unless over-ridden by the sample group description associated with a group of samples. For files with only one key per track, this box allows the basic encryption parameters to be specified once per track instead of being repeated per sample.

If both the value of default_isProtected is 1 and default_Per_Sample_IV_Size is 0, then the default_constant_IV_size for all samples that use these settings SHALL be present. A Constant IV SHALL NOT be used with counter-mode encryption. A sample group description may supply keys or keys and Constant IVs for sample groups that override these default values for those samples mapped to the group.

> NOTE The version field of the Track Encryption Box is set to a value greater than zero when the pattern encryption defined in 9.6 is used and to zero otherwise.

func (*ProtectionSystemSpecificHeaderBox) Mp4BoxRead

func (b *ProtectionSystemSpecificHeaderBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (ProtectionSystemSpecificHeaderBox) Mp4BoxType

func (*ProtectionSystemSpecificHeaderBox) Mp4BoxUpdate

func (b *ProtectionSystemSpecificHeaderBox) Mp4BoxUpdate() uint32

func (*ProtectionSystemSpecificHeaderBox) Mp4BoxWrite

func (b *ProtectionSystemSpecificHeaderBox) Mp4BoxWrite(w io.Writer) (err error)

type SampleDescriptionBox

type SampleDescriptionBox struct {
	FullHeader
	Container
}

The sample description table gives detailed information about the coding type used, and any initialization information needed for that coding.

The information stored in the sample description box after the entry‐count is both track‐type specific as documented here, and can also have variants within a track type (e.g. different codings may use different specific information after some common fields, even within a video track).

Which type of sample entry form is used is determined by the media handler, using a suitable form, such as one defined in clause 12, or defined in a derived specification, or registration.

Multiple descriptions may be used within a track.

> Note Though the count is 32 bits, the number of items is usually much fewer, and is restricted by the fact that the reference index in the sample table is only 16 bits

If the ‘format’ field of a SampleEntry is unrecognized, neither the sample description itself, nor the associated media samples, shall be decoded.

> Note The definition of sample entries specifies boxes in a particular order, and this is usually also followed in derived specifications. For maximum compatibility, writers should construct files respecting the order both within specifications and as implied by the inheritance, whereas readers should be prepared to accept any box order.

All string fields shall be null‐terminated, even if unused. “Optional” means there is at least one null byte.

Entries that identify the format by MIME type, such as a TextSubtitleSampleEntry, TextMetaDataSampleEntry, or SimpleTextSampleEntry, all of which contain a MIME type, may be used to identify the format of streams for which a MIME type applies. A MIME type applies if the contents of the string in the optional configuration box (without its null termination), followed by the contents of a set of samples, starting with a sync sample and ending at the sample immediately preceding a sync sample, are concatenated in their entirety, and the result meets the decoding requirements for documents of that MIME type. Non‐sync samples should be used only if that format specifies the behaviour of ‘progressive decoding’, and then the sample times indicate when the results of such progressive decoding should be presented (according to the media type).

> Note The samples in a track that is all sync samples are therefore each a valid document for that MIME type.

In some classes derived from SampleEntry, namespace and schema_location are used both to identify the XML document content and to declare “brand” or profile compatibility. Multiple namespace identifiers indicate that the track conforms to the specification represented by each of the identifiers, some of which may identify supersets of the features present. A decoder should be able to decode all the namespaces in order to be able to decode and present correctly the media associated with this sample entry.

> Note Additionally, namespace identifiers may represent performance constraints, such as limits on document size, font size, drawing rate, etc., as well as syntax constraints such as features that are not permitted or ignored.

func (*SampleDescriptionBox) Mp4BoxRead

func (b *SampleDescriptionBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (SampleDescriptionBox) Mp4BoxType

func (b SampleDescriptionBox) Mp4BoxType() BoxType

func (*SampleDescriptionBox) Mp4BoxUpdate

func (b *SampleDescriptionBox) Mp4BoxUpdate() uint32

func (*SampleDescriptionBox) Mp4BoxWrite

func (b *SampleDescriptionBox) Mp4BoxWrite(w io.Writer) (err error)

type SampleEncryptionBox

type SampleEncryptionBox struct {
	FullHeader
	NullContainer

	// is the identifier of the encryption algorithm used to encrypt the track.
	AlgorithmID PiffAlgorithmID

	// is the size in bytes of the InitializationVector field
	IVSize PiffIVSize

	// is a key identifier that uniquely identifies the key needed to decrypt samples referred to by this sample encryption box.
	KID [16]uint8

	Samples []SampleEncryptionSampleEntry
}

The Sample Encryption box contains the sample specific encryption data. It is used when the sample data in the track or fragment is encrypted. The box MUST be present for Track Fragment Boxes or Sample Table Boxes that contain or refer to sample data for tracks containing encrypted data. It SHOULD be omitted for unencrypted content.

For an AlgorithmID of Not Encrypted, no initialization vectors are needed and this table SHOULD be omitted.

For an AlgorithmID of AES-CTR, if the IV_size field is 16 then the InitializationVector specifies the entire 128 bit IV value used as the counter value. If the InitializationVector field is 8, then its value is copied to bytes 0 to 7 of the 16 byte block passed to AES ECB and bytes 8 to 15 are set to zero. However the initial counter value is specified, bytes 8 to 15 are used as a simple block counter that is incremented for each block of the sample processed and is kept in network byte order.

Regardless of the length specified in the IV_size field, the initialization vectors for a given key MUST be unique for each sample in all Tracks. It is RECOMMENDED that the initial initialization vector be randomly generated and then incremented for each additional protected sample added. This provides entropy and ensures that the initialization vectors are unique.

For an AlgorithmID of AES-CBC, initialization vectors must by 16 bytes long and MUST be constructed such that the IV for the first sample in a fragment is randomly generated and subsequent samples within the same fragment use the last block of ciphertext from the previous sample as their IV. Note that the IV for each sample is still added to the SampleEncryptionBox (even though it can be retrieved from the previous sample) to facilitate random sample access.

The sub sample encryption entries SHALL NOT include an entry with a zero value in both the BytesOfClearData field and in the BytesOfEncryptedData field. Further, it is RECOMMENDED that the sub sample encryption entries be as compactly represented as possible. For example, instead two entries with {15 clear, 0 encrypted}, {17 clear, 500 encrypted} use one entry of {32 clear, 500 encrypted}.

See Section 6, Encryption of Track Level Data, for further details on how encryption is applied.

func (*SampleEncryptionBox) Mp4BoxRead

func (b *SampleEncryptionBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (SampleEncryptionBox) Mp4BoxType

func (b SampleEncryptionBox) Mp4BoxType() BoxType

func (*SampleEncryptionBox) Mp4BoxUpdate

func (b *SampleEncryptionBox) Mp4BoxUpdate() uint32

func (SampleEncryptionBox) Mp4BoxUserType

func (b SampleEncryptionBox) Mp4BoxUserType() UserType

func (*SampleEncryptionBox) Mp4BoxWrite

func (b *SampleEncryptionBox) Mp4BoxWrite(w io.Writer) (err error)

type SampleEncryptionSampleEntry

type SampleEncryptionSampleEntry struct {
	// specifies the initialization vector required for decryption of the
	// sample.
	InitializationVector []byte
	Subsamples           []SampleEncryptionSubsampleEntry
}

type SampleEncryptionSubsampleEntry

type SampleEncryptionSubsampleEntry struct {
	// specifies the number of bytes of clear data at the beginning of this sub
	// sample encryption entry. Note that this value may be zero if no clear
	// bytes exist for this entry.
	BytesOfClearData uint16

	// specifies the number of bytes of encrypted data following the clear data.
	// Note that this value may be zero if no encrypted bytes exist for this
	// entry.
	BytesOfProtectedData uint32
}

type SampleEntry

type SampleEntry struct {
	Header
	Container

	// is an integer that contains the index of the data reference to use to
	// retrieve data associated with samples that use this sample description.
	// Data references are stored in Data Reference Boxes. The index ranges from
	// 1 to the number of data references.
	DataReferenceIndex uint16
}

8.5.2 Sample Description Box

func (*SampleEntry) Mp4BoxRead

func (b *SampleEntry) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (*SampleEntry) Mp4BoxWrite

func (b *SampleEntry) Mp4BoxWrite(w io.Writer) (err error)

func (*SampleEntry) SampleEntrySize

func (b *SampleEntry) SampleEntrySize() (size uint32)

type SampleSizeBox

type SampleSizeBox struct {
	FullHeader
	NullContainer

	// is integer specifying the default sample size. If all the samples are the
	// same size, this field contains that size value. If this field is set to
	// 0, then the samples have different sizes, and those sizes are stored in
	// the sample size table. If this field is not 0, it specifies the constant
	// sample size, and no array follows.
	SampleSize uint32
	Entries    []SampleSizeEntry
}

This box contains the sample count and a table giving the size in bytes of each sample. This allows the media data itself to be unframed. The total number of samples in the media is always indicated in the sample count.

There are two variants of the sample size box. The first variant has a fixed size 32‐bit field for representing the sample sizes; it permits defining a constant size for all samples in a track. The second variant permits smaller size fields, to save space when the sizes are varying but small. One of these boxes must be present; the first version is preferred for maximum compatibility.

func (*SampleSizeBox) Mp4BoxRead

func (b *SampleSizeBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (SampleSizeBox) Mp4BoxType

func (b SampleSizeBox) Mp4BoxType() BoxType

func (*SampleSizeBox) Mp4BoxUpdate

func (b *SampleSizeBox) Mp4BoxUpdate() uint32

func (*SampleSizeBox) Mp4BoxWrite

func (b *SampleSizeBox) Mp4BoxWrite(w io.Writer) (err error)

type SampleSizeEntry

type SampleSizeEntry struct {
	// is an integer specifying the size of a sample, indexed by its number.
	EntrySize uint32

	// is an integer that gives the number of samples in each of these chunks
	SamplesPerChunk uint32

	// is an integer that gives the index of the sample entry that describes the
	// samples in this chunk. The index ranges from 1 to the number of sample
	// entries in the Sample Description Box
	SampleDescrptionIndex uint32
}

type SampleTableBox

type SampleTableBox struct {
	Header
	Container
}

The sample table contains all the time and data indexing of the media samples in a track. Using the tables here, it is possible to locate samples in time, determine their type (e.g. I‐frame or not), and determine their size, container, and offset into that container.

If the track that contains the Sample Table Box references no data, then the Sample Table Box does not need to contain any sub‐boxes (this is not a very useful media track).

If the track that the Sample Table Box is contained in does reference data, then the following sub‐boxes are required: Sample Description, Sample Size, Sample To Chunk, and Chunk Offset. Further, the Sample Description Box shall contain at least one entry. A Sample Description Box is required because it contains the data reference index field which indicates which Data Reference Box to use to retrieve the media samples. Without the Sample Description, it is not possible to determine where the media samples are stored. The Sync Sample Box is optional. If the Sync Sample Box is not present, all samples are sync samples.

A.7 provides a narrative description of random access using the structures defined in the Sample Table Box.

func (*SampleTableBox) Mp4BoxRead

func (b *SampleTableBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (SampleTableBox) Mp4BoxType

func (b SampleTableBox) Mp4BoxType() BoxType

func (*SampleTableBox) Mp4BoxUpdate

func (b *SampleTableBox) Mp4BoxUpdate() uint32

func (*SampleTableBox) Mp4BoxWrite

func (b *SampleTableBox) Mp4BoxWrite(w io.Writer) (err error)

type SampleToChunkBox

type SampleToChunkBox struct {
	FullHeader
	NullContainer
	Entries []SampleToChunkEntry
}

Samples within the media data are grouped into chunks. Chunks can be of different sizes, and the samples within a chunk can have different sizes. This table can be used to find the chunk that contains a sample, its position, and the associated sample description.

The table is compactly coded. Each entry gives the index of the first chunk of a run of chunks with the same characteristics. By subtracting one entry here from the previous one, you can compute how many chunks are in this run. You can convert this to a sample count by multiplying by the appropriate samples‐per‐chunk.

func (*SampleToChunkBox) Mp4BoxRead

func (b *SampleToChunkBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (SampleToChunkBox) Mp4BoxType

func (b SampleToChunkBox) Mp4BoxType() BoxType

func (*SampleToChunkBox) Mp4BoxUpdate

func (b *SampleToChunkBox) Mp4BoxUpdate() uint32

func (*SampleToChunkBox) Mp4BoxWrite

func (b *SampleToChunkBox) Mp4BoxWrite(w io.Writer) (err error)

type SampleToChunkEntry

type SampleToChunkEntry struct {
	// is an integer that gives the index of the first chunk in this run of
	// chunks that share the same samples‐per‐chunk and
	// sample‐description‐index; the index of the first chunk in a track has the
	// value 1 (the first_chunk field in the first record of this box has the
	// value 1, identifying that the first sample maps to the first chunk).
	FirstChunk uint32

	// is an integer that gives the number of samples in each of these chunks
	SamplesPerChunk uint32

	// is an integer that gives the index of the sample entry that describes the
	// samples in this chunk. The index ranges from 1 to the number of sample
	// entries in the Sample Description Box
	SampleDescrptionIndex uint32
}

type SchemeInformationBox

type SchemeInformationBox struct {
	Header
	Container
}

The Scheme Information Box is a container Box that is only interpreted by the scheme being used. Any information the encryption or restriction system needs is stored here. The content of this box is a series of boxes whose type and format are defined by the scheme declared in the Scheme Type Box.

func (*SchemeInformationBox) Mp4BoxRead

func (b *SchemeInformationBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (SchemeInformationBox) Mp4BoxType

func (b SchemeInformationBox) Mp4BoxType() BoxType

func (*SchemeInformationBox) Mp4BoxUpdate

func (b *SchemeInformationBox) Mp4BoxUpdate() uint32

func (*SchemeInformationBox) Mp4BoxWrite

func (b *SchemeInformationBox) Mp4BoxWrite(w io.Writer) (err error)

type SchemeTypeBox

type SchemeTypeBox struct {
	FullHeader
	NullContainer

	// is the code defining the protection or restriction scheme.
	SchemeType FourCC

	// is the version of the scheme (used to create the content)
	SchemeVersion uint32

	// allows for the option of directing the user to a web‐page if they do not
	// have the scheme installed on their system. It is an absolute URI formed
	// as a null‐terminated string in UTF‐8 characters.
	SchemeURI NullTerminatedString
}

The Scheme Type Box (‘schm’) identifies the protection or restriction scheme.

func (*SchemeTypeBox) Mp4BoxRead

func (b *SchemeTypeBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (SchemeTypeBox) Mp4BoxType

func (b SchemeTypeBox) Mp4BoxType() BoxType

func (*SchemeTypeBox) Mp4BoxUpdate

func (b *SchemeTypeBox) Mp4BoxUpdate() uint32

func (*SchemeTypeBox) Mp4BoxWrite

func (b *SchemeTypeBox) Mp4BoxWrite(w io.Writer) (err error)

type SoundMediaHeaderBox

type SoundMediaHeaderBox struct {
	FullHeader
	NullContainer

	// is a fixed‐point 8.8 number that places mono audio tracks in a stereo
	// space; 0 is centre (the normal value); full left is ‐1.0 and full right
	// is 1.0.
	Balance int16
}

Audio tracks use the SoundMediaHeaderbox in the media information box as defined in 8.4.5. The sound media header contains general presentation information, independent of the coding, for audio media. This header is used for all tracks containing audio.

func (*SoundMediaHeaderBox) Mp4BoxRead

func (b *SoundMediaHeaderBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (SoundMediaHeaderBox) Mp4BoxType

func (b SoundMediaHeaderBox) Mp4BoxType() BoxType

func (*SoundMediaHeaderBox) Mp4BoxUpdate

func (b *SoundMediaHeaderBox) Mp4BoxUpdate() uint32

func (*SoundMediaHeaderBox) Mp4BoxWrite

func (b *SoundMediaHeaderBox) Mp4BoxWrite(w io.Writer) (err error)

type SyncSampleBox

type SyncSampleBox struct {
	FullHeader
	NullContainer
	SampleNumbers []uint32 // gives the numbers of the samples that are sync samples in the stream.
}

This box provides a compact marking of the sync samples within the stream. The table is arranged in strictly increasing order of sample number.

If the sync sample box is not present, every sample is a sync sample.

func (*SyncSampleBox) Mp4BoxRead

func (b *SyncSampleBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (SyncSampleBox) Mp4BoxType

func (b SyncSampleBox) Mp4BoxType() BoxType

func (*SyncSampleBox) Mp4BoxUpdate

func (b *SyncSampleBox) Mp4BoxUpdate() uint32

func (*SyncSampleBox) Mp4BoxWrite

func (b *SyncSampleBox) Mp4BoxWrite(w io.Writer) (err error)

type TimeToSampleBox

type TimeToSampleBox struct {
	FullHeader
	NullContainer
	Entries []TimeToSampleEntry
}

This box contains a compact version of a table that allows indexing from decoding time to sample number. Other tables give sample sizes and pointers, from the sample number. Each entry in the table gives the number of consecutive samples with the same time delta, and the delta of those samples. By adding the deltas a complete time‐to‐sample map may be built.

The Decoding Time to Sample Box contains decode time delta's: DT(n+1) = DT(n) + STTS(n) where STTS(n) is the (uncompressed) table entry for sample n.

The sample entries are ordered by decoding time stamps; therefore the deltas are all non‐negative.

The DT axis has a zero origin; DT(i) = SUM(for j=0 to i‐1 of delta(j)), and the sum of all deltas gives the length of the media in the track (not mapped to the overall timescale, and not considering any edit list).

The Edit List Box provides the initial CT value if it is non‐empty (non‐zero).

func (*TimeToSampleBox) Mp4BoxRead

func (b *TimeToSampleBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (TimeToSampleBox) Mp4BoxType

func (b TimeToSampleBox) Mp4BoxType() BoxType

func (*TimeToSampleBox) Mp4BoxUpdate

func (b *TimeToSampleBox) Mp4BoxUpdate() uint32

func (*TimeToSampleBox) Mp4BoxWrite

func (b *TimeToSampleBox) Mp4BoxWrite(w io.Writer) (err error)

type TimeToSampleEntry

type TimeToSampleEntry struct {
	// is an integer that counts the number of consecutive samples that have the
	// given duration.
	SampleCount uint32

	// is an integer that gives the delta of these samples in the time‐scale of
	// the media.
	SampleDelta uint32
}

type TrackBox

type TrackBox struct {
	Header
	Container
}

This is a container box for a single track of a presentation. A presentation consists of one or more tracks. Each track is independent of the other tracks in the presentation and carries its own temporal and spatial information. Each track will contain its associated Media Box.

Tracks are used for two purposes: (a) to contain media data (media tracks) and (b) to contain packetization information for streaming protocols (hint tracks).

There shall be at least one media track within an ISO file, and all the media tracks that contributed to the hint tracks shall remain in the file, even if the media data within them is not referenced by the hint tracks; after deleting all hint tracks, the entire un‐hinted presentation shall remain.

func (*TrackBox) Mp4BoxRead

func (b *TrackBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (TrackBox) Mp4BoxType

func (b TrackBox) Mp4BoxType() BoxType

func (*TrackBox) Mp4BoxUpdate

func (b *TrackBox) Mp4BoxUpdate() uint32

func (*TrackBox) Mp4BoxWrite

func (b *TrackBox) Mp4BoxWrite(w io.Writer) (err error)

type TrackEncryptionBox

type TrackEncryptionBox struct {
	FullHeader
	NullContainer

	// specifies the count of the encrypted Blocks in the protection pattern,
	// where each Block is of size 16-bytes. See 9.1 for further details.
	DefaultCryptByteBlock uint8

	// specifies the count of the unencrypted Blocks in the protection pattern.
	// See the skip_byte_block field in 9.1 for further details.
	DefaultSkipByteBlock uint8

	// is the protection flag which indicates the default protection state of
	// the samples in the track. See the isProtected field in 9.1 for further
	// details.
	DefaultIsProtected uint8

	// is the default Initialization Vector size in bytes. See the
	// Per_Sample_IV_Size field in 9.1 for further details.
	DefaultPerSampleIVSize uint8

	// is the default key identifier used for samples in this track. See the KID
	// field in 9.1 for further details.
	DefaultKID [16]byte

	// is the size of a possible default Initialization Vector for all samples.
	DefaultConstantIVSize uint8

	// if present, is the default Initialization Vector for all samples. See the
	// constant_IV field in 9.1 for further details.
	DefaultConstantIV []byte
}

The Track Encryption Box contains default values for the isProtected flag, Per_Sample_IV_Size, and KID for the entire track. In the case where pattern-based encryption is in effect, it supplies the pattern and when Constant IVs are in use, it supplies the Constant IV. These values are used as the encryption parameters for the samples in this track unless over-ridden by the sample group description associated with a group of samples. For files with only one key per track, this box allows the basic encryption parameters to be specified once per track instead of being repeated per sample.

If both the value of default_isProtected is 1 and default_Per_Sample_IV_Size is 0, then the default_constant_IV_size for all samples that use these settings SHALL be present. A Constant IV SHALL NOT be used with counter-mode encryption. A sample group description may supply keys or keys and Constant IVs for sample groups that override these default values for those samples mapped to the group.

> NOTE The version field of the Track Encryption Box is set to a value greater than zero when the pattern encryption defined in 9.6 is used and to zero otherwise.

func (*TrackEncryptionBox) Mp4BoxRead

func (b *TrackEncryptionBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (TrackEncryptionBox) Mp4BoxType

func (b TrackEncryptionBox) Mp4BoxType() BoxType

func (*TrackEncryptionBox) Mp4BoxUpdate

func (b *TrackEncryptionBox) Mp4BoxUpdate() uint32

func (*TrackEncryptionBox) Mp4BoxWrite

func (b *TrackEncryptionBox) Mp4BoxWrite(w io.Writer) (err error)

type TrackExtendsBox

type TrackExtendsBox struct {
	FullHeader
	NullContainer

	// identifies the track; this shall be the track ID of a track in the Movie
	// Box
	TrackID uint32

	// these fields set up defaults used in the track fragments.
	DefaultSampleDescrptionIndex uint32
	DefaultSampleDuration        uint32
	DefaultSampleSize            uint32
	DefaultSampleFlags           uint32
}

This sets up default values used by the movie fragments. By setting defaults in this way, space and complexity can be saved in each Track Fragment Box.

The sample flags field in sample fragments (default_sample_flags here and in a Track Fragment Header Box, and sample_flags and first_sample_flags in a Track Fragment Run Box) is coded as a 32‐bit value. It has the following structure:

bit(4) reserved=0;
unsigned int(2) is_leading;
unsigned int(2) sample_depends_on;
unsigned int(2) sample_is_depended_on;
unsigned int(2) sample_has_redundancy;
bit(3) sample_padding_value;
bit(1) sample_is_non_sync_sample;
unsigned int(16) sample_degradation_priority;

The is_leading, sample_depends_on, sample_is_depended_on and sample_has_redundancy values are defined as documented in the Independent and Disposable Samples Box.

The flag sample_is_non_sync_sample provides the same information as the sync sample table [8.6.2]. When this value is set 0 for a sample, it is the same as if the sample were not in a movie fragment and marked with an entry in the sync sample table (or, if all samples are sync samples, the sync sample table were absent).

The sample_padding_value is defined as for the padding bits table. The sample_degradation_priority is defined as for the degradation priority table.

func (*TrackExtendsBox) Mp4BoxRead

func (b *TrackExtendsBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (TrackExtendsBox) Mp4BoxType

func (b TrackExtendsBox) Mp4BoxType() BoxType

func (*TrackExtendsBox) Mp4BoxUpdate

func (b *TrackExtendsBox) Mp4BoxUpdate() uint32

func (*TrackExtendsBox) Mp4BoxWrite

func (b *TrackExtendsBox) Mp4BoxWrite(w io.Writer) (err error)

type TrackFragmentBox

type TrackFragmentBox struct {
	Header
	Container
}

Within the movie fragment there is a set of track fragments, zero or more per track. The track fragments in turn contain zero or more track runs, each of which document a contiguous run of samples for that track. Within these structures, many fields are optional and can be defaulted.

It is possible to add 'empty time' to a track using these structures, as well as adding samples. Empty inserts can be used in audio tracks doing silence suppression, for example.

func (*TrackFragmentBox) Mp4BoxRead

func (b *TrackFragmentBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (TrackFragmentBox) Mp4BoxType

func (b TrackFragmentBox) Mp4BoxType() BoxType

func (*TrackFragmentBox) Mp4BoxUpdate

func (b *TrackFragmentBox) Mp4BoxUpdate() uint32

func (*TrackFragmentBox) Mp4BoxWrite

func (b *TrackFragmentBox) Mp4BoxWrite(w io.Writer) (err error)

type TrackFragmentHeaderBox

type TrackFragmentHeaderBox struct {
	FullHeader
	NullContainer

	TrackID uint32

	// the base offset to use when calculating data offsets
	BaseDataOffset uint64

	SampleDescrptionIndex uint32
	DefaultSampleDuration uint32
	DefaultSampleSize     uint32
	DefaultSampleFlags    uint32
}

Each movie fragment can add zero or more fragments to each track; and a track fragment can add zero or more contiguous runs of samples. The track fragment header sets up information and defaults used for those runs of samples.

The base‐data‐offset, if explicitly provided, is a data offset that is identical to a chunk offset in the Chunk Offset Box, i.e. applying to the complete file (e.g. starting with a file‐type box and movie box). In circumstances when the complete file does not exist or its size is unknown, it may be impossible to use an explicit base‐data‐offset; then, offsets need to be established relative to the movie fragment.

func (*TrackFragmentHeaderBox) Mp4BoxRead

func (b *TrackFragmentHeaderBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (TrackFragmentHeaderBox) Mp4BoxType

func (b TrackFragmentHeaderBox) Mp4BoxType() BoxType

func (*TrackFragmentHeaderBox) Mp4BoxUpdate

func (b *TrackFragmentHeaderBox) Mp4BoxUpdate() uint32

func (*TrackFragmentHeaderBox) Mp4BoxWrite

func (b *TrackFragmentHeaderBox) Mp4BoxWrite(w io.Writer) (err error)

type TrackHeaderBox

type TrackHeaderBox struct {
	FullHeader
	NullContainer

	// is an integer that declares the creation time of this track (in seconds
	// since midnight, Jan. 1, 1904, in UTC time).
	CreationTime uint64

	// is an integer that declares the most recent time the track was modified
	// (in seconds since midnight, Jan. 1, 1904, in UTC time).
	ModificationTime uint64

	// is an integer that uniquely identifies this track over the entire
	// life‐time of this presentation. Track IDs are never re‐used and cannot be
	// zero.
	TrackID uint32

	// is an integer that indicates the duration of this track (in the timescale
	// indicated in the Movie Header Box). The value of this field is equal to
	// the sum of the durations of all of the track’s edits. If there is no edit
	// list, then the duration is the sum of the sample durations, converted
	// into the timescale in the Movie Header Box. If the duration of this track
	// cannot be determined then duration is set to all 1s.
	Duration uint64

	// specifies the front‐to‐back ordering of video tracks; tracks with lower
	// numbers are closer to the viewer. 0 is the normal value, and ‐1 would be
	// in front of track 0, and so on.
	Layer int16

	// is an integer that specifies a group or collection of tracks. If this
	// field is 0 there is no information on possible relations to other tracks.
	// If this field is not 0, it should be the same for tracks that contain
	// alternate data for one another and different for tracks belonging to
	// different such groups. Only one track within an alternate group should be
	// played or streamed at any one time, and must be distinguishable from
	// other tracks in the group via attributes such as bitrate, codec,
	// language, packet size etc. A group may have only one member.
	AlternateGroup int16

	// is a fixed 8.8 value specifying the track's relative audio volume. Full
	// volume is 1.0 (0x0100) and is the normal value. Its value is irrelevant
	// for a purely visual track. Tracks may be composed by combining them
	// according to their volume, and then using the overall Movie Header Box
	// volume setting; or more complex audio composition (e.g. MPEG‐4 BIFS) may
	// be used.
	Volume int16

	// provides a transformation matrix for the video; (u,v,w) are restricted
	// here to (0,0,1), hex (0,0,0x40000000).
	Matrix [9]int32

	// width and height fixed‐point 16.16 values are track‐dependent as follows:
	//
	// For text and subtitle tracks, they may, depending on the coding format,
	// describe the suggested size of the rendering area. For such tracks, the
	// value 0x0 may also be used to indicate that the data may be rendered at
	// any size, that no preferred size has been indicated and that the actual
	// size may be determined by the external context or by reusing the width
	// and height of another track. For those tracks, the flag
	// track_size_is_aspect_ratio may also be used.
	//
	// For non‐visual tracks (e.g. audio), they should be set to zero.
	//
	// For all other tracks, they specify the track's visual presentation size.
	// These need not be the same as the pixel dimensions of the images, which
	// is documented in the sample description(s); all images in the sequence
	// are scaled to this size, before any overall transformation of the track
	// represented by the matrix. The pixel dimensions of the images are the
	// default values.
	Width  uint32
	Height uint32
}

This box specifies the characteristics of a single track. Exactly one Track Header Box is contained in a track.

In the absence of an edit list, the presentation of a track starts at the beginning of the overall presentation. An empty edit is used to offset the start time of a track.

The default value of the track header flags for media tracks is 7 (track_enabled, track_in_movie, track_in_preview). If in a presentation all tracks have neither track_in_movie nor track_in_preview set, then all tracks shall be treated as if both flags were set on all tracks. Server hint tracks should have the track_in_movie and track_in_preview set to 0, so that they are ignored for local playback and preview.

Under the ‘iso3’ brand or brands that share its requirements, the width and height in the track header are measured on a notional 'square' (uniform) grid. Track video data is normalized to these dimensions (logically) before any transformation or placement caused by a layup or composition system. Track (and movie) matrices, if used, also operate in this uniformly‐scaled space.

The duration field here does not include the duration of following movie fragments, if any, but only of the media in the enclosing Movie Box. The Movie Extends Header box may be used to document the duration including movie fragments, when desired and possible.

func (*TrackHeaderBox) Mp4BoxRead

func (b *TrackHeaderBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (TrackHeaderBox) Mp4BoxType

func (b TrackHeaderBox) Mp4BoxType() BoxType

func (*TrackHeaderBox) Mp4BoxUpdate

func (b *TrackHeaderBox) Mp4BoxUpdate() uint32

func (*TrackHeaderBox) Mp4BoxWrite

func (b *TrackHeaderBox) Mp4BoxWrite(w io.Writer) (err error)

type TrackRunBox

type TrackRunBox struct {
	FullHeader
	NullContainer

	// the number of samples being added in this run; also the number of rows in
	// the following table (the rows can be empty)
	SampleCount uint32

	// is added to the implicit or explicit data_offset established in the track
	// fragment header.
	DataOffset int32

	// provides a set of flags for the first sample only of this run.
	FirstSampleFlags uint32

	Samples []TrackRunSampleEntry
}

Within the Track Fragment Box, there are zero or more Track Run Boxes. If the duration‐is‐empty flag is set in the tf_flags, there are no track runs. A track run documents a contiguous set of samples for a track.

The number of optional fields is determined from the number of bits set in the lower byte of the flags, and the size of a record from the bits set in the second byte of the flags. This procedure shall be followed, to allow for new fields to be defined.

If the data‐offset is not present, then the data for this run starts immediately after the data of the previous run, or at the base‐data‐offset defined by the track fragment header if this is the first run in a track fragment, If the data‐offset is present, it is relative to the base‐data‐offset established in the track fragment header.

func (*TrackRunBox) Mp4BoxRead

func (b *TrackRunBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (TrackRunBox) Mp4BoxType

func (b TrackRunBox) Mp4BoxType() BoxType

func (*TrackRunBox) Mp4BoxUpdate

func (b *TrackRunBox) Mp4BoxUpdate() uint32

func (*TrackRunBox) Mp4BoxWrite

func (b *TrackRunBox) Mp4BoxWrite(w io.Writer) (err error)

type TrackRunSampleEntry

type TrackRunSampleEntry struct {
	SampleDuration              uint32
	SampleSize                  uint32
	SampleFlags                 uint32
	SampleCompositionTimeOffset int64
}

type UnknownBox

type UnknownBox struct {
	Header
	NullContainer
	Data []byte
}

func (*UnknownBox) Mp4BoxRead

func (b *UnknownBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (UnknownBox) Mp4BoxType

func (b UnknownBox) Mp4BoxType() BoxType

func (*UnknownBox) Mp4BoxUpdate

func (b *UnknownBox) Mp4BoxUpdate() uint32

func (*UnknownBox) Mp4BoxWrite

func (b *UnknownBox) Mp4BoxWrite(w io.Writer) (err error)

type UserType

type UserType uuid.UUID

func BoxTypeToUserType

func BoxTypeToUserType(boxType BoxType) UserType

type VideoMediaHeaderBox

type VideoMediaHeaderBox struct {
	FullHeader
	NullContainer

	// specifies a composition mode for this video track, from the following
	// enumerated set, which may be extended by derived specifications:
	//
	// * copy = 0 copy over the existing image
	GraphicsMode uint16

	// is a set of 3 colour values (red, green, blue) available for use by
	// graphics modes
	OpColor [3]uint16
}

Video tracks use the VideoMediaHeaderbox in the media information box as defined in 8.4.5. The video media header contains general presentation information, independent of the coding, for video media. Note that the flags field has the value 1.

func (*VideoMediaHeaderBox) Mp4BoxRead

func (b *VideoMediaHeaderBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (VideoMediaHeaderBox) Mp4BoxType

func (b VideoMediaHeaderBox) Mp4BoxType() BoxType

func (*VideoMediaHeaderBox) Mp4BoxUpdate

func (b *VideoMediaHeaderBox) Mp4BoxUpdate() uint32

func (*VideoMediaHeaderBox) Mp4BoxWrite

func (b *VideoMediaHeaderBox) Mp4BoxWrite(w io.Writer) (err error)

type VisualSampleEntryBox

type VisualSampleEntryBox struct {
	SampleEntry

	Width           uint16
	Height          uint16
	HorizResolution uint32
	VertResolution  uint32
	FrameCount      uint16
	CompressorName  string
	Depth           uint16

	Clap *CleanApertureBox
	Pasp *PixelAspectRatioBox
}

Video tracks use VisualSampleEntryBox.

In video tracks, the frame_count field must be 1 unless the specification for the media format explicitly documents this template field and permits larger values. That specification must document both how the individual frames of video are found (their size information) and their timing established. That timing might be as simple as dividing the sample duration by the frame count to establish the frame duration.

The width and height in the video sample entry document the pixel counts that the codec will deliver; this enables the allocation of buffers. Since these are counts they do not take into account pixel aspect ratio.

func (*VisualSampleEntryBox) Mp4BoxRead

func (b *VisualSampleEntryBox) Mp4BoxRead(r io.Reader, header *Header) (err error)

func (*VisualSampleEntryBox) Mp4BoxUpdate

func (b *VisualSampleEntryBox) Mp4BoxUpdate() uint32

func (*VisualSampleEntryBox) Mp4BoxWrite

func (b *VisualSampleEntryBox) Mp4BoxWrite(w io.Writer) (err error)

func (*VisualSampleEntryBox) VisualSampleEntrySize

func (b *VisualSampleEntryBox) VisualSampleEntrySize() (size uint32)

Jump to

Keyboard shortcuts

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