Playing AVI Files with DirectX
Provides a class for playing AVI files and describes how to use it.
CAviSurface implements an interface to play a true- or high-color AVI file into a DirectDrawSurface. CAviSurfaceWithSound extends this to play the sound simultaneously into a streaming DirectSoundBuffer.
To use the classes you have to use DirectDraw in a 16-Bit or 24-Bit colormodus. 8-Bit Colordepth is currently not supported, neither as sourceformat nor as targetformat. This is partially due to the usually installed AVI - Decompressors and partially due to my own laziness.
To use the class you simply have to use the following codefrags:
- Construct the DirectDraw (and DirectSound) Interface.
- Call the constructor lpAviSurface = new CAviSurface (or CAviSurfaceWithSound)
- To start the playback, call lpAviSurface->Start(); // Sound begins to play when using CAviSurfaceWithSound
- In your general UpdateFrame-Method of the Application call lpAviSurface->BltTo(where.x,where.y,lpddsTargetSurface);
- Call lpAviSurface->Stop() to suspend playback, another call to lpAviSurface->Start() will contiue the playback.
- Destroy the Object with delete lpAviSurface;
CAviSurface(char *lpszFilename,LPDIRECTDRAW lpDDraw,BOOL bLoop=FALSE)
- Constructs a DirectDrawSurface, linked with an AVI-File HRESULT SetColorKey(DWORD dwColorKey)
- Set a Keycolor (no Keyspace) HRESULT BlitTo(int x,int y,LPDIRECTDRAWSURFACE lpddsTarget)
- Draws Videosurface to (left,upper) = (x,y) in Targetsurface HRESULT StretchBlitTo(RECT *rcTarget,LPDIRECTDRAWSURFACE lpddsTarget)
- Draws Videosurface to Targetrectangle in TargetSuface virtual BOOL Start()
- Starts Videoplayback into surface virtual BOOL Stop()
- Stops the playback[hr]
CAviSurfaceWithSound(char *lpszFilename,LPDIRECTDRAW lpDDraw,LPDIRECTSOUND lpDS,BOOL bLoop)
- Opens the AVI-File lpszFilename and attaches it to a Directdrawsurface and a DirectSoundbuffer.
- bLoop specifys, if the AVI-File is played looping. ~CAviSurfaceWithSound()
- Frees all the stuff virtual BOOL Start()
- Starts the soundplay and the videoplayback virtual BOOL Stop()
- Stops the soundplay and the videoplayback For more information see the headerfile "avisurfave.h"
[hr]
Files in the included archive:
- avisurface.cpp, avisurface.h - Implementation of the classes
- dderrmsg.cpp, dderrmsg.h - translates a DDraw errormessage into a text string
- standartmacros.h - exactly one macro (grin)
- videoexample.* MSDEV Projectfiles for the examplecode
- aboutbox.cpp, aboutbox.h - guess what it is
- ddframw.cpp, ddframw.h - the applications main window
- resources.h - the resource defines
- videoexample.exe - release build
- AVISurface.html - this file The sources compile fine under VC++ 4.2, but it should be easy to convert to other compilers. - (Sometimes I will switch back to Borland)
Remember to run the program in an 16 or 24 bit colordepth environment, because it works in a window, and only supports the high/truecolor target.
[hr]
To Do:
- I currently do not know how to interpret the value AVIStreamInfo.dwInitialFrames exactly, so there is a problem in the synchronization of the sound and the graphics in some AVI's.
- Adding support for 8-Bit and 32-Bit Colordepth. (I currently do not need this, so no time to do it)[size="5"] LEGAL ISSUES
I don't promise that this software works and in no case I will be liable to any damage, this software does. (But if you find any bugs, please let me know!) You can use this software for whatever you want. You don't have to pay me. If you use it in a program, please credit me, send a postcard (or a copy of the program).
[email="mam90ccr@rzaix340.rz.uni-leipzig.de"]Gert Wollny[/email]
Henricistr. 29
04177 Leipzig
Germany
- Stops the soundplay and the videoplayback For more information see the headerfile "avisurfave.h"
- Starts the soundplay and the videoplayback virtual BOOL Stop()
- Frees all the stuff virtual BOOL Start()
- bLoop specifys, if the AVI-File is played looping. ~CAviSurfaceWithSound()
- Opens the AVI-File lpszFilename and attaches it to a Directdrawsurface and a DirectSoundbuffer.
- Stops the playback[hr]
- Starts Videoplayback into surface virtual BOOL Stop()
- Draws Videosurface to Targetrectangle in TargetSuface virtual BOOL Start()
- Draws Videosurface to (left,upper) = (x,y) in Targetsurface HRESULT StretchBlitTo(RECT *rcTarget,LPDIRECTDRAWSURFACE lpddsTarget)
- Set a Keycolor (no Keyspace) HRESULT BlitTo(int x,int y,LPDIRECTDRAWSURFACE lpddsTarget)
Related Tutorials
Procedural Generation of 2D Tile Maps in Games
The article explains how to build a procedural 2D cave map generator using cellular automata. It covers map representat…
Localizing A Game Into French — Which Variant Should You Choose?
So, you’re making an awesome indie game, and now you’re thinking about localizing it into French? Great idea! There ar…
How Long Does It Take To Localize An Indie Game?
So you’re planning on localizing your indie game, but you’re not sure how much time to schedule in. While the timing o…
Creating game videos: best practices and pitfalls to avoid
Game video production: practical tips on how to create a game trailer or teaser that you can be proud of. Give your aud…
Adopting CI/CD: How Midwinter Entertainment iterates at speed with the help of IMS
Game development was once like one long sprint: a huge effort until you reached the finish line — at which point you co…
GameDev.net
5 Things to Consider When Making a Video to Promote Your App or Game
How can you show an app or game in your video in a way that attracts new users? Let’s take a look at what to go by when…
Discussion
More from Gert Wollny
Comparing Shadow Mapping Techniques with Shadow Explorer
New Incentives and a Whole New Platform From The Intel AppUp developer program
The final installment in this series on Intel's AppUp program details additional incentives and opportunities for devel…
The Game Maker
This book excerpt contains the first chapter of the book that introduces beginning game developers to the Game Maker pr…
Discussion