It bothered me that recording Steam games required editing the launch options every session. Here's what I've come up with:
Dir.mkdir '/tmp/ssr/' unless File.exists?( '/tmp/ssr/' )
ssr = IO.popen( 'simplescreenrecorder 2>&1' )
while line = ssr.gets
if line =~ /SSR_GLINJECT_SHM=(\d+)/
IO.write( '/tmp/ssr/glinject-shm', $1 )
File.delete( '/tmp/ssr/glinject-shm' )
This starts SSR in a wrapper that watches its output for the SHM line, writes its value to a temp file, then deletes that file when the program terminates.
if File.exists?( '/tmp/ssr/glinject-shm' )
ENV['LD_PRELOAD'] = 'libssr-glinject.so'
ENV['SSR_GLINJECT_SHM'] = `cat /tmp/ssr/glinject-shm`
exec( ARGV )
This checks whether the file created by the above wrapper exists and adds the environment variables iff SSR is ready to record.
Using these, I can set all my steam games to permanently launch as ssr-glplay '%command%', and the script takes care of hooking up with SSR (or not, if it isn't running).
Is it feasible to roll this functionality into the main application? I'd like to just launch all my games with the LD_PRELOAD line all the time, and let libssr-glinject.so look for the glinject-shm file itself to decide whether to run.
And keeping in mind that I have no idea how this works, would it also be possible to do this the other way around, having the .so write to glinject-shm and wait for SSR to pick it up? This will allow players to start SSR at any time while the game's running if they decide to record something.
There's a simpler way to get the SSR_GLINJECT_SHM value from SSR: put the command in the 'command' field. The script will continue to run even if SSR is stopped, so it should also watch for its parent process to disappear so it can delete the file and stop itself. The advantage is that you don't have to parse the output of SimpleScreenRecorder anymore.
Currently the libssr-glinject library won't be able to start when there is no valid SSR_GLINJECT_SHM to attach to. This could be changed, but it will introduce some overhead (I would have to check some file periodically so the library can attach when SSR appears). It's a bit complicated because the library would have to know when SSR disappears as well (or when SSR is used to record in non-OpenGL modes, or when multiple instances of SSR are used at the same time).
I could also change the approach completely so the system doesn't rely on SHM ids anymore. I could use a memory-mapped file in /dev/shm instead, but I'm not sure whether all distributions provide this directory (it should be tmpfs to make this work). I'm also not entirely sure whether this is equivalent to using normal shared memory.
And as you suggested, I can indeed reverse the roles and let the game create the shared memory. This has some other advantages as well. It makes support for multiple windows or multiple processes at the same time easier. It also makes it possible to change recording settings without restarting the game.
Something like the scripts you created should be good enough for now, but this could be improved in the future.
would this work with xubuntu 12.04.3? i notice it's using Ruby, do i have to install ruby from the default repositories? where do i store ssr-glrecord and ssr-glplay and who should own them and what permissions do they need?
i am looking to incorporate this because i don't know what steam games or any games for the matter use opengl, i just want to be able to start ssr, open my game, click record and not have to worry about whether the game is opengl or not and i certainly don't want to edit the launch command for every steam game before i launch it and then have to remove the command. i'd like to just add ssr-glplay '%command%' thing to all my steam games and be done with it.
Awesome software by the way. I used it for the first time this morning to record Steam game Serious Sam 3 BFE, it recorded my voice and the game because i setup loopbacks and a null-sink and told ssr to record the null-sink. End video turned out great, just need to adjust my audio levels next time using pavucontrol. it's my latest upload if you want to see it. http://www.youtube.com/ubuntuaddicted
Pretty much any serious game is using OpenGL. But OpenGL recording isn't perfect yet, and I've heard that it doesn't work with some games.
To use these scripts you will have to install ruby as you guessed, and then you have to put the scripts somewhere in your PATH. For Ubuntu, the simplest way to do this is to create a directory called 'bin' in your home folder and put the scripts in there (owned by you), make them executable (chmod +x filename), and then log out and log in again so it will detect the 'bin' folder (this happens by default in the .profile file I think).
Just a heads-up to anyone who may want to use these scripts: they disable Steam overlay in games, because it also uses LD_PRELOAD. To allow both OpenGL recording in SSR and Steam overlay to work together, change this line in ssr-glplay from:
ENV['LD_PRELOAD'] = 'libssr-glinject.so'
ENV['LD_PRELOAD'] = ENV['LD_PRELOAD'] + ' libssr-glinject.so'
Does that actually work? My experience is that it crashes the game on launch because the two interfere ...
It does. I managed to play and record some footage with the overlay.