Skip to content

An experimental library aiming to make video playback in MonoGame possible.

License

Notifications You must be signed in to change notification settings

NonRelative/MonoVideo

Repository files navigation

MonoVideo

An experimental library aiming to make video playback in MonoGame possible.

🚧 Project status

Abandoned as June 2024

⚠️ This library is currently in Alpha! Expect breaking changes and bugs in any release!
👉 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

Basic Usage

  1. 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 and ffplay are not needed!).
    Development tests and examples use pre-compiled ffmpeg_essentials_build by GyanD: Latest version

If you choose to compile FFmpeg yourself, make sure to include the rawvideo codec and rgba pixel format.

  1. Set the path to your ffmpeg executable:

You must do this before creating any Video instance!

Video.SetFFmpegExecutablePath(Path.Combine("lib", "ffmpeg.exe"));
  1. 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);
  1. Start the video playback. This will also load the metadata if you haven't done so already (see Optimization):
myVideo.Play();
  1. 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!

Optimization

Loading the video is divided into two steps:

  1. Loading metadata
  2. 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.

Where's the sound?

Audio playback will be implemented in one of the future updates! (Approximate date: 2024-05-01)

Future Plans

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

About

An experimental library aiming to make video playback in MonoGame possible.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages