Skip to content

About

Animate every run/activity that started from a particular radius as a 3D video (Blender).

Topics

Resources

Stars

55 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

Repository files navigation

strava-home-runs

tests Python 3.11+ License: MIT

Turns GPX, TCX or FIT files (from Strava, Garmin or any other GPS source) into a 3D video of every run that started within a chosen radius of one point. It generalizes the script I used to animate five years of runs that started from my home.

Animation of 289 runs leaving the same point in Barcelona, each at its own pace, with a clock and a histogram of finish times

All runs leave at the same moment and each one moves at its real pace. Routes you run often glow brighter, like a heat map. A clock, a "still running" counter and a histogram of finish times fill in as runners get home. The runner marker can be a cut-out of your face.

The map uses streets, lakes and rivers from OpenStreetMap and elevation from AWS Terrain Tiles, and is rendered in Blender. No API keys are needed.

Requirements

  • pixi, which installs Python, the Python packages and ffmpeg into a local environment.
  • Blender 5.0 or newer (tested with 5.2), installed separately.
macOS (Homebrew)
brew install pixi
brew install --cask blender
Linux
curl -fsSL https://pixi.sh/install.sh | sh
sudo snap install blender --classic   # or the tarball from blender.org
Windows (PowerShell)
winget install prefix-dev.pixi
winget install BlenderFoundation.Blender

The tool looks for Blender on your PATH and in /Applications/Blender.app; --blender /path/to/blender points it elsewhere. uv also works (uv run homeruns ...) if ffmpeg is on your PATH.

Getting your files

  • Strava: Settings → My Account → Download or Delete Your Account → Request your archive. Use the activities/ folder from the zip.
  • Garmin Connect: Account → Data Management → Export Your Data. The FIT files are in zip files inside the export; unzip those too.

The tool reads .gpx, .tcx and .fit files, gzipped or not, and searches folders recursively.

Usage

Run it from this folder. The first pixi run sets up the environment.

pixi run homeruns ~/Downloads/strava_export/activities --face me.png --place Lisbon --preview

--preview renders a half-size version in a few minutes. When it looks right, run the same command without --preview for the full 1440×2560 video. On an Apple Silicon Mac that takes about 1.5 hours (5 s per frame).

--face takes a PNG or WebP of a face on a transparent background. On macOS and iOS, "Copy Subject" in Photos makes one. The face is tinted orange; --tint 0 keeps its colours. Without --face, each runner is an orange dot.

pixi run homeruns --help lists all options.

Options
Option Default
--title, --subtitle HOME RUNS since <year>, <n> runs, <total> km Text at the top; can use {runs}, {km}, {first_year}, {last_year}
--place Added to the default subtitle
--credit Extra line under the map credit, e.g. "Running & editing: Your Name"
--radius 200 Metres from home a run must start within
--home auto lat,lon of home
--since, --until Date range, YYYY-MM-DD
--sport run Keep tracks whose type contains this; any keeps all
--seconds 30 Video seconds until the longest run finishes
--size 1440x2560 Output size; the layout is made for 9:16
--layout vertical feed: 4:5 crop (1440×1800) for LinkedIn or Instagram feeds. shorts: 9:16 with the text clear of the YouTube Shorts, Reels and TikTok buttons and caption. Works with --overlay-only
--style dark Map style of the video: dark, blueprint, or the light paper and mono (see Still images)
--privacy-radius 0 Cut this many metres around home from every track
--no-sea Don't treat land at sea level as sea (needed in places like the Netherlands); lakes and rivers from OpenStreetMap are still drawn
--line-strength auto Brightness of a single route
--crf 16 Video quality; higher gives a smaller file
--font-title, --font-text, --font-clock system fonts TTF/OTF files
--stills Also render still images of the finished heat map in dark, blueprint, paper and/or mono (no value: all)
--no-video Skip the video, e.g. to only make --stills
--keep-frames Keep the rendered PNGs in the work folder
--overlay-only Redraw the text on kept frames and encode, without Blender
Pipeline details
  1. Reads every track and keeps the runs (--sport). Files without a type are kept.
  2. Finds home, the place where most runs start (or --home lat,lon), and keeps the runs that start within --radius metres.
  3. Cleans the GPS: drops spikes faster than --max-speed (7 m/s), cuts a track where the signal is lost for good (in the metro, for example) and shortens long pauses.
  4. Downloads elevation, streets, lakes and rivers for the area and caches them in --work (default .homeruns/).
  5. Renders the scene in Blender, adds the text overlay and writes home_runs.mp4 and home_runs_final.png.
Title and overlay details

The title and subtitle can use {runs}, {km} (total distance), {first_year} and {last_year}, with Python format specs after a colon:

pixi run homeruns ~/Downloads/strava_export/activities --title "All my runs from home since {first_year}" \
    --subtitle "{runs} runs, {km:.0f} km, Lisbon"

The distance is measured on the cleaned tracks after --privacy-radius, so it can be a little lower than Strava's total.

Changing the text without rendering again

The text, clock and histogram are drawn after Blender renders the frames. Render with --keep-frames (a few GB at full size), and --overlay-only can redo the text in a few minutes without Blender:

pixi run homeruns ~/Downloads/strava_export/activities --face me.png --place Lisbon --keep-frames
pixi run homeruns --overlay-only --title "MY HOME RUNS" --place Lisbon

--overlay-only takes no track files. It reads everything from the work folder, so pass the same --work (and --preview for preview frames). It accepts the text, font, --credit, --layout, --out and --crf options. Changes to the 3D scene, such as the map, routes, camera, marker, --style or --seconds, need a full render. Frames kept before {km} was added don't store distances, so {km} can't be filled for them.

Still images

--stills also renders the finished heat map, without the text, as PNG images in four map styles: dark (the video's look), blueprint (blue), and paper and mono (light maps with the routes drawn like ink). Each is a single frame at twice the video size, cropped to the map, so it takes seconds. The same styles work for the video with --style, and the text and histogram follow the style's colours.

dark blueprint
Heat map of 289 Barcelona runs in the dark style: orange routes glowing on a night map The same heat map in the blueprint style: blue routes glowing on a dark blue map
paper mono
The same heat map in the paper style: dark red routes on a cream map with blue sea and rivers The same heat map in the mono style: black routes on a light grey map

With --no-video you get only the images:

pixi run homeruns ~/Downloads/strava_export/activities --stills --no-video         # all four styles
pixi run homeruns ~/Downloads/strava_export/activities --stills paper,mono --no-video

They are named after --out: home_runs_<style>.png by default, or home_runs_preview_<style>.png (at video size) with --preview. --stills takes an optional value, so put it after the files (or write --stills=paper).

Privacy

The video starts at your chosen location and every run leaves from it, and the still images show the same routes, so both can show where you live. --privacy-radius 300 cuts the first and last 300 m of every track, like Strava's privacy zones, so runners appear at the edge of the circle. With many runs the centre can still be estimated, so don't publish the video or the images if your address must stay private.

How it works
  • Timing: the clock starts slowly and speeds up exponentially, so the busy first minutes are readable and the long runs don't drag.
  • Camera: at every frame, it finds the closest position at which everything drawn so far fits between the title and the clock.
  • Heat: routes render additively in a separate view layer, and the compositor maps the sum onto a heat colour ramp.
  • Marker: each face is a camera-facing card at the head of its route.

The code is in homeruns/:

File Role
tracks.py Reads GPX/TCX/FIT, finds home, cleans GPS
basemap.py Downloads elevation, streets, lakes and rivers
prepare.py Builds the street texture and route points
scene.py Builds the scene in Blender
render_setup.py Render settings and the video's map style
styles.py Colours of the map styles
restyle.py Recolours the scene in a map style
stills.py Renders the last frame for still images
overlay.py Text, histogram and encoding; crops the still images
timewarp.py Clock curve
face.py Face and dot marker sprites
__main__.py Command line and pipeline

Tests for track reading, cleaning, the map cache, lake and river outlines and the clock curve are in tests/ and run with pixi run test (or uv run pytest). They don't include Blender.

Credits

  • Map data © OpenStreetMap contributors (ODbL). The video and the still images carry this credit.
  • Elevation from AWS Terrain Tiles (SRTM, GMTED, NED and other sources).
  • Strava is a trademark of Strava, Inc. and Garmin is a trademark of Garmin Ltd. This project is not affiliated with or endorsed by either.

License

MIT

About

Animate every run/activity that started from a particular radius as a 3D video (Blender).

Topics

Resources

Stars

55 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages