Capturing game footage with FFmpeg in Ubuntu

It’s surprisingly easier than I expected. I’d previously thought FFmpeg was so complicated that I looked everywhere else for a decent video capture tool in Linux.

I found the following explanation at qubodup’s blog. And he, in turn, found the tutorial from a much larger blog post.

  1. Start the game/open the window you want to record (I expect it should be windowed for the following instructions to make sense).
  2. In a terminal, enter ‘xwininfo’ and then click on the window you will be recording.
  3. You’ll see a bunch of information pop up in the window.
    1. If you want to capture window decorations, also make note of the values in -geometry at the bottom. (width, height, upper-left X, upper-left Y)
    2. If you want to capture only the window contents, make note of Width, Height, Absolute upper-left X, Absolute upper-left Y.
  4. In a terminal, type/paste the following

    ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s WIDTHxHEIGHT -i :0.0+XPOSITION,YPOSITION -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.mkv

  5. Replace the capitals with the values you noted previously.
  6. Press enter to begin recording. When done, press Ctrl-C in the terminal.
  7. In a terminal, type the following to encode the video

    ffmpeg -i output.mkv -acodec libmp3lame -ab 128k -ac 2 -vcodec libx264 -vpre hq -crf 22 -threads 0 our-final-product.mp4

I’ve yet to get the audio to record properly, but at least the video records flawlessly.

One Response to “Capturing game footage with FFmpeg in Ubuntu”

  1. Jose Damian says:

    Great! I’ve got the same issue with the audio, but the video records flawlessly. Thanks for the great job!

Leave a Reply


Staypressed theme by Themocracy