media_analyzer
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.
Prerequisites
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.
- Official Website & Installation: https://exiftool.org/
- macOS (Homebrew):
brew install exiftool - Debian/Ubuntu:
sudo apt install libimage-exiftool-perl - Windows: Download the Windows Executable from the official website and ensure its location is in your PATH environment variable.
Verify your installation by typing exiftool -ver in your terminal.
Features
- 🗃️ Unified Metadata: Gathers core properties (
FileMetadata) and photographic details (CaptureDetails) from media files. - 🕰️ Time Resolution: Analyzes multiple tags to determine the most accurate UTC timestamp and
timezone (
TimeInfo). - 🌍 Geolocation & Weather: Performs reverse geocoding on GPS coordinates (
GpsInfo) and fetches historical weather and sun data (WeatherInfo) from the time of capture. - 🏷️ Rich Media Tagging: Identifies special characteristics like
is_motion_photo,is_hdr,is_burst, andis_slowmotion(TagData). - 🖼️ Thumbnail Generation: Creates a tiny, Base64-encoded JPEG data URL, perfect for UI placeholders.
- ✅ Robust & Asynchronous: Built with
tokiofor non-blocking I/O and provides clear error handling via the [MediaAnalyzerErrorenum.
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.
Installation
Add media_analyzer to your Cargo.toml dependencies:
Quick Start
Create a MediaAnalyzer instance using its builder, then call the analyze_media method.
use ;
async
Error Handling
All potentially failing operations return Result<_, MediaAnalyzerError>. The MediaAnalyzerError enum covers
critical failures in the analysis pipeline, including:
Exiftool: Theexiftoolprocess 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.- And others for I/O and initialization issues.
Core Dependencies
This crate is a high-level orchestrator that builds upon several powerful tools and libraries:
- ExifTool: The definitive tool for reading and writing media metadata.
- exiftool_rs: For persistent communication with the
exiftoolprocess. - meteostat_rs: For fetching historical weather and climate data.
- reverse_geocoder: For offline reverse geocoding.
- Chrono & Chrono-tz: For time and timezone handling.
API Documentation
Full API documentation is available on docs.rs.
Contributing
Contributions, bug reports, and feature requests are welcome! Please open an issue or submit a pull request on the GitHub repository.
License
This crate is licensed under the Apache License 2.0. See the LICENSE.md file for details.