Skip to main content
GameDev.net gamedev.net
🔒 Locked

Playing Video Files(.avi, .mpg, .mp4) Platform Independently

Started by jonnys Feb 23, 2007 at 9:06 PM 5 replies 2.2k views
Original Post
jonnys
jonnys
Does anybody know anyway to play video files platform independently? I've looked everywhere and cant find any examples. I really want to put intro videos (like the ones in commercial games), so any thought/opinion/help would be appreciated. Thanks
Arelaith
Arelaith
If you want to implement them, you could use a state class, to run through what ever videos, main menus, etc. Whether its directX or ogl, a state machine could work?
KreK
KreK
You'll need a decoding library for those media files. A great one is FFmpeg, it's open source and LGPL (with a few caveats). Though it carries 'mpeg' in its name, it actually supports all popular formats and quite a few obscure ones.

The FFmpeg is just a C API so you'll need to write your own decoding system, which usually involves setting up a few threads, one to collect packets from media files, another one which does decoding and yet another one which converts decoded frames from video formats to texture friendly RGB format and does the updating of dynamic textures in your 3D scene.
jonnys
jonnys
Quote:
Original post by KreK
You'll need a decoding library for those media files. A great one is FFmpeg, it's open source and LGPL (with a few caveats). Though it carries 'mpeg' in its name, it actually supports all popular formats and quite a few obscure ones.

The FFmpeg is just a C API so you'll need to write your own decoding system, which usually involves setting up a few threads, one to collect packets from media files, another one which does decoding and yet another one which converts decoded frames from video formats to texture friendly RGB format and does the updating of dynamic textures in your 3D scene.


Thanks for the info, but you know anywhere I can find sample code that uses this decoding system?

Ravuya
Ravuya
I believe the SMPEG library is open-source and cross-platform; it's based around SDL.

FFMPEG has a pile of stuff too, but I haven't had a chance to use it and so can't advocate it either way.
KreK
KreK
I just took a peek at SMPEG, but the library seems to be dated, goes back to the beginning of millennium. That's not necessary a bad thing, but you have to wonder about using something that is not actively being developed. FFmpeg is a library in constant progress, they don't even offer binaries to download, you have to checkout the latest version via Subversion client.

You must realize that FFmpeg is a rather low-level API. There is no such function as play_me_some_video_on_this_window( hWnd, videofile ). You have to implement that function yourself and this means you need to be familiar with 3D API (if you are going to apply videos to textures on your scenes), sound API (OpenAL or DirectSound) and threading.

Here's the list of FFmpeg supported media formats:

http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html#SEC21


Because FFmpeg is being developed on GCC compiler and uses some things from C99 standard, getting it to work under MS compilers is a bit tricky, but there's a very detailed tutorial on how to set it up:

http://arrozcru.no-ip.org/ffmpeg/

Be sure to check out the 'FFmpeg on Windows Wiki' as it will guide you step by step on compiling the library. Once you get the libs, read this for the introduction tutorial:

http://www.inb.uni-luebeck.de/~boehme/using_libavcodec.html

become familiar with FFmpeg API documentation (Doxygen, alas, but what can you do):
http://cekirdek.pardus.org.tr/~ismail/ffmpeg-docs/

and also take a look at "glover" - OpenGL Movie player
http://code.google.com/p/glover/
Excors
Excors
Quote:
Original post by jonnys
Quote:
Original post by KreK
... FFmpeg ...

Thanks for the info, but you know anywhere I can find sample code that uses this decoding system?

The FFmpeg source includes ffplay.c, which plays videos in a window and seems like a sensible place to start.

(I've just used FFmpeg for outputting video files from a game, and got away with copying most of the code from output_example.c, and then it seemed to work reasonably straightforwardly. I used the pre-built binaries from here, and they worked fine in VS2005 after modifying common.h to not rely on inttypes.h.)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.