| Crates.io | media_analyzer |
| lib.rs | media_analyzer |
| version | 0.3.9 |
| created_at | 2025-09-30 21:01:21.059603+00 |
| updated_at | 2025-11-07 18:58:02.79326+00 |
| description | Extract file-based information from photo and video files. |
| homepage | https://github.com/ruurdbijlsma/media_analyzer_rs |
| repository | https://github.com/ruurdbijlsma/media_analyzer_rs |
| max_upload_size | |
| id | 1861737 |
| size | 250,676 |
A Rust crate for extracting information from video and photo files.
This crate provides a high-level, asynchronous API that acts as an orchestrator over tools like exiftool, combining
raw metadata with intelligent parsing, geolocation, and historical weather data to produce a single, structured, and
easy-to-use result.
Example output, converted to json, viewable here.
This crate requires an installation of exiftool to be available. If you don't want it in your PATH, you can pass
the location of the executable in when building a MediaAnalyzer.
brew install exiftoolsudo apt install libimage-exiftool-perlVerify your installation by typing exiftool -ver in your terminal.
FileMetadata) and photographic details (CaptureDetails) from
media files.TimeInfo).GpsInfo) and fetches historical
weather and sun data (WeatherInfo) from the time of capture.is_motion_photo, is_hdr, is_burst, and
is_slowmotion (TagData).tokio for non-blocking I/O and provides clear error handling via the [
MediaAnalyzerError enum.AnalyzeResult StructThe primary output of this crate is the AnalyzeResult struct. It is a single, consolidated container that holds all
the information gathered during the analysis pipeline, making it easy to access any piece of data you need.
Add media_analyzer to your Cargo.toml dependencies:
cargo add media_analyzer
Create a MediaAnalyzer instance using its builder, then call the analyze_media method.
use media_analyzer::{MediaAnalyzer, MediaAnalyzerError};
#[tokio::main]
async fn main() -> Result<(), MediaAnalyzerError> {
// 1. Build the analyzer. The builder allows for custom configuration.
let mut analyzer = MediaAnalyzer::builder()
.weather_search_radius_km(75.0) // Optional: configure the analyzer
.build()
.await?;
// 2. Define the path to the photo or video file to analyze.
let media_file = Path::new("path/to/your/photo.jpg");
// 3. Analyze the photo, for a video you'd use analyze_media.
// The thumbnail should be tiny, as it's meant to be a preview file
// that might be shown while the real image is loading. For example, at most 10x10 pixels.
let result = analyzer.analyze_media(media_file).await?;
// 4. Access the data from the `AnalyzeResult`.
if let Some(gps) = result.gps_info {
println!("Location: {}, {}", gps.location.name, gps.location.country_code);
}
if let Some(model) = result.capture_details.camera_model {
println!("Camera: {}", model);
}
if let Some(utc_time) = result.time_info.datetime_utc {
println!("Taken at (UTC): {}", utc_time);
}
if result.tags.is_hdr {
println!("This is an HDR image.");
}
Ok(())
}
All potentially failing operations return Result<_, MediaAnalyzerError>. The MediaAnalyzerError enum covers
critical failures in the analysis pipeline, including:
Exiftool: The exiftool process failed to execute or read the file.Metadata: The media file was missing essential tags required for analysis (e.g., ImageWidth).Time: No usable time or date information could be extracted from any source.DataUrl: The provided thumbnail path was invalid or not a supported image format.Weather: The external weather API call failed.This crate is a high-level orchestrator that builds upon several powerful tools and libraries:
exiftool process.Full API documentation is available on docs.rs.
Contributions, bug reports, and feature requests are welcome! Please open an issue or submit a pull request on the GitHub repository.
This crate is licensed under the Apache License 2.0. See the LICENSE.md file for details.