Skip to main content

trajviz

PyPI version PyPI downloads Python versions License: MIT CI pre-commit Ruff mypy Pydantic v2 Beartype

Fast 3D camera trajectory video renderer using NumPy + OpenCV.

Renders animated top-down trajectory visualizations from 3D camera positions, with configurable ghost trails, color-coded markers, glow effects, and camera frustum overlays. Frames are piped directly to ffmpeg as raw RGB — no intermediate files.

Spiral trajectory demo

Spiral trajectory with wedge frustum overlay. Colors encode time progression: blue at the start, magenta at the end. Generated by scripts/generate_demo.py.

Colors are user-provided as RGBA per position (n, 4), so they can encode anything. The renderer draws each segment with its assigned color and smoothly advances through the trajectory.

Coloring strategies

Time gradient — show trajectory progression:

t = np.linspace(0, 1, n, dtype=np.float32)
colors = np.stack([t, np.zeros(n), 1 - t, np.ones(n)], axis=1, dtype=np.float32)

Floor / zone coloring — assign colors by vertical position:

colors = np.zeros((n, 4), dtype=np.float32)
colors[:, 3] = 1.0  # full opacity
for i, z in enumerate(positions[:, 2]):
    if z < 3.0:
        colors[i, :3] = [0.2, 0.5, 0.9]   # blue = ground floor
    elif z < 6.0:
        colors[i, :3] = [0.9, 0.5, 0.1]   # orange = first floor
    else:
        colors[i, :3] = [0.1, 0.8, 0.4]   # green = second floor

Speed-based — highlight fast vs slow movement:

deltas = np.linalg.norm(np.diff(positions, axis=0), axis=1)
speed = np.concatenate([[deltas[0]], deltas])
speed_norm = (speed - speed.min()) / (speed.max() - speed.min() + 1e-8)
colors = plt.get_cmap("coolwarm")(speed_norm).astype(np.float32)

Uniform — single color for the entire trajectory:

colors = np.tile([0.2, 0.8, 0.4, 1.0], (n, 1)).astype(np.float32)

Installation

pip install trajviz
# or
uv add trajviz

Usage

import numpy as np
from trajviz import render_trajectory_video, TrajectoryRenderConfig

# Random 3D trajectory
positions = np.random.randn(120, 3).astype(np.float32)
positions = np.cumsum(positions * 0.1, axis=0)

# RGBA colors per frame (e.g., gradient from blue to red)
t = np.linspace(0, 1, 120)
colors = np.stack([t, np.zeros(120), 1 - t, np.ones(120)], axis=1).astype(np.float32)

render_trajectory_video(
    positions=positions,
    colors_rgba=colors,
    output_path="trajectory.mp4",
)

Configuration

All rendering options are controlled via TrajectoryRenderConfig:

from trajviz import TrajectoryRenderConfig, FrustumStyle

config = TrajectoryRenderConfig(
    width=1080,
    height=1080,
    elevation_deg=45.0,
    frustum_style=FrustumStyle.WEDGE,
    fps=30,
)

render_trajectory_video(positions, colors, "out.mp4", config=config)

Side-by-side comparison

Combine a recording with its trajectory overlay:

from trajviz import combine_videos_side_by_side

combine_videos_side_by_side(
    left_path="recording.mp4",
    right_path="trajectory.mp4",
    output_path="combined.mp4",
    fps=30,
)

Development

pip install -e ".[dev]"
pre-commit install

# Run tests
pytest tests/ -v

# Run linting
pre-commit run --all-files

Requirements

  • Python >= 3.10
  • ffmpeg on PATH
  • numpy, opencv-python-headless, pydantic, jaxtyping, beartype, difflogtest

Metadata

Release files for trajviz 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trajviz 0.1.0
File Size Uploaded Provenance
trajviz-0.1.0.tar.gz 312.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for trajviz 0.1.0
File Interpreter ABI Platform
trajviz-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 325.2 kB

Release files / trajviz-0.1.0.tar.gz

Download URL trajviz-0.1.0.tar.gz
Size 312.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b1bd02d9ea5a024f6e1ded190ad522689722914176f78d404fe9980177d38370
BLAKE2b-256 checksum
How to use checksums
db61c86b8a747fc79c1910a465cc7fc04a319bfef94fce33e3127a8c696f8c75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 12, 2026.

Transparency log

Release files / trajviz-0.1.0-py3-none-any.whl

Download URL trajviz-0.1.0-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ffdb72ad4f9ddfac2605ea9d6696c66373459622d19c4ce32b186a70b7ab5b56
BLAKE2b-256 checksum
How to use checksums
75570bf80f8cb602378b39b433d35306ee273ad429a4c44a32f0d32ce8dd1c8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 12, 2026.

Transparency log

Security for trajviz 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for trajviz-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page