ffmpegで直接X11をgrabする

ffmpegが直接X Windowエンコードできることが分かったので、それ用のスクリプト

fps = 4

str = `xwininfo`
x = {}
x[:x] = str.match(/^  Absolute upper-left X:  (\d+)/)[1].to_i
x[:y] = str.match(/^  Absolute upper-left Y:  (\d+)/)[1].to_i
x[:width] = str.match(/^  Width: (\d+)/)[1].to_i
x[:height] = str.match(/^  Height: (\d+)/)[1].to_i

system(
  "ffmpeg -y -r #{fps} -f x11grab -s %dx%d -i :0.0+%d,%d -r #{fps} out.flv" %
  [ x[:width], x[:height], x[:x], x[:y] ])