diff --git a/src/api.rs b/src/api.rs index 8aa2c90..d2a81d6 100644 --- a/src/api.rs +++ b/src/api.rs @@ -67,6 +67,31 @@ pub struct Box { /// # Ok::<(), anyhow::Error>(()) /// ``` pub fn get_boxes(r: &mut R, size: u64, decode: bool) -> anyhow::Result> { + get_boxes_with_registry(r, size, decode, default_registry()) +} + +/// Parse an MP4/ISOBMFF file and return the complete box tree as JSON-serializable structures. +/// +/// # Parameters +/// - `r`: A reader that implements `Read + Seek` (e.g., `File`, `Cursor>`) +/// - `size`: The total size of the MP4 data to parse (typically file length) +/// - `decode`: Whether to decode known box types using the default registry +/// +/// # Returns +/// A vector of `Box` structs representing the top-level boxes in the file. +/// Each box contains metadata (offset, size, type) and optionally decoded content. +/// +/// # Example +/// ```no_run +/// use mp4box::{get_boxes_with_registry, registry::default_registry}; +/// use std::fs::File; +/// +/// let mut file = File::open("video.mp4")?; +/// let size = file.metadata()?.len(); +/// let boxes = get_boxes_with_registry(&mut file, size, true, default_registry())?; // decode known boxes +/// # Ok::<(), anyhow::Error>(()) +/// ``` +pub fn get_boxes_with_registry(r: &mut R, size: u64, decode: bool, registry: Registry) -> anyhow::Result> { // let mut f = File::open(&path)?; // let file_len = f.metadata()?.len(); @@ -114,10 +139,9 @@ pub fn get_boxes(r: &mut R, size: u64, decode: bool) -> anyhow:: } // build JSON tree - let reg = default_registry(); let json_boxes = boxes .iter() - .map(|b| build_box(r, b, decode, ®)) + .map(|b| build_box(r, b, decode, ®istry)) .collect(); Ok(json_boxes) diff --git a/src/lib.rs b/src/lib.rs index d87bf6b..0224bbe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,5 +93,5 @@ pub use registry::{ }; // High-level API -pub use api::{Box, HexDump, get_boxes, hex_range}; +pub use api::{Box, HexDump, get_boxes, get_boxes_with_registry, hex_range}; pub use samples::{SampleInfo, TrackSamples, track_samples_from_path, track_samples_from_reader};