menu_bookDocumentation
Video: VideoPlayer Decoding and VideoWriter Encoding with Streaming Support
s&box provides VideoPlayer for decoding video and VideoWriter for encoding video frames.
VideoPlayer
Decodes video files or URLs, exposing the current frame as a Texture.Supported codecs: VP9 (.webm/.mp4), AV1 (.webm/.mp4, best quality), 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" );
// HTTP streaming
player.Play( "https://example.com/stream.webm" );
// Use the texture anywhere
panel.Style.SetBackgroundImage( player.Texture );
material.Set( "Texture", player.Texture );
// Audio control
player.Audio.Volume = 0.5f;
player.Audio.Position = WorldPosition;
player.Audio.TargetMixer = Mixer.FindMixerByName( "Music" );VideoWriter
Encodes RGBA frames into video files. Supports VP9, AV1, and animated WebP with transparency.CSHARP
var writer = new VideoWriter( "recordings/output.mp4", new VideoWriter.Config
{
Width = 1920, Height = 1080,
FrameRate = 60, Bitrate = 14,
Codec = VideoWriter.Codec.AV1,
Preset = VideoWriter.EncodingPreset.Fast,
AudioCodec = VideoWriter.AudioCodec.Opus,
} );
writer.AddFrame( rgbaBytes );
await writer.FinishAsync();EncodingPreset options: Fast (real-time), Balanced (general), Quality (offline export).
Was this helpful?