Documentation ¶
Overview ¶
Module mp4ff implements MP4 media file parsing and writing for AVC and HEVC video, AAC and AC-3 audio, stpp and wvtt subtitles, and timed metadata tracks. It is focused on fragmented files as used for streaming in MPEG-DASH, MSS and HLS fMP4, but can also decode and encode all boxes needed for progressive MP4 files.
Command Line Tools ¶
Some useful command line tools are available in [cmd](cmd) directory.
- mp4ff-info prints a tree of the box hierarchy of a mp4 file with information about the boxes.
- mp4ff-pslister extracts and displays SPS and PPS for AVC or HEVC in a mp4 or a bytestream (Annex B) file. Partial information is printed for HEVC.
- mp4ff-nallister lists NALUs and picture types for video in progressive or fragmented file
- mp4ff-subslister lists details of wvtt or stpp (WebVTT or TTML in ISOBMFF) subtitle samples
- mp4ff-crop crops a **progressive** mp4 file to a specified duration
- mp4ff-encrypt encrypts a fragmented file using cenc or cbcs Common Encryption scheme
- mp4ff-decrypt decrypts a fragmented file encrypted using cenc or cbcs Common Encryption scheme
You can install these tools by going to their respective directory and run `go install .` or directly from the repo with
go install github.com/Eyevinn/mp4ff/cmd/mp4ff-info@latest go install github.com/Eyevinn/mp4ff/cmd/mp4ff-encrypt@latests
for each individual tool.
Example code ¶
Example code for some common use cases is available in the [examples](examples) directory. The examples and their functions are:
- initcreator creates typical init segments (ftyp + moov) for different video and audio codecs
- resegmenter reads a segmented file (CMAF track) and resegments it with other segment durations using `FullSample`
- segmenter takes a progressive mp4 file and creates init and media segments from it. This tool has been extended to support generation of segments with multiple tracks as well as reading and writing `mdat` in lazy mode
- multitrack parses a fragmented file with multiple tracks
- combine-segs combines single-track init and media segments into multi-track segments
- add-sidx adds a top-level sidx box describing the segments of a fragmented files.
Packages ¶
The top-level packages in the mp4ff module are
- mp4 provides support for for parsing (called Decode) and writing (Encode) a plethor of mp4 boxes. It also contains helper functions for extracting, encrypting, dectrypting samples and a lot more.
- avc deals with AVC (aka H.264) video in the `mp4ff/avc` package including parsing of SPS and PPS, and finding start-codes in Annex B byte streams.
- hevc provides structures and functions for dealing with HEVC video and its packaging
- sei provides support for handling Supplementary Enhancement Information (SEI) such as timestamps for AVC and HEVC video.
- av1 provides basic support for AV1 video packaging
- aac provides support for AAC audio. This includes handling ADTS headers which is common for AAC inside MPEG-2 TS streams.
- bits provides bit-wise and byte-wise readers and writers used by the other packages.
Specifications ¶
The main specification for the MP4 file format is the ISO Base Media File Format (ISOBMFF) standard ISO/IEC 14496-12 7th edition 2021. Some boxes are specified in other standards, as should be commented in the code.
Directories ¶
Path | Synopsis |
---|---|
Package aac parses and generates AAC meta data including ADTS headers.
|
Package aac parses and generates AAC meta data including ADTS headers. |
Package av1 decodes (parses) and encodes (writes) AV1 CodecConfigurationRecord.
|
Package av1 decodes (parses) and encodes (writes) AV1 CodecConfigurationRecord. |
Package avc parses AVC (H.264) NAL unit headers, slice headers and complete SPS and PPS.
|
Package avc parses AVC (H.264) NAL unit headers, slice headers and complete SPS and PPS. |
Package bits provides bit and bytes reading and writing including Golomb codes and EBSP as used by MPEG video standards.
|
Package bits provides bit and bytes reading and writing including Golomb codes and EBSP as used by MPEG video standards. |
Package cmd provides command line tools built using mp4ff.
|
Package cmd provides command line tools built using mp4ff. |
mp4ff-crop
mp4ff-crop crops a (progressive) mp4 file to just before a sync frame after specified number of milliseconds.
|
mp4ff-crop crops a (progressive) mp4 file to just before a sync frame after specified number of milliseconds. |
mp4ff-decrypt
mp4ff-decrypt decrypts a fragmented mp4 file encrypted with Common Encryption scheme cenc or cbcs.
|
mp4ff-decrypt decrypts a fragmented mp4 file encrypted with Common Encryption scheme cenc or cbcs. |
mp4ff-encrypt
mp4ff-encrypt encrypts a fragmented mp4 file using Common Encryption with cenc or cbcs scheme.
|
mp4ff-encrypt encrypts a fragmented mp4 file using Common Encryption with cenc or cbcs scheme. |
mp4ff-info
mp4ff-info prints the box tree of input mp4 (ISOBMFF) file.
|
mp4ff-info prints the box tree of input mp4 (ISOBMFF) file. |
mp4ff-nallister
mp4ff-nallister lists NAL units and slice types of AVC or HEVC tracks of an mp4 (ISOBMFF) file or a file containing a byte stream in Annex B format.
|
mp4ff-nallister lists NAL units and slice types of AVC or HEVC tracks of an mp4 (ISOBMFF) file or a file containing a byte stream in Annex B format. |
mp4ff-pslister
mp4ff-pslister lists parameter sets for AVC/H.264 or HEVC/H.265 from mp4 sample description, bytestream, or hex input.
|
mp4ff-pslister lists parameter sets for AVC/H.264 or HEVC/H.265 from mp4 sample description, bytestream, or hex input. |
mp4ff-subslister
mp4ff-subslister lists and displays content of wvtt or stpp samples.
|
mp4ff-subslister lists and displays content of wvtt or stpp samples. |
Package examples provides example programs built using mp4ff.
|
Package examples provides example programs built using mp4ff. |
add-sidx
add-sidx shows how to add a top-level sidx box to a fragmented file provided it does not exist.
|
add-sidx shows how to add a top-level sidx box to a fragmented file provided it does not exist. |
combine-segs
combine-segs provides an example of multiplexing tracks from fragmented MP4 files.
|
combine-segs provides an example of multiplexing tracks from fragmented MP4 files. |
initcreator
initcreator shows how one can create init segments for video, audio, and subtitles.
|
initcreator shows how one can create init segments for video, audio, and subtitles. |
multitrack
multitrack is an example showing how to decode a multitrack fragmented file with video and closed caption (CEA-608) tracks.
|
multitrack is an example showing how to decode a multitrack fragmented file with video and closed caption (CEA-608) tracks. |
resegmenter
resegmenter is an example on how to resegment a fragmented file to a new target segment duration.
|
resegmenter is an example on how to resegment a fragmented file to a new target segment duration. |
segmenter
segmenter segments a progressive mp4 file into init and media segments.
|
segmenter segments a progressive mp4 file into init and media segments. |
Package hevc - parsing of HEVC(H.265) NAL unit headers, slice headers, VPS, SPS, and PPS.
|
Package hevc - parsing of HEVC(H.265) NAL unit headers, slice headers, VPS, SPS, and PPS. |
Package mp4 is a library for parsing and writing MP4/ISOBMFF files with a focus on fragmented files.
|
Package mp4 is a library for parsing and writing MP4/ISOBMFF files with a focus on fragmented files. |
Package sei provides SEI (Supplementary Enhancement Information) parsing and encoding for both AVC and HEVC video standards.
|
Package sei provides SEI (Supplementary Enhancement Information) parsing and encoding for both AVC and HEVC video standards. |