Skip to main content

Crate mpn

Crate mpn 

Source
Expand description

§mpn

mpn is a Rust command-line tool that sniffs common media containers from magic bytes, deep-inspects MPEG-4 / ISO BMFF (MP4-family) files with mp4parse, and prints structured TOML-like text to stdout.

Crates.io Crates.io GitHub Repo stars GitHub repo size main docs.rs License License

§Usage

mpn path/to/media.file
mpn --help

Every run emits a [media] block with sniffed format, mime, and inspect. When inspect = true, track and codec sections from mp4parse are included. Other recognized containers exit successfully with inspect = false and no track dump.

Exit status is 0 on success (including sniff-only), 1 on I/O or parse errors (error = "…" on stderr).

§Sniffing vs inspect

StageWhat happens
SniffRead leading bytes; set format, mime, and whether the file is MP4-family.
InspectOnly when MP4-family (inspect = true): parse boxes, tracks, codecs.

Sniffed containers include MP4 / M4V / MOV / M4A / 3GP (inspectable), plus Matroska / WebM, WAV, AVI, Ogg, FLAC, AIFF, FLV, ASF, MPEG-TS, MP3, and unknown (application/octet-stream).

§Output

MP4-family file (inspect runs; track sections truncated):

$ mpn tests/files/test-bokeh-au-2t-vd-30f-854x480.mp4

[media]
uri = "tests/files/test-bokeh-au-2t-vd-30f-854x480.mp4"
bytes = 441551
format = "m4v"
mime = "video/x-m4v"
inspect = true
modified = …
[media.track.audio]
track_id = 1
…
[media.track.video.codec]
codec_name = "AVC"

Non-media or unrecognized content (sniff only):

$ mpn src/main.rs

[media]
uri = "src/main.rs"
bytes = …
format = "unknown"
mime = "application/octet-stream"
inspect = false

§Installation

§crates.io

If Rust and Cargo are installed, this is the quickest way to get a release binary:

cargo install mpn

§From source

git clone https://github.com/sitkevij/mpn && \
cd mpn && \
cargo test && \
cargo build --release && \
target/release/mpn tests/files/test-bokeh-au-2t-vd-30f-854x480.mp4

§Packaging

Distro packages and other channels:

Packaging status

§Development

make ci          # format check, clippy, tests (matches GitHub CI core)
make pre-commit  # format, clippy, tests (local commits)

The first cargo test builds dev-dependencies and installs rusty-hook from .rusty-hook.toml (pre-commit runs make pre-commit).

§License

MIT OR Apache-2.0

§Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

§mpn - Overview

This library provides functionality to inspect MPEG-4 (MP4) files and extract detailed metadata about their structure, tracks, codecs, and timing information.

§Features

  • Sniff common video/audio container formats from magic bytes
  • Parse MP4 file structure and metadata (deep inspect for MP4-family only)
  • Extract video track information (dimensions, codec, timing)
  • Extract audio track information (channels, sample rate, codec)
  • Display file system metadata (creation, modification, access times)
  • Support for multiple video codecs (AVC, AV1, VPx, MP4V, H.263)
  • Support for multiple audio codecs (ES, FLAC, Opus, ALAC, MP3, LPCM)

§Usage

The main entry point is the run function, which takes parsed command-line arguments and processes a media file (deep inspect for MPEG-4 / ISO BMFF).

§Output Format

The library outputs structured information in an INI-like format with sections:

  • [media] - File-level metadata, including sniffed format / mime / inspect
  • [media.track.video] - Video track information
  • [media.track.audio] - Audio track information
  • [media.track.video.header] - Video track header details
  • [media.track.audio.header] - Audio track header details
  • [media.track.video.codec] - Video codec-specific information
  • [media.track.audio.codec] - Audio codec-specific information

Structs§

Media
Media struct which holds file metadata.

Constants§

ARG_MEDIAFILE
Command-line argument name for the media file path.

Functions§

run
Inspect MP4 file and output box metadata.