Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a script to record windowed games with ffmpeg.

This is what I have so far:


INFO=$(xwininfo -frame)

WIN_GEO=$(echo $INFO | grep -oEe 'geometry [0-9]+x[0-9]+' | grep -oEe '[0-9]+x[0-9]+')
WIN_XY=$(echo $INFO | grep -oEe 'Corners:\s+\+[0-9]+\+[0-9]+' | grep -oEe '[0-9]+\+[0-9]+' | sed -e 's/+/,/' )

ffmpeg -f x11grab -y -r 60 -s $WIN_GEO -i :0.0+$WIN_XY -f alsa -i pulse -crf 18 -preset ultrafast -threads 8 -async 5000 $1.mkv

It allows me to click on a window and record it - it works, but has some issues:

  • I manually have to redirect the game audio with pavucontrol to be able to record it
  • Audio gets out of sync, I tried many options with no luck
  • I can't find a way to record both game audio and microphone audio


  • Could the script be improved somehow for better quality/performance?
  • How can I prevent the audio going out of sync?
  • How can I record both game video, game audio and microphone audio at the same time?
share|improve this question

You must log in to answer this question.

Browse other questions tagged .