Skip to main content

Crate media_analyzer

Crate media_analyzer 

Source
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 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 BasicMetadata struct, while also providing photographic details like ISO, aperture, and camera model in CameraSettings.

  • 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 TimeInfo struct.

  • Rich Media Tagging: Identifies a wide variety of special media characteristics, such as is_motion_photo, is_hdr, is_burst, is_slowmotion, and is_timelapse, all available in the MediaFeatures struct.

  • 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 MediaMetadata Struct

The primary output of this crate is the MediaMetadata 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

  1. Create a MediaAnalyzer instance using its builder.
  2. Call the MediaAnalyzer::analyze_media method 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 analyzer = MediaAnalyzer::builder()
        .build()?;

    // 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)?;

    // 4. Access the structured data from the `MediaMetadata`.
    if let Some(gps) = result.gps {
        println!("Location: {}, {}", gps.location.name, gps.location.country_code);
    }

    if let Some(model) = result.camera.camera_model {
        println!("Camera: {}", model);
    }

    if let Some(utc_time) = result.time.datetime_utc {
        println!("Taken at (UTC): {}", utc_time);
    }

    Ok(())
}

Structs§

BasicMetadata
CameraSettings
GpsInfo
LocationName
MediaAnalyzer
The main entry point for the media analysis pipeline.
MediaAnalyzerBuilder
Use builder syntax to set the inputs and finish with build().
MediaFeatures
MediaMetadata
PanoInfo
PanoViewInfo
SourceDetails
Provides context on the origin and reliability of the extracted time information.
TimeInfo
Represents the extracted and consolidated time information for a media file.
TimeZoneInfo
Contains details about the timezone determination.

Enums§

MediaAnalyzerError