This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
mp4-atom is a Rust library for encoding/decoding ISO Base Media File Format (ISO/IEC 14496-12) atoms at a low level. MP4 files consist of atoms (boxes) containing data, identified by 4-byte FourCC codes (like moov, mdat, trak).
Build and check the code:
cargo build # Build the library
cargo build --all-features # Build with all features (bytes, tokio, serde)
cargo check --all-targets --all-features # Check all targets with all featuresRun tests:
cargo test # Run all tests
cargo test --all-targets # Run tests on all targets
cargo test <test_name> # Run a specific testCode quality and CI checks:
just check # Run full CI checks (check, clippy, fmt, shear)
just test # Run all tests
just fix # Auto-fix issues (fix, clippy fix, fmt, shear fix)Linting and formatting:
cargo clippy --all-targets --all-features -- -D warnings # Run clippy with strict warnings
cargo fmt -- --check # Check formatting
cargo fmt # Auto-format codeThe library revolves around several key traits defined in src/:
Atom(atom.rs): Core trait for all atom types, providesKINDconstant and encode/decode methodsDecode/Encode(coding.rs): For working with byte slicesReadFrom/WriteTo(io.rs): Synchronous IO operationsAsyncReadFrom/AsyncWriteTo(tokio/): Async IO with tokio featureBuf/BufMut(buf.rs): Custom buffer traits for contiguous byte slices
Atoms are organized hierarchically matching the MP4 format:
src/moov/: Movie metadata atoms (mvhd, trak, etc.)trak/: Track-level atomsmdia/: Media informationminf/stbl/: Sample table atomsstsd/: Sample descriptions for codecs (h264, hevc, av01, mp4a, etc.)
src/moof/: Movie fragment atoms for streamingsrc/meta/: Metadata atoms (HEIF/AVIF support)src/: Top-level atoms (ftyp, mdat, free, etc.)
-
Atom Encoding/Decoding: Each atom type implements the
Atomtrait with:KIND: FourCC identifierdecode_body(): Parse atom contentsencode_body(): Write atom contents
-
Header Handling: Use
Header::read_from()to handle large atoms without loading into memory -
Any Enum:
src/any.rsprovides a giant enum of all supported atoms for flexible decoding -
Error Handling: All operations return
Result<T>with custom error types inerror.rs
bytes: Enables support forbytescrate types (Bytes, BytesMut)tokio: Enables async IO supportserde: Enables serialization/deserialization support
Tests are located in:
- Unit tests: Within each module using
#[cfg(test)] - Integration tests:
src/test/directory with sample MP4 files for different codecs
Run specific codec tests:
cargo test h264 # Test H.264 support
cargo test hevc # Test HEVC support
cargo test av1 # Test AV1 support