ffmpeg-screencaster is a basic script to make screencasts with the simple yet excellent FFmpeg command-line software. It’s features are:
- support for multi-headed display
- support for specific video geometry
- uses xrandr to (sort of) detect screen geometry
If you have more screens, you might need to adjust it.
#!/bin/bash
vp=$2
dest=$1
if [ -n ${dest} ]
then
dest=`date +%Y%m%d_%H%M%S`.mp4
echo "Using default filename: ${dest}"
fi
setViewport() {
case "${!1}" in
'') viewport=`xrandr -q | head -1 | cut -f 2 -d ','`
width=`echo $viewport | cut -f 2 -d ' '`
height=`echo $viewport | cut -f 4 -d ' '`
echo "Using default ${width}x${height} video size"
viewport=${width}x${height};;
0) vp=`xrandr -q | grep DisplayPort-0 | cut -f 4 -d ' '`
viewport=`echo ${vp} | cut -f 1 -d '+'`
pos_x=`echo ${vp} | cut -f 2 -d '+'`
pos_y=`echo ${vp} | cut -f 3 -d '+'`
echo "Using screen 0 ${viewport} +${pos_x}+${pos_y}";;
1) vp=`xrandr -q | grep DisplayPort-1 | cut -f 3 -d ' '`
viewport=`echo ${vp} | cut -f 1 -d '+'`
pos_x=`echo ${vp} | cut -f 2 -d '+'`
pos_y=`echo ${vp} | cut -f 3 -d '+'`
echo "Using screen 1 ${viewport} +${pos_x}+${pos_y}";;
2) vp=`xrandr -q | grep DisplayPort-2 | cut -f 3 -d ' '`
viewport=`echo ${vp} | cut -f 1 -d '+'`
pos_x=`echo ${vp} | cut -f 2 -d '+'`
pos_y=`echo ${vp} | cut -f 3 -d '+'`
echo "Using screen 2 ${viewport} +${pos_x}+${pos_y}";;
*) vp=${!1}
viewport=`echo ${vp} | cut -f 1 -d '+'`
if [[ $vp == *"+"* ]]; then
pos_x=`echo ${vp} | cut -f 2 -d '+'`
pos_y=`echo ${vp} | cut -f 3 -d '+'`
echo "Video position was explicitly set to +${pos_x}+${pos_y}"
fi
echo "Video size set to an explicit value: ${!1}";;
esac
}
pos_x=0
pos_y=0
setViewport vp
ffmpeg -f x11grab -r 25 -s ${viewport} -i :0.0+${pos_x},${pos_y} -vcodec libx264 ${dest}