Include video using SDL


Hi, second post here!

Been reading png files in SDL and using them as textures…

Now, would like to include in my game 2 short videos made in Blender, in dvi and mp4 formats.
Is it possible to do so using SDL and how, please?

Thank you! ;-)))


It’s a bit more complex than decoding a PNG and displaying it on the screen. You basically have to decode each frame using a decoder library, and then display each frame of the video to the screen in a timely manner that is similar to what the video is supposed to be playing at. This is a very complex operation that will take a bit of work for you to create.

There are a couple of samples that might help, (you’ll need to swap out the Theora decoding out for the format you want to use): TheoraPlay

Other than that, Google is your friend: sdl2 video player


Thank you very much for your support!

video.cpp here attached plays a mp4 video whose codecs appear below.

Based on, running Windows x64, Visual Studio 2015, SDL2, ffmpeg 4.0 and C++.

Hope it helps!

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘crawl.mp4’:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 1970-01-01T00:00:00.000000Z
Duration: 00:00:29.00, start: 0.000000, bitrate: 689 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1344x680, 612 kb/s, 10 fps, 10 tbr, 10 tbn, 20 tbc (default)
creation_time : 1970-01-01T00:00:00.000000Z
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 75 kb/s (default)
creation_time : 1970-01-01T00:00:00.000000Z
handler_name : SoundHandler
screen final size: 1344x680

video.cpp (19.8 KB)