DEV Community

Daniel Habib
Daniel Habib

Posted on

Create a Simple Splat Video with spatialstudio

This tutorial assumes you have a basic understanding of Python. If anything is unclear, feel free to ask in the comments below!

Install spatialstudio

pip install spatialstudio
Enter fullscreen mode Exit fullscreen mode

This library offers low‑level utilities that help you easily create splat videos—3D videos you can walk around in. These videos use the .splv file format, short for SPatiaLVideo.

In this guide, we'll build a simple splat video that displays a cube toggling between red and blue every second.

Initialize the encoder (main.py)

from spatialstudio import splv

width, height, depth = 8, 8, 8
encoder = splv.Encoder(
    width,
    height,
    depth,
    framerate=1.0,
    outputPath="color_cube.splv"
)
Enter fullscreen mode Exit fullscreen mode
  • We define the resolution of our 3D video—think of it like going from 1080p to 8p, but in 3D.
  • Then, we create the encoder, which collects frames, compresses them, and writes them to a .splv file. We also specify the framerate here.

Create the frames

frame_total = 300  
red = (255, 0, 0)
blue = (0, 0, 255)

for frame_index in range(frame_total):
    frame = splv.Frame(width, height, depth)
    voxel_color = red if frame_index % 2 == 0 else blue
    frame.set_voxel(4, 4, 4, voxel_color)
    encoder.encode(frame)
Enter fullscreen mode Exit fullscreen mode

Here’s what’s happening:

  1. frame_total: Total number of frames we’ll generate.
  2. red and blue: RGB tuples defining the colors.
  3. Inside the loop:
  • We create an empty Frame (3D grid).
  • Pick red or blue depending on whether the frame index is even or odd.
  • Set a single voxel at (4, 4, 4) to that color.
  • Encode the frame with encoder.encode(frame).

You’re free to populate more voxels per frame as desired!

Finish encoding and write to disk

encoder.finish()
Enter fullscreen mode Exit fullscreen mode

This final step tells the encoder to compress all collected frames and write the .splv file. You’ll end up with color_cube.splv in your working directory.

Preview your splv file

Use the free browser‑based preview tool—no login required:
https://splats.com/preview

If you run into issues, drop a comment below or hop into our Discord!

Can’t wait to see your 3D creations—share them on the subreddit or Discord!

Full code

from spatialstudio import splv

width, height, depth = 8, 8, 8
encoder = splv.Encoder(width, height, depth, framerate=1.0, outputPath="color_cube.splv")

frame_total = 300  
red = (255, 0, 0)
blue = (0, 0, 255)

for frame_index in range(frame_total):
    frame = splv.Frame(width, height, depth)
    voxel_color = red if frame_index % 2 == 0 else blue
    frame.set_voxel(4, 4, 4, voxel_color)
    encoder.encode(frame)

encoder.finish()

print(f"Created color-changing voxel animation: color_cube.splv")
Enter fullscreen mode Exit fullscreen mode

Formatting Notes for dev.to

  • Posts on dev.to use Jekyll front matter, enclosed in triple dashes (---) at the top (dev.to).
  • Use fenced code blocks with three backticks, and specify the language (like python or bash) for syntax highlighting (docs.github.com).
  • Including a blank line before and after code blocks helps readability (docs.github.com).

Let me know if you'd like to adjust anything or add visuals, diagrams, or links!

Top comments (0)