BVH reader/writer and kinematics utilities
Project description
pybvh
A lightweight Python library for reading, writing, and manipulating BVH motion capture files. Built for researchers and developers working with skeletal animation and motion data.
Features
- Read & write BVH files with full hierarchy and motion data preservation
- Rotation conversions between Euler angles, rotation matrices, quaternions, 6D (Zhou et al.), and axis-angle — all vectorized with NumPy
- Forward kinematics to compute 3D joint positions from angles
- Skeleton operations: retargeting, scaling, joint extraction, Euler order changes
- Frame operations: slicing, concatenation, resampling to different frame rates
- Batch loading of entire directories with optional parallel I/O
- NumPy export in any rotation representation — ready for ML pipelines
- Pandas ready via an export option ready to become a Dataset
- 3D visualization with Matplotlib (static frames and animated videos)
Installation
pip install pybvh
Quick Start
import pybvh
# Load a BVH file
bvh = pybvh.read_bvh_file("walk.bvh")
print(bvh) # 24 joints, 120 frames at 0.008333Hz
# Access motion data as NumPy arrays
bvh.root_pos # (F, 3) root translation per frame
bvh.joint_angles # (F, J, 3) Euler angles in degrees
bvh.joint_names # ['Hips', 'Spine', ...] (excludes end sites)
# Get 3D joint positions via forward kinematics
coords = bvh.get_spatial_coord() # (F, N, 3)
# Convert to other rotation representations
root_pos, quats, joints = bvh.get_frames_as_quaternion() # (F,3), (F,J,4), joints
root_pos, rot6d, joints = bvh.get_frames_as_6d() # (F,3), (F,J,6), joints
# Write back to file
bvh.to_bvh_file("output.bvh")
Batch Loading for ML
Load an entire dataset directory and convert to NumPy arrays in one call:
from pybvh import read_bvh_directory, batch_to_numpy
# Load all BVH files from a directory
clips = read_bvh_directory("dataset/", parallel=True)
# Convert to padded NumPy array — ready for training
data = batch_to_numpy(clips, representation="6d", pad=True)
# shape: (batch, max_frames, features)
Supported representations: "euler", "quaternion", "6d", "axisangle", "rotmat".
Skeleton Operations
# Change Euler rotation order for all joints
bvh_xyz = bvh.change_all_euler_orders("XYZ")
# Scale the skeleton
bvh_scaled = bvh.scale_skeleton(0.01) # meters to centimeters
# Retarget motion to a different skeleton
bvh_retarget = bvh.change_skeleton(reference_bvh)
# Extract a subset of joints
bvh_upper = bvh.extract_joints(["Hips", "Spine", "Neck", "Head"])
# Slice and concatenate frames
clip = bvh.slice_frames(10, 50)
combined = bvh.concat(other_bvh)
# Resample to a different frame rate
bvh_30fps = bvh.resample(30)
Rotation Utilities
All functions are batch-vectorized and work on arbitrary batch dimensions:
from pybvh import rotations
# Convert between any pair of representations
R = rotations.euler_to_rotmat(angles, order="ZYX", degrees=True)
q = rotations.rotmat_to_quat(R)
aa = rotations.quat_to_euler(q, order="ZYX", degrees=True)
# Quaternion SLERP interpolation
q_mid = rotations.quat_slerp(q1, q2, t=0.5)
Visualization
from pybvh import plot
# Plot a single frame
plot.plot_frame(bvh, frame=0)
# Create an animation video
plot.plot_animation(bvh, output_path="walk.mp4")
Pandas Integration
import pandas as pd
# BVH to DataFrame
df = pd.DataFrame(bvh.get_df_constructor(mode="euler"))
# DataFrame back to BVH
from pybvh import df_to_bvh
bvh_from_df = df_to_bvh(bvh.hierarchy_info_as_dict(), df)
Tutorials
The repository includes Jupyter notebooks with detailed walkthroughs:
- Introduction to pybvh — reading, writing, and basic operations
- Spatial coordinates — forward kinematics and 3D positions
- Rotations — rotation representations and conversions
Requirements
- Python >= 3.9
- NumPy >= 1.21
- Matplotlib >= 3.7
Pandas is optional (pip install "pybvh[pandas]") - only used in the tutorials, not part of pybvh library.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pybvh-0.3.0.tar.gz.
File metadata
- Download URL: pybvh-0.3.0.tar.gz
- Upload date:
- Size: 40.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d1f23facfd2345e49babe8b0126e033c786faf452e37f8a89da29558c8abeb4
|
|
| MD5 |
d5aafc2f249dff4f8c79aeaee289959a
|
|
| BLAKE2b-256 |
e24ac156a1415a77103e0ed3ba8ed69486d331b505b033e378ee9582c48d99cc
|
Provenance
The following attestation bundles were made for pybvh-0.3.0.tar.gz:
Publisher:
publish.yml on VictorS-67/pybvh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybvh-0.3.0.tar.gz -
Subject digest:
9d1f23facfd2345e49babe8b0126e033c786faf452e37f8a89da29558c8abeb4 - Sigstore transparency entry: 1196603365
- Sigstore integration time:
-
Permalink:
VictorS-67/pybvh@56271d08f3227ef7b57fedbca997a95c988ec5f1 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/VictorS-67
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@56271d08f3227ef7b57fedbca997a95c988ec5f1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pybvh-0.3.0-py3-none-any.whl.
File metadata
- Download URL: pybvh-0.3.0-py3-none-any.whl
- Upload date:
- Size: 42.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
869803c3d8c6e9091c04bedb7150d5b4765abc15f5fca31cb98af0d0ac7842ee
|
|
| MD5 |
c32cd0cc92ec088dcffcf76b5d21b186
|
|
| BLAKE2b-256 |
f78aea8aca840231cd3cd1dc48f6660d6480ca6d8b8f227281fc27e6eb38e0e8
|
Provenance
The following attestation bundles were made for pybvh-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on VictorS-67/pybvh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybvh-0.3.0-py3-none-any.whl -
Subject digest:
869803c3d8c6e9091c04bedb7150d5b4765abc15f5fca31cb98af0d0ac7842ee - Sigstore transparency entry: 1196603456
- Sigstore integration time:
-
Permalink:
VictorS-67/pybvh@56271d08f3227ef7b57fedbca997a95c988ec5f1 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/VictorS-67
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@56271d08f3227ef7b57fedbca997a95c988ec5f1 -
Trigger Event:
release
-
Statement type: