DDNet Live: Twitch spectates an online game2016-01-10 · DDNet · Frugality
Last night I had an idea and implemented it, soo let's see what will happen. But first, the idea:
Have a livestream  of DDNet running non-stop  that always shows some interesting  players on the server.
It's surprisingly simple to livestream from Linux to Twitch. Only FFmpeg is needed:
This works pretty well, but takes quite a bit of CPU on my old computer. So instead I wanted to run it on my new server with a Haswell-era J1900 CPU.
Possible ways to improve performance:
- Use an OpenGL recorder instead of x11grab
- Get Intel Quick Sync Video working for hardware H264 encoding
2. Running Non-Stop
My server is a small and cheap ASRock Q1900-ITX:
The nice part is that it's passively cooled and quite power efficient, drawing only 5 Watts in idle. This machine has been running as my home server for quite some time, but barely gets any action. Let's change that!
The X server starts without problems even without any monitors attached, the only thing that's left to do is increasing the framebuffer size so that our game can run in it:
We don't even need a window manager. After all we just run a single window in exactly the resolution of the framebuffer.
The FFmpeg recording still works in exactly the same way. Unfortunately I couldn't get H264 hardware encoding to work with the J1900 CPU. Related bug reports make me believe it just doesn't work on these cheaper Intel CPUs.
Artificial Intelligence Twitch Control
Now that we have the game running and are streaming it to Twitch, we need to control it somehow. My goal was to find an approach that always shows some interesting players in action, so that you could watch the stream all day and enjoy it.
But finding a reasonable way to do this seems too complicated and I didn't look forward to hacking the DDNet C/C++ source code, so instead I opted to utilize an existing system in DDNet: FIFO command input!
DDNet servers and clients can be remote controlled through a FIFO file. This is very useful to send the same commands to dozens of servers at once. But for the client its use was pretty limited, until now!
Instead of thinking of an algorithm to find interesting players, why not let the Twitch viewers themselves control who they want to watch through the chat?
Right now there is really not much limitation to what you can do. Only a
handful of commands are explicitly blocked, otherwise the client can be
controlled freely and every single chat message is sent to the client. The
client commands and
client settings list the
available commands and settings. Chat
commands can be sent to the
server as well through the
say command. Some examples:
Let's see how this goes. Luckily the Nim script runs independently from the server, so I will be able to make changes to it on the fly. Just be nice and don't cause any trouble, thanks.
Feel free to head over to Twitch, watch the action and control the server using the Twitch chat. Twitch has some delay, so it takes a few seconds for you to see your command executed.