Alien Arena Official Forums
In-game recorder for alien arena - Printable Version

+- Alien Arena Official Forums (http://red.planetarena.org/forum)
+-- Forum: Community (http://red.planetarena.org/forum/forumdisplay.php?fid=1)
+--- Forum: General Discussion (http://red.planetarena.org/forum/forumdisplay.php?fid=2)
+--- Thread: In-game recorder for alien arena (/showthread.php?tid=2220)



In-game recorder for alien arena - Benau - 04-13-2017

Hi!

It's been a long time since my play in alien arena, but I never forget about about the old times, so now I decide to come back with some interesting idea as in the topic.

Recently I have tried to implement a in-game recorder for supertuxkart, and it was a success. Than I tried a more ambitious plan which is to separate the code for it out of supertuxkart. The result is here:
https://github.com/Benau/libopenglrecorder
This is a c++11 library with exposed API "extern C-ed" and bsd licensing, which allowing a very wide usage for everybody.

Currently it builds fine in my linux, for windows I think you will need at least msvc2013.
The prebuilt binaries are here (see windows folder), the dlls are built with static runtime
library, so I think it should work without msvc2015 runtime:
https://github.com/supertuxkart/dependencies/tree/master
Just copy suitable dll / lib / include there.

Than I tried to hack alien arena next, first include openglrecorder.h in both files:
in r_main.c int R_Init( void *hinstance, void *hWnd ):
Quote: (around line 1708) R_GenerateShadowFBO();
Com_DPrintf("%s : %d\n", __FILE__, __LINE__ );

RecorderConfig cfg;
cfg.m_triple_buffering = 1;
cfg.m_record_audio = 1;
cfg.m_width = 1920;
cfg.m_height = 1080;
cfg.m_video_format = OGR_VF_VP8;
cfg.m_audio_format = OGR_AF_VORBIS;
cfg.m_audio_bitrate = 112000;
cfg.m_video_bitrate = 200000;
cfg.m_record_fps = 30;
cfg.m_record_jpg_quality = 90;
ogrInitConfig(&cfg);
ogrRegReadPixelsFunction(qglReadPixels);
ogrRegPBOFunctions(qglGenBuffersARB, qglBindBufferARB, qglBufferDataARB,
qglDeleteBuffersARB, qglMapBufferARB, qglUnmapBufferARB);
ogrSetSavedName("record");
You may adjust the settings above as name implies (see openglrecorder.h for details), use OGR_VF_MJPEG will allow abetter quality, though the video will be large.
The sounding record in linux is done by pulseaudio while windows is wasapi
Notice: In windows you may need a function to wrap againist qgl* function, as some of it may have a __stdcall supplied, this is true for glew in windows which supertuxkart uses.

You can check https://github.com/Benau/libopenglrecorder/blob/master/USAGE.md in my repo for details.

Then in cl_main.c:2679 near the end of "if ( render_trigger )" (I assume this is the last rendering command?) add this: (of course the static int is a quick hack!)
Quote:static int prepared = 0;
if (prepared == 0)
{
prepared = 1;
ogrPrepareCapture();
}
ogrCapture();

Finally in r_main.c R_Shutdown, add an ogrDestroy(); for clean up when exit.

Then alien arena will record its rendering context, which ogrCapture() will grab the current frame asynchronously if you enabled m_triple_buffering, until you exit the game. It's a c++11 library, so unique_ptr I used will auto-delete and join the recording threads. Finally a "record.mkv / .webm" will be formed in the current running directory.

In my testing audio / video sync is very good, also libopenglrecorder will auto duplicate / discard frame so as to fits your m_record_fps.

You can see how I did for supertuxkart with complete features / callbacks here:
https://github.com/supertuxkart/stk-code/blob/libopenglrecorder/src/graphics/irr_driver.cpp
Search for all the functions about "ogrXXX"

Interesting idea? Though I don't know how input / output handling is done in alienarena, so a user can press a button to start / stop record....

BTW a not-sure-if bug...
In glw_imp.c Sys_SetCpuCore Method, you seem to always SetProcessAffinityMask to 1 (sys_affinity->value is always 1), at least in my task manager crx.exe always uses only 1 core of all CPUs, is it intended? At least for vp8 live encoding I need to comment out those code to utilize all cores without affecting the gameplay.


RE: In-game recorder for alien arena - [SiN]bAnfire - 04-13-2017

So, for a noob like me, reading this, you are saying that this can record the game
directly to a video output?
Instead of the need capturing it afterwards with e.g. Fraps?

Are there any requirements on the pc specs for this to work fluently?

What is the fps?
What quality output do you get? 1080?


RE: In-game recorder for alien arena - Benau - 04-13-2017

Directly to a webm or mkv with sound, no more additional work

fps is the m_record_fps you specified, quality will be the best if you use OGR_VF_MJPEG which will be an mjpeg mkv + vorbis audio, which no encoding happening in the background, and this is suitable for slow pc. (vorbis encoding is low-cpu-usage so doesn't matter). if you specified cfg.m_width = 1920; cfg.m_height = 1080;, than the output video will be at 1920x1080 with 30fps.

For on-the-fly VP8 encoding, you need at least a dual-core CPU with ~3.0ghz, and you can adjust the video bitrate if you want higher VP8 quality (H264 not done yet)

I have tried the above hacks in Alien Arena, and I successfully recorded a video + audio file in both windows / linux after exiting Alien Arena.