An experimental library aiming to make video playback in MonoGame possible.
👉 Bug fixes and feature requests are more than welcome!
✔️ - This platform/version is supported and tested
⚡ - This platform/version is untested, but, theoretically, should work.
❌ - This platform/version is unsupported. I might add support for it later.
Platform | Status |
---|---|
DesktopGL (Windows) | ✔️ |
WindowsDX (Windows) | ❌ |
DesktopGL (Linux) | ⚡ |
DesktopGL (MacOS) | ⚡ |
Version | Status |
---|---|
.NET 9.0 (Preview) | ⚡ |
.NET 8.0 | ✔️ |
.NET 7.0 | ❌ |
.NET 6.0 | ❌ |
- Download or compile FFmpeg, which is a required component to stream your video into raw format.
Place the
ffmpeg
executable somewhere near your game. (ffprobe
andffplay
are not needed!).
Development tests and examples use pre-compiledffmpeg_essentials_build
byGyanD
: Latest version
If you choose to compile FFmpeg yourself, make sure to include the
rawvideo
codec andrgba
pixel format.
- Set the path to your
ffmpeg
executable:
You must do this before creating any
Video
instance!
Video.SetFFmpegExecutablePath(Path.Combine("lib", "ffmpeg.exe"));
- Create a
Video
instance and provide the path to your video and an instance of the graphics device:
var myVideo = new Video(Path.Combine("Content", "video.mp4"), _graphics.GraphicsDevice);
- Start the video playback. This will also load the metadata if you haven't done so already (see Optimization):
myVideo.Play();
- Update the video and draw the current frame:
protected override void Update(GameTime gameTime)
{
myVideo.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
_spriteBatch.Begin();
if (videoPlayer.CurrentFrame is not null) // Check whether the video is playing, or you'll get a null texture!
_spriteBatch.Draw(myVideo.CurrentFrame, Vector2.Zero, Color.White);
_spriteBatch.End();
}
And that's it! Your video is now streaming from the disk!
👉 Also check out the minimal example!
Loading the video is divided into two steps:
- Loading metadata
- Playing (streaming) the video
By default, you can simply call Play()
and the library will handle all the steps for you. However, it's important to note that loading metadata might be expensive. It is recommended to load the metadata without starting the playback in the LoadContent()
method:
protected override void LoadContent()
{
video.LoadMetadata();
}
Do note that metadata only has to be loaded once; it is never changed during the lifetime of the Video
object.
This library still has a long way to go before becoming a feature-complete library. Please note that the plans listed below are placed in no particular order.
- Audio support (top priority)
- Streamed audio support
- Async loading and decoding
- Looping the video
- Direct rendering using shader
-
Seek functionality(presumably impossible to implement due to streaming) - Playback error handling