BVH (BioVision Hierarchy) motion capture files parser for DuckDB.
BVH files store skeletal animation data in a hierarchical structure with relative coordinates. This extension parses BVH files and calculates absolute world positions for all joints, making motion capture data easily queryable in DuckDB.
INSTALL bvh2sql FROM community;
LOAD bvh2sql;-- Read BVH file and get absolute positions
SELECT frame_id, time, joint_name, world_x, world_y, world_z
FROM bvh_absolute_positions('motion.bvh')
LIMIT 10;-- Calculate Hips movement distance between frames
SELECT
time,
world_x AS "Hips.x",
world_z AS "Hips.z",
SQRT(
POWER(world_x - LAG(world_x) OVER (ORDER BY time), 2) +
POWER(world_z - LAG(world_z) OVER (ORDER BY time), 2)
) as distance_moved
FROM bvh_absolute_positions('motion.bvh')
WHERE joint_name = 'Hips'
LIMIT 20;-- Export all positions to CSV
COPY (
SELECT * FROM bvh_absolute_positions('motion.bvh')
) TO 'output_pos.csv' (HEADER, DELIMITER ',');Defines the skeletal structure:
- ROOT: Root segment name (usually "Hips")
- OFFSET: X, Y, Z offset from parent joint
- CHANNELS: Number and types of channels
- Root typically has 6 channels (3 position + 3 rotation)
- Other joints have 3 channels (rotation only)
- JOINT: Child joint definition
- End Site: Terminal node (end of bone chain)
Contains frame-by-frame animation data:
- Frames: Total number of frames
- Frame Time: Time interval between frames (seconds)
- Frame data rows with channel values
| Column | Type | Description |
|---|---|---|
| frame_id | INTEGER | Frame number (0-indexed) |
| time | DOUBLE | Time in seconds |
| joint_name | VARCHAR | Name of the joint |
| world_x | DOUBLE | Absolute X position in world space |
| world_y | DOUBLE | Absolute Y position in world space |
| world_z | DOUBLE | Absolute Z position in world space |
| rot_x | DOUBLE | X-axis rotation (degrees) |
| rot_y | DOUBLE | Y-axis rotation (degrees) |
| rot_z | DOUBLE | Z-axis rotation (degrees) |
BVH files store joint positions as relative offsets from parent joints. This extension:
- Parses the hierarchical structure
- Reads motion data frame by frame
- Calculates absolute world positions using 4x4 transformation matrices
- Applies translations and rotations in the order declared by each joint's BVH
CHANNELS - Returns data as a standard SQL table
MIT License
``