Expand description
§Media Analyzer
A toolkit for extracting info from video and photo files.
This crate provides a high-level, asynchronous API to analyze media files. It acts as a
facade over tools like exiftool, combining raw metadata with parsing,
geolocation, and historical weather data to produce a single, easy-to-use result.
The core philosophy is to be a “best-effort” analyzer. It robustly processes what it can, and provides detailed information in a structured format.
§Prerequisites
This crate requires a command-line installation of exiftool to be available in the
system’s PATH. You can download it from the official ExifTool website.
You can also pass the location of you exiftool executable if you don’t want it in PATH.
§Key Features
-
Unified Metadata: Gathers basic properties like width, height, duration, and MIME type into a clean
FileMetadatastruct, while also providing photographic details like ISO, aperture, and camera model inCaptureDetails. -
Time Resolution: It analyzes multiple EXIF tags, file metadata, and GPS data to determine the most accurate UTC timestamp and timezone information, summarized in the
TimeInfostruct. -
Geolocation & Weather: Automatically performs reverse geocoding on GPS coordinates to find human-readable location names (
GpsInfo). If successful, it then fetches historical weather and sun data (sunrise, sunset) for the precise time and place the media was captured, populating theWeatherInfostruct. -
Rich Media Tagging: Identifies a wide variety of special media characteristics, such as
is_motion_photo,is_hdr,is_burst,is_slowmotion, andis_timelapse, all available in theTagDatastruct. -
Thumbnail Generation: Creates a tiny, Base64-encoded JPEG data URL, for use as a blurred placeholder in a UI while the full media loads.
§The AnalyzeResult Struct
The 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.
§Usage
- Create a
MediaAnalyzerinstance using its builder. - Call the
MediaAnalyzer::analyze_mediamethod with the path to your media file.
use std::path::Path;
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(50.0) // Optional: configure the analyzer
.build()
.await?;
// 2. Define the path to the media file to analyze.
let media_file = Path::new("assets/sunset.jpg");
// 3. Analyze the media file. For a photo, the file itself can serve as the thumbnail.
let result = analyzer.analyze_media(media_file).await?;
// 4. Access the structured 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);
}
Ok(())
}Structs§
- Analyze
Result - Capture
Details - File
Metadata - GpsInfo
- Location
Name - Media
Analyzer - The main entry point for the media analysis pipeline.
- Media
Analyzer Builder - Use builder syntax to set the inputs and finish with
build(). - Pano
Info - Pano
View Info - Source
Details - Provides context on the origin and reliability of the extracted time information.
- SunInfo
- TagData
- Time
Info - Represents the extracted and consolidated time information for a media file.
- Time
Zone Info - Contains details about the timezone determination.
- Weather
Info
Enums§
- Media
Analyzer Error - The primary error type for the media-analyzer crate.