I'm looking for a video encoding library in C++ that I can use to record game footage.

It can not be an external application like Fraps, it must be a library.

Ideally the encoding can be done in real time without affecting game performance too much, although this is not a must have requirement.

Another preference is that the video file being saved from the game is already compressed and ready to be used by most video players without any further processing. I realize that this might not be possible especially for real time encoding, so I would accept a trade off of having to process the file later for better compression and/or better file format.

I'd like to hear about your experience integrating the library into a game if possible and any interesting trade offs you had to make.

Some libraries support more that one file format or codec, so advice on the file format would also be appreciated.

  • \$\begingroup\$ Questions on what library to use are off-topic on GDSE, I hear, as the responses will be overly broad, mostly subject to opinions, and peppered with thinly veiled advertisements. You may be able to rephrase your question to avoid this problem. \$\endgroup\$ – Lars Viklund Dec 1 '14 at 12:33

It depends on the use-case.

For recording games, I've seen that a general 'game record' mode where the game records the user input on a timeline so as to be able to recreate the game at any point to be really useful, and you can generate the video afterwards, or pass around these recorded games and others can watch using the game engine rather than a video player.

Or maybe you mean in-game capture that immediately converts to a video live and stores only the video. Assuming so:

The classic library is ffmpeg's libavcodec. You can compile this so it as to avoid GPL codecs and such.

Codecs like H.264 (libx264) are GPL - if that's ok with you, then fast presets and baseline profiles will work better than most. H.263 or even MJPEG otherwise.

But I normally stream y4m (its trivial to generate this format yourself without using the GPL lib) to an ffmpeg exe using my popen3. Why don't you want an external exe? Its a tidy way of allowing it to run on separate cores and coping with the fact that it may take longer to compress your video than it the game time it represents.

I have also concatentated to MJPEG using libjpeg internally and post-converted with FFMPEG.

And finally I have made live FLV streams so games could be watched live. This is surprisingly easy.

| improve this answer | |
