It works for both realtime and demo playback. Two ways to record from demo-
1. use "capturedemo" command to record the entire video.
2. bind capture_start and capture_stop to keys. Play the demo normally and use the start/stop keys to record selected segments.

Video Recording commands and cvars:
[+] capture_codec [ code] – A 4-letter code for the desired codec to use. XVID has been tested to work as a high-quality compressed format, others include MPG4 and DIVX. The K-lite codec pack includes a tool to identify available codecs and their codes.

[+] capture_fps [value] – Frames-per-second for video capture.
[+] capture_console [0/1] – Toggle to show the console in video capture output.
[+] capture_hack[value] – Set to a low integer value like 1 or 2 if captured video looks like slow motion. Sometimes it helps.
[+] capture_mp3 [0/1] – Capture audio in mp3 format instead of wav format. Used during video capture.
[+] capture_mp3_kbps[value] – mp3 data rate, used if capture_mp3 is set.
[+] capture_start – Start video capture in real-time. Works during gameplay or during demo playback. Can stop anytime.
[+] capture_stop – Stop video capture. Can restart any time, and will save to a new file.
[+] capturedemo [demoname] – Play back a demo and capture it to video. This is the best way to capture smooth video on most computers.
[+] con_logcenterprint [0/1] – record centerprint messages in demos. Set to 0 for less screen text during playback.