Documentation
¶
Overview ¶
Package mp4 writes ISO base media files (MP4, QuickTime): a video track of HEVC or MV-HEVC with Apple's stereo signalling, and audio tracks of AC-3 or E-AC-3, from the same sources the Matroska muxer takes.
Index ¶
- Constants
- func AVCC(sps, pps []byte) []byte
- func AVCCodec(sps []byte) string
- func AVCSample(au []byte) []byte
- func MovieAt(r io.ReaderAt, size int64) ([]byte, error)
- func Mux(f io.WriteSeeker, sources []mkv.Source, o Options) error
- func SplitAnnexB(au []byte) [][]byte
- type Live
- type Options
- type Reader
- type Spatial
Constants ¶
const LiveTimescale = 90000
LiveTimescale is the stream's timescale: the 90 kHz of its timestamps.
Variables ¶
This section is empty.
Functions ¶
func AVCC ¶ added in v0.21.0
AVCC is an avcC box's body for an SPS and a PPS (NAL units without start codes): a decoder's configuration.
func AVCCodec ¶ added in v0.20.0
AVCCodec is the codec string a browser wants for an H.264 stream (avc1.PPCCLL: the SPS's profile, constraints and level).
func AVCSample ¶ added in v0.21.0
AVCSample is an H.264 access unit (Annex B) as an MP4 sample: its NAL units each after its length (4 bytes), the parameter sets left out (an avcC carries them).
func MovieAt ¶ added in v0.13.0
MovieAt finds and reads the movie box of a file of size bytes through r, reading only box headers on the way: with the movie box at the end (after the media data), the file's first and last pieces are enough.
func Mux ¶
Mux writes the sources (the video first, then audio tracks) to f, in decode order interleaved by time; the movie header goes last, so f is written once through, then its media data box is sized.
func SplitAnnexB ¶ added in v0.20.0
SplitAnnexB is the NAL units of an Annex B access unit, without their start codes.
Types ¶
type Live ¶ added in v0.20.0
Live writes one H.264 video stream as a fragmented MP4 as its frames are made, for a browser's media source (MSE) reading it live: the movie header once (Init), then a fragment a frame (moof and mdat), each decoded as it arrives (no B-frames). The frames are Annex B access units; their parameter sets go into the avcC, not the samples.
type Options ¶
type Options struct {
// FPSNum and FPSDen are the video's frame rate, which sets its
// timescale (24000/1001 for film).
FPSNum, FPSDen int
// Spatial, when set, marks the video track as a stereo pair.
Spatial *Spatial
// QuickTime writes a QuickTime (.mov) brand instead of MP4's.
QuickTime bool
}
Options for Mux.
type Reader ¶ added in v0.13.0
type Reader struct {
Tracks []mkv.ReadTrack
Duration time.Duration
// LayerParams is, for an MV-HEVC track, its second layer's parameter
// sets (lhvC) as Annex B NAL units.
LayerParams map[uint64][]byte
// Stereo is, for a video track Apple's stereo boxes describe, what
// they say: "both" when vexu's eyes box names both eyes, "one" when it
// names one.
Stereo map[uint64]string
// contains filtered or unexported fields
}
Reader reads an MP4 or QuickTime file's samples in file order, each as a Matroska-style packet, its tracks described as a Matroska reader describes them (codec ids, avcC or hvcC as the codec private data), so the conversion takes either alike.
Video: H.264 (avc1, avc3), HEVC (hvc1, hev1; MV-HEVC's second layer with it, lhvC), Dolby Vision's configuration. Audio: AC-3, E-AC-3, AAC (described, for the caller to leave or code), and PCM (sowt, twos, in24, in32, lpcm), given little-endian, a chunk a packet. The edit list's start is kept: a track that starts late does.
func NewReader ¶ added in v0.13.0
func NewReader(f io.ReadSeeker) (*Reader, error)
NewReader reads the file's movie box.
func ParseMovie ¶ added in v0.13.0
ParseMovie describes a file from its movie box alone: its tracks, with no samples to read (Next fails).
func (*Reader) Next ¶ added in v0.13.0
Next returns the next sample in file order, its time the presentation time (the edit list applied).
type Spatial ¶
type Spatial struct {
// FOV is the horizontal field of view of each eye's picture, in
// degrees (an iPhone's spatial video says 63.4, Vision Pro's 71.6).
FOV float64
// Baseline is the distance between the two cameras, in millimetres
// (an iPhone's 19.24, Vision Pro's 63.76).
Baseline float64
// Disparity is a shift of the two views, -1 to 1 of the picture's
// width, 0 for none.
Disparity float64
// HeroRight makes the right eye the hero (the one shown in 2D); the
// left is the base layer and the hero otherwise.
HeroRight bool
}
Spatial is what a stereo (MV-HEVC) video track says of itself to a player: Apple's video extended usage, which visionOS and the Quest read to show the two views to the two eyes. Photos marks a file "spatial" only with a field of view and a baseline or disparity adjustment.