Skip to main content

Analyze video/image with machine learning methods, exif data, and other file based information.

Project description

Media Analyzer

Media Analyzer is a Python library designed to analyze media files, providing insights into their content and metadata. It supports various functionalities, including image classification, captioning, optical character recognition (OCR), and facial recognition.

Features

  • GPS: Gather GPS coordinates from exif, and reverse geocode to get the country, province and city.
  • Exif: Extract exif data/metadata from photos, videos, gifs, etc.
  • Weather: Get weather info at the time the photo/video was taken.
    • temperature
    • dewpoint
    • relative humidity
    • precipitation
    • wind gust
    • pressure
    • sun hours
    • condition
  • Quality Detection: Detect objectively measurable quality of images:
    • Sharpness
    • Noise
    • Exposure
    • Dynamic range
    • Color clipping (white/black levels)
    • A composite score is generated, so photos can be ranked by quality.
  • Image Classification: Identify objects, scene type, activities, animals, and events present in images.
  • Image Captioning: Generate descriptive captions for images using models like BLIP or LLM-based captioners.
  • Embedding: Generate clip embeddings for images and text. Can be used to cluster images or search semantically through images.
  • Optical Character Recognition (OCR): Extract text from images to identify documents, receipts, menus, and more.
  • LLM: Get detailed image summary, more indepth than just a caption, using an LLM. Can also be used to generate a summary of a document shown in a photo or video.
  • Facial Recognition: Detect faces in images and provide details such as age, sex, bounding box, and facial landmarks. Includes an embedding of the face, which can be used for clustering.
  • Datetime Taken: Photo and video files are messy and have unreliable datetime tags. This packages uses six different methods with varying priority to get the datetime a photo is taken, including the timezone if possible.
  • Data Url: Generate data url for tiny preload thumbnail.

Installation

To install Media Analyzer, use pip:

pip install media-analyzer

Requirements

You must have the following in PATH.

Examples

Example output of the main analyze function can be viewed at example_output.json. Further example code is available at /examples.

Usage

Here's a basic example of how to use Media Analyzer:

from media_analyzer import MediaAnalyzer
from pathlib import Path

analyzer = MediaAnalyzer()
media_file = Path("image.jpg")
result = analyzer.photo(media_file)

print(result)

Disable analysis modules

The analysis is done based on modules, the following modules are available and enabled by default:

File-based Modules:

  • "DataUrlModule"
  • "ExifModule"
  • "GPSModule"
  • "TimeModule"
  • "WeatherModule"

Visual Modules:

  • "CaptionModule"
  • "ClassificationModule"
  • "EmbeddingModule"
  • "FacesModule"
  • "ObjectsModule"
  • "OCRModule"
  • "QualityDetectionModule"
  • "SummaryModule"

Modules can be turned off by changing the config provided to the MediaAnalyzer class:

from media_analyzer import MediaAnalyzer, AnalyzerSettings, FileModule, VisualModule
from pathlib import Path

config = AnalyzerSettings(
  enabled_file_modules={FileModule.EXIF},  # Only do exif data analysis on file
  enabled_visual_modules={VisualModule.CAPTION},  # Only do caption module as visual module
)
analyzer = MediaAnalyzer(config=config)
media_file = Path(__file__).parents[1] / "tests/assets/tent.jpg"
result = analyzer.photo(media_file)

Configuration

The AnalyzerSettings class allows you to customize various aspects of the analysis:

media_languages: List of languages for OCR to consider.
captions_provider: The provider for image captioning (e.g., 'BLIP', 'LLM').
enable_text_summary: Enable or disable text summarization.
enable_document_summary: Enable or disable document summarization.
document_detection_threshold: Confidence threshold for document detection.
face_detection_threshold: Confidence threshold for face detection.
enabled_file_modules: List of file modules to enable (e.g., exif data, gps, weather detection).
enabled_visual_modules: List of visual modules to enable (e.g., 'classification', 'captioning', 'ocr', 'facial_recognition').

Full docs can be found at https://ruurdbijlsma.github.io/media-analyzer.

Attribution

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

media_analyzer-0.2.2.tar.gz (35.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

media_analyzer-0.2.2-py3-none-any.whl (69.4 kB view details)

Uploaded Python 3

File details

Details for the file media_analyzer-0.2.2.tar.gz.

File metadata

  • Download URL: media_analyzer-0.2.2.tar.gz
  • Upload date:
  • Size: 35.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for media_analyzer-0.2.2.tar.gz
Algorithm Hash digest
SHA256 fa117ac992f2465f7d27027eded3c1dc38e0c10307aab596c34bd921c67dde6c
MD5 2912c09d18e7129d1466eb827b49782e
BLAKE2b-256 55a51eb57da178d52a751b67a00d4621b97da61d76f3d2f10c98f3e0932ad696

See more details on using hashes here.

Provenance

The following attestation bundles were made for media_analyzer-0.2.2.tar.gz:

Publisher: publish-to-pypi.yml on RuurdBijlsma/media-analyzer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file media_analyzer-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: media_analyzer-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 69.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for media_analyzer-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 44af6fad8d7744da4ff138976212ae839b8dc1d63f27f6ff352c021cadf1d984
MD5 814369f0be584f265a7c4ad529bb2c9a
BLAKE2b-256 800c4ce230470b38f4b888042c2e51ec7628ca37ad7c9de8f05f9cc8c682d2be

See more details on using hashes here.

Provenance

The following attestation bundles were made for media_analyzer-0.2.2-py3-none-any.whl:

Publisher: publish-to-pypi.yml on RuurdBijlsma/media-analyzer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page