Adventure Game Studio | Forums

AGS Support => Advanced Technical Forum => Topic started by: Scavenger on 12 Jun 2012, 17:40

Title: Advice on Writing a Plugin (FFMPEG?)
Post by: Scavenger on 12 Jun 2012, 17:40
I'm back in the saddle after making my animated film, and one thing that I'm missing from my game is full motion video. I'm a competent animator, and I can work my way around after effects, so producing animated cutscenes is no problem. However, as my game is in 8bit and not 16bit (a deliberate choice, a lot of effects in my game depend on it being 8bit - and besides, I've created a load of assets anyway so switching to 16bit is not an attractive option.) I can't use the built in PlayVideo command, and using FLC files will lead to my game's size being bloated up beyond any measure and be difficult to sync a soundtrack to. There is another option for me, but it involves the deadly black arts of plugins. I've done a small amount of C++ in the past, and I've written a simple plugin before (to use mikmod instead of DUMB for MOD music, mikmod had bugs in it that stopped individual channels from being manipulated, though, so I didn't continue it.).

The only robust and documented 8bit video codec out there is Smacker, which fortunately for me has an FFMPEG codec. I am a little intimidated trying to write another plugin, though, as my programming prowess has always been really weak. The main thing is getting everything linked together and compiling, rather than the code itself. I'm aware, from reading a couple of tutorials on the matter, that it can be abstracted down a bit and the frame processing can be placed in AGS_PRERENDER (instead of a while loop, like the tutorial says), while the frame itself could probably be either blitted directly to the screen or onto a dynamic sprite. It would be interesting to have a Smacker file play overlaid on the background, so that there is the illusion that the smacker video /is/ the background. I intend to reinstall VC++ and meddle around with this anyway, but if anyone can give me any advice on getting FFMPEG working within the context of AGS, I'd love to hear it. I always get confused around the static linking stage. With Mikmod I just used an external DLL instead, but that doesn't seem too elegant.

As an aside, does anyone know how much faster processing a sprite with GetRawBitMapSurface () is than a GetPixel/PutPixel loop? A few of the graphical effects in my game are depressingly slow with GP/PP, as they rely on checking the pixels directly each loop, which cuts the FPS while they're on screen by about half - something I don't want to happen. If I could open it up a bit so that a sprite can be referenced as an array rather than through AGS the effects should go much, much faster. I'm not sure why that functionality isn't inside AGS itself, but hey, c'est la vie. If I can get that working, I can make effects in my game almost cost-free!
Title: Re: Advice on Writing a Plugin (FFMPEG?)
Post by: Kweepa on 12 Jun 2012, 22:15
Processing a sprite from a plugin is about 50 times faster than using scripting, so you don't need to worry about speed. This reflects the difference in speed of scripting vs C++, rather than any particular slowness of GetPixel() which is not significantly slower than any other native script function or operation.

I can't give any specific advice about AGS 3.x plugins. I will say that the workflow with 2.x was much smoother.
Title: Re: Advice on Writing a Plugin (FFMPEG?)
Post by: Monsieur OUXX on 13 Jun 2012, 12:17
I have 3 recommendations :
1) Read this: Help Workshop You said you're more concerned about linking than coding, but it's a good start. In particular, check the comment about "Multi-threaded" projects.
2) Keep in mind the following tricks:
   - Static linking (as opposed to dynamic linking) is the best way to be sure that all required DLLs and components are integrated in the final result.
   - You can try to compile your stuff with minGw rather than VisualC++. It will remove dependencies on Microsoft stuff, and might save you the trouble of having to tell people to install the "Microsoft Visual C++ 20xx Redistributable Package" in order to use your plugin. It's not very easy, though, like always when it comes to compiling with plenty of dependencies. someone has done that, though, search it on the forums.
   - If I recall there is a plugin that allows you to code your engine plugins in C# rather than C++ (just sayin', in case you don't like C++).

3) Try to get some help from the people who made video plugins. In particular, check out the "theora" plugin and the "Direct 3D 1.0" plugin (here (, that render the video onto a surface, and make it easier to display it on-screen.

PS: I have another idea: there is an engine plugin that allows you to run c# functions directly from within your game. If your FFMPEG/Smasher library already exists out there in the big wild world, then maybe you could just call the rendering of your video from within your game using a c# instruction to do a a system call, directly to the DLL. I don't know if it could work but it's worth investigating.