Recording games with FFmpeg

Here you can see youtube or twitch videos of Warzone 2100 games.

Recording games with FFmpeg

Postby Forgon » 05 Mar 2017, 16:18

This tutorial is written for ArchLinux, but also useful for other operating systems.

0. To record Warzone2100's sound and listen to it at the same time, reconfigure Alsa.
Follow the tutorial at https://trac.ffmpeg.org/wiki/Capture/ALSA#Recordaudiofromanapplicationwhilealsoroutingtheaudiotoanoutputdevice and replace '<Your Output Device Name>' with the simple name of your card, e.g. 'Intel' or its number (typically '0') for ~/.asoundrc as suggested there. If unsure, check the output of `arecord -L`.

1. OpenAL does not default to Alsa. To change that, run `mkdir /etc/openal; echo drivers=alsa > alsoft.conf`.

2. When recording, mind the tradeoff between encoding quality and speed. Either framerate or bitrate should be given.

I chose 40fps with lossless encoding and a free container format:

`ffmpeg -video_size 1280x800 -framerate 40 -f x11grab -i $DISPLAY -f alsa -ac 2 -ar 44100 -i loopout -c:a flac -c:v libx264 -qp 0 -preset ultrafast game.mkv`

3. The process may be killed with 'SIGINT' or 'SIGTERM', e.g. when runinng `ffmpeg [...] & sleep 30; warzone2100 --debug=all`.

4. You can also limit the size of your output file, e.g. with `-fs 500M game.mkv`.

5. Trim and split the video as needed. To remove the first 30s and last 15s in a video of 25 minutes, run:

`ffmpeg -i game.mkv -ss 30 -to 24:45 -vcodec libx264 -qp 0 -acodec flac ingame.mkv`

Reencode! Do not copy input streams with `-c copy` or the equivalent `-acodec copy -vcodec copy` since this corrupts the output file.

6. Codec compression is useful for lossless codecs. I saved ~30% filesize with:

`ffmpeg -i game.mkv -vcodec libx264 -qp 0 -preset veryslow -acodec flac -compression_level 12 game_upload.mkv`

7. Consider process imaging to safeguard against power outage if FFmpeg takes a long time, e.g. with dmtcp or cryopid.

8. Check your files, e.g. with `ffprobe -hide_banner game.mkv`.

9. Extract frames and store them as images.

Take a screenshot in the middle of the 30th second 800px large:
`ffmpeg -i game.mkv -ss 30.5 -vframes 1 -vf scale=800:800 screenshot.png`

Create a list of thumbnails to chose from, e.g. for YouTube:
`ffmpeg -i game.mkv -vf 'select=gt(scene\,0.5)' -vsync vfr -vframes 3 thumbnail_%03d.png`

10. For further help read man pages, visit https://trac.ffmpeg.org or join Freenode's #ffmpeg channel.
Forgon
Greenhorn
 
Posts: 6
Joined: 07 Dec 2016, 22:23

Re: Recording games with FFmpeg

Postby NoQ » 06 Mar 2017, 00:01

Yay thanks.

Historical thread on the topic: viewtopic.php?f=3&t=6521&p=90944#p90944
User avatar
NoQ
Special
Special
 
Posts: 6031
Joined: 24 Dec 2009, 11:35
Location: /var/zone


Return to Gameplay streams & videos