- Go 100%
| .gitignore | ||
| go.mod | ||
| go.sum | ||
| main.go | ||
| README.md | ||
| todo.md | ||
Go Drone Cam GPS
Automatically select the sharpest frames from a drone video and geotag them using ArduPilot flight logs for use in photogrammetry software like WebODM.
This tool automates the tedious process of manually selecting clear frames from a video. Instead of extracting frames at a fixed interval (e.g., one every 4 seconds), it analyzes the video to find the frame with the least motion blur within each time window, leading to higher quality map and 3D model generation.
Features
- Blur Detection: Uses FFmpeg's Laplacian filter to calculate a sharpness score for every frame.
- Intelligent Frame Selection: Finds the single sharpest frame within configurable time windows (default is 3 seconds).
- Automatic Geotagging: Parses ArduPilot JSON logs to find the flight's takeoff time and GPS coordinates.
- EXIF Data Injection: Uses
exiftoolto write GPS latitude, longitude, and altitude to the selected image frames. - Simplified Workflow: Replaces a multi-step manual process with a single command.
Requirements
- Go: The programming language the tool is written in.
- FFmpeg: For video analysis (sharpness) and frame extraction.
- ExifTool: For writing GPS metadata to the final images.
mavlogdump.py(frompymavlink): To convert the binary ArduPilot dataflash log (.bin) into a JSON format the tool can read.
Usage
Step 1: Convert ArduPilot Log to JSON
First, convert your drone's binary dataflash log file (.bin) into the required JSON format.
mavlogdump.py --format json your-flight-log.bin > log.json
Step 2: Combine and Prepare Your Video (If Necessary)
If your drone records video in multiple files, you should combine them into a single video file first.
# This example command safely concatenates all .MP4 files in the current directory
ffmpeg -f concat -safe 0 -i <(for f in ./*.MP4; do echo "file '$PWD/$f'"; done) -c copy combined.mp4
Step 3: Run the Go Program
Execute the main program, providing the path to your combined video and the JSON log file. The program will create an images directory and populate it with the sharpest, geotagged frames.
go run main.go -v combined.mp4 -l log.json -t 3
Command-line Flags:
-v: Path to the video file (required).-l: Path to the JSON log file (required).-t: Time step in seconds between selected frames (optional, default:3).
The program will:
- Analyze
combined.mp4for frame sharpness (this may take some time). - Read
log.jsonto determine the flight path and timing. - Select the best frames.
- Create an
imagesdirectory. - Extract the selected frames into
images/output_xxxx.png. - Write GPS coordinates to each image.
Step 4: Upload to Photogrammetry Software
Upload the resulting images from the images directory to your photogrammetry software (e.g., WebODM).