Skip to content

Play video on StreamDeck

wischi edited this page Mar 7, 2021 · 4 revisions

This is a short example how to play a video on the StreamDeck.

We use the extension method DrawFullScreenBitmap (from the DrawFullScreen example) to draw frames to StreamDeck and AForge.Video.FFMPEG to decode video frames.

Demo video of the example

There is sill some flickering (for example right after 00:28) but at the moment I'm not exactly sure why.

All you need to do something similar is

  1. StreamDeckSharp (of course) - for example via nuget
  2. DrawFullScreenBitmap extension
  3. And AForge.NET (you can use another video decoder, but IMHO AForge VideoFileReader is one of the simplest)

And a few lines of code to make it work ;-)

static void Main(string[] args)
{
    using (var deck = StreamDeck.FromHID())
    using (VideoFileReader reader = new VideoFileReader())
    {
        reader.Open(@"C:\PathToVideo\vid.mp4");
        var fr = reader.FrameRate;
        var msWait = (int)Math.Round(1.0 / fr);

        while (true)
        {
            using (var frame = reader.ReadVideoFrame())
            {
                if (frame == null) return;
                deck.DrawFullScreenBitmap(frame);
            }
            Thread.Sleep(msWait);
        }
    }
}
Clone this wiki locally