#!/bin/bash

echo 'click on the window you want to capture, I need to get its size !'
INFO=(`xwininfo |grep -oEe 'Absolute upper-left X:  [0-9]+|Absolute upper-left Y:  [0-9]+|Width: [0-9]+|Height: [0-9]+'|awk '{if($4=="") {print $2} else {print $4};}'`)

# ffmpeg need a odd size so let's do some math ;)
if [ $(( ${INFO[2]} % 2 )) -ne 0 ]
then
        INFO[2]=$(( ${INFO[2]} + 1 ))
fi
if [ $(( ${INFO[3]} % 2 )) -ne 0 ]
then
        INFO[3]=$(( ${INFO[3]} + 1 ))
fi

`ffmpeg -f x11grab -r 30 -s ${INFO[2]}x${INFO[3]} -i :0.0+${INFO[0]},${INFO[1]} -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 output1.mkv`