Automatically record video from the demo file

I have a demo file (say test.dem) and I need to be able to turn this demo into video automatically, without any human intervention.

Why do I need it: I want to create an automatic generator of “machinima” videos. E.g. I replace certain game models (players, npcs), then I playback demo and record a video. So I get different video with different characters every time. And it needs to be automatic.

The closest thing I’ve accomplished so far:

  1. Create autoexec.cfg in cfg directory and automatically start a map:

map d2_coast_01

  1. Create autorun.lua client script in garrysmod\lua\autorun\client with the following code:

local function onTimer()
    if (!engine.IsPlayingDemo()) then RunConsoleCommand("gm_video"); end
    timer.Simple(0.1, onTimer);
timer.Simple(0.1, onTimer)

RunConsoleCommand("playdemo", "test");

If I do this and start the game, it automatically loads level, starts recording new video and starts demo playback.
It almost works! However my timer is ignored, seems like when I start demo playback all my timers and hooks are deleted :frowning:
So what I need on top of that:

  1. Stop video recording when demo playback ends (now it does not end and starts to record menu forever)
  2. Ideally I want to quit the game when video recording ends.

Please help me! Is there a way to run lua code during demo playback, setup hooks and timers? I can’t figure it out.

Ok, I managed to do it by hacking “gm_demo_to_video” console command. It works now!