mp4-atom
This library provides encoding for the ISO Base Media File Format (ISO/IEC 14496-12). It's meant to be low level, performing encoding/decoding of the binary format without validation or interpretation of the data. You have to know what boxes to expect!
Atoms
MP4 files are made up of atoms, which are boxes of data.
They have an upfront size and a 4-byte code to identify the type of box.
Examples include moov, mdat, trak, etc.
Unfortunately, the specification is quite complex and often gated behind a paywall. Using this library does require some additional knowledge of the format otherwise you should use a higher level library.
See the documentation.
Examples
Decoding/encoding a byte buffer
use ;
use ;
// A simple ftyp atom
let mut input = from_static;
let atom = decode?;
// Make sure we got the right atom
assert_eq!;
// Encode it back
let mut output = new;
atom.encode?;
assert_eq!;
Synchronous IO
NOTE: reading a Mdat atom will read the entire contents into memory.
See the next example to avoid this.
use ;
let mut reader = stdin;
let atom = read_from?;
// Make sure we got the right atom
assert_eq!;
// Encode it back to a Write type
let writer = stdout;
atom.write_to?;
Handling large atoms
To avoid reading large files into memory, you can call Header::read_from manually:
use ;
let mut reader = stdin;
let header = read_from?;
match header.kind ;
Asynchronous IO
Enable using the tokio feature.
It's the same as the above two but using the AsyncReadFrom, AsyncWriteTo, and AsyncReadAtom traits instead.