Skip to main content

Estimate the distance to an explosion from video and audio analysis

Project description

Explosion Distance Estimator

Install this package with:

pip install explosion_distance_estimator

Then run:

explosion-distance-estimator --help

Overview

The Explosion Distance Estimator is a Python tool that estimates the distance to an explosion in a video. It calculates the distance based on the delay between the visible flash and the sound of the blast, using video and audio analysis, real-world temperature data from Open-Meteo, and basic physics principles.

Features:

  • Video Analysis: Extracts frames from the video to detect the moment of the explosion (flash).
  • Audio Analysis: Extracts the audio and detects the peak of the explosion's sound.
  • Temperature Data: Fetches temperature data from Open-Meteo for the given date and location.
  • Distance Calculation: Uses basic physics to estimate the distance to the explosion:
    v = 331 + 0.6 × T
    distance = (sound_time - flash_time) × v
    

Basic run

python3 explosion_distance_estimator.py

Uses:

  • Default video: test_explosion.mp4
  • Today’s date
  • Kyiv coordinates (lat: 50.4501, lon: 30.5234)

Full CLI options

python3 explosion_distance_estimator.py   --video explosion.mp4   --lat 47.0951   --lon 37.5496   --temp 1   --plot   --keep   --outdir output

Options:

Flag Description
--video Path to the video file (MP4 with audio)
--temp Weather date: either a day offset (0 = today, 1 = yesterday) or exact date (2024-03-27)
--lat Latitude of the explosion location
--lon Longitude of the explosion location
--plot Generate 3 plots: brightness, audio spectrogram, and combined view
--keep Keep extracted frames and audio after analysis
--outdir Output folder for logs, plots, and CSV (default: output)

Output

  • Plots: brightness_plot.png, audio_spectrogram.png, combined_plot.png (if --plot is set)
  • Run log: output/run_YYYYMMDD_HHMMSS.log
  • CSV log: output/log.csv
  • Temporary frames and audio (only if --keep is used)

Example Scenarios

# Detect explosion from a video recorded yesterday in Mariupol
python3 explosion_distance_estimator.py   --video mariupol_blast.mp4   --temp 1   --lat 47.0951   --lon 37.5496   --plot

# Estimate using a historical date and keep all intermediate files
python3 explosion_distance_estimator.py   --temp 26.03.2025   --keep

How It Works

  1. Extract frames from the video and analyze brightness
  2. Detect the flash moment (spike in brightness)
  3. Extract audio and detect the sound peak (blast)
  4. Fetch temperature for the provided date/location via Open-Meteo
  5. Estimate the distance using basic physics:
    v = 331 + 0.6 × T
    distance = (sound_time - flash_time) × v
    

Installation

Install this package locally with:

pip install explosion_distance_estimator

Then run:

explosion-distance-estimator --help

Requirements

🔧 FFmpeg Required

This tool uses ffmpeg under the hood to extract audio from video files. You must have the FFmpeg binary installed and accessible in your system’s PATH.

🛠️ How to install FFmpeg:

macOS

  1. With Homebrew (recommended):

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    brew install ffmpeg
    
  2. Manual download:

    • Download from: https://evermeet.cx/ffmpeg/
    • Move the downloaded ffmpeg binary to /usr/local/bin/:
      sudo mv ~/Downloads/ffmpeg /usr/local/bin/
      chmod +x /usr/local/bin/ffmpeg
      

Windows

  1. Download FFmpeg from: https://ffmpeg.org/download.html
  2. Extract and move the bin/ directory to a known location (e.g., C:\ffmpeg\bin)
  3. Add that location to your system PATH:
    • Open Start Menu → search “Environment Variables”
    • Edit PATH and add C:\ffmpeg\bin

Linux (Debian/Ubuntu)

sudo apt update
sudo apt install ffmpeg

Check installation

After installing, confirm ffmpeg is available:

ffmpeg -version

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

explosion_distance_estimator-1.0.2.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

explosion_distance_estimator-1.0.2-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file explosion_distance_estimator-1.0.2.tar.gz.

File metadata

File hashes

Hashes for explosion_distance_estimator-1.0.2.tar.gz
Algorithm Hash digest
SHA256 5e1ba04624f3fdc14786067bf2c6f3e667fb9d92e785b8e241a2960ec10cd616
MD5 d5c4b3ed1de33bb130b0a3bb0d5667c9
BLAKE2b-256 a105372e484681f121b36d7edaf44e6b2757abf75c363674b12a9b6e95f84c95

See more details on using hashes here.

File details

Details for the file explosion_distance_estimator-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for explosion_distance_estimator-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9813d83be5a77430911b8693383e016c5d345e49e739475cd3441dc4c517c1e5
MD5 66bc73056c4f4f7df6d53b623dbede38
BLAKE2b-256 8e67f96d9f013e798ff133c8424f0ad20080865a605c29a63efd971cedb5a932

See more details on using hashes here.

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