Expand description
mp4san
is an MP4 format “sanitizer”.
Currently the sanitizer always performs the following functions:
- Return all presentation metadata present in the input as a self-contained contiguous byte array.
- Find and return a pointer to the span in the input containing the (contiguous) media data.
“Presentation” metadata means any metadata which is required by an MP4 player to play the file. “Self-contained and contiguous” means that the returned metadata can be concatenated with the media data to form a valid MP4 file.
The original metadata may or may not need to be modified in order to perform these functions. In the case that the
original metadata does not need to be modified, the returned SanitizedMetadata::metadata
will be None
to
prevent needless data copying.
§Unsupported MP4 features
The sanitizer does not currently support:
- “Fragmented” MP4 files, which are mostly used for adaptive-bitrate streaming.
- Discontiguous media data, i.e. media data (
mdat
) boxes interspersed with presentation metadata (moov
). - Media data references (
dref
) pointing to separate files. - Any similar format, e.g. Quicktime File Format (
mov
) or the legacy MP4 version 1, which does not contain theisom
compatible brand in its file type header (ftyp
).
§Usage
The main entry points to the sanitizer are sanitize
/sanitize_async
, which take a Read
+ Skip
input.
The Skip
trait represents a subset of the Seek
trait; an input stream which can be skipped forward, but not
necessarily seeked to arbitrary positions.
let example_input = [example_ftyp(), example_mdat(), example_moov()].concat();
let sanitized = mp4san::sanitize(std::io::Cursor::new(example_input))?;
assert_eq!(sanitized.metadata, Some([example_ftyp(), example_moov()].concat()));
assert_eq!(sanitized.data.offset, example_ftyp().len() as u64);
assert_eq!(sanitized.data.len, example_mdat().len() as u64);
The parse
module also contains a less stable and undocumented API which can be used to parse individual MP4 box
types.
Re-exports§
pub use crate::error::Error;
Modules§
Structs§
- Config
- Configuration for the MP4 sanitizer.
- Config
Builder - Builder for
Config
. - Input
Span - A pointer to a span in the given input.
- Sanitized
Metadata - Sanitized metadata returned by the sanitizer.
- Seek
Skip Adapter - An adapter implementing
Skip
/AsyncSkip
for all types implementing [Seek
]/[AsyncSeek
].
Enums§
- Config
Builder Error - Error type for ConfigBuilder
Constants§
- COMPATIBLE_
BRAND - The ISO Base Media File Format “compatble brand” recognized by the sanitizer.
Traits§
- Async
Skip - A subset of the [
AsyncSeek
] trait, providing a cursor which can skip forward within a stream of bytes. - Skip
- A subset of the [
Seek
] trait, providing a cursor which can skip forward within a stream of bytes.
Functions§
- sanitize
- Sanitize an MP4 input, with the default
Config
. - sanitize_
async - Sanitize an MP4 input asynchronously, with the default
Config
. - sanitize_
async_ with_ config - Sanitize an MP4 input asynchronously, with the given
Config
. - sanitize_
with_ config - Sanitize an MP4 input, with the given
Config
.