menu_bookDocumentation
Video - s&box Media Documentation
Video
s&box can decode and play video files for cutscenes, UI elements, or in-world displays.
VideoPlayer
The VideoPlayer decodes video and exposes frames as a Texture:
| Codec | Containers | Notes |
|---|---|---|
| VP9 | .webm, .mp4 | Good compatibility |
| AV1 | .webm, .mp4 | Best compression |
| WebP | .webp | Supports transparency |
| H.264 | .mp4 | Windows only |
CSHARP
var player = new VideoPlayer();
player.OnLoaded += () => Log.Info( $"Loaded {player.Width}x{player.Height}" );
player.Play( FileSystem.Mounted, "videos/intro.webm" );Streaming
Stream from URLs:
CSHARP
player.Play( "https://example.com/stream.webm" );Using the Texture
VideoPlayer.Texture updates each frame:CSHARP
// UI panel background
panel.Style.SetBackgroundImage( player.Texture );
// Material texture
material.Set( "Texture", player.Texture );Audio
Audio settings on the Audio accessor:
CSHARP
player.Audio.Volume = 0.5f;
player.Audio.Position = WorldPosition;
player.Audio.TargetMixer = Mixer.FindMixerByName( "Music" );VideoWriter
Record gameplay to video:
CSHARP
var writer = new VideoWriter();
writer.Open( "output.webm", width, height );
// Each frame
writer.WriteFrame( renderTexture );
// Finish
writer.Close();Performance
- Video decoding is hardware-accelerated when possible
- Large videos can impact frame time
- Consider resolution vs quality tradeoff
Was this helpful?