Skip to content

Instantly share code, notes, and snippets.

@FabianPastor
Last active October 27, 2016 21:08
Show Gist options
  • Save FabianPastor/2aef7071f7c25adb000094a3c99a2fb3 to your computer and use it in GitHub Desktop.
Save FabianPastor/2aef7071f7c25adb000094a3c99a2fb3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Get the coordinates of the active window's
# top-left corner, and the window's size.
# This excludes the window decoration.
unset x y w h
eval $(xwininfo |
sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
-e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
-e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
-e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )
#echo -n "$x $y $w $h"
if [ ! -f ./capture.sh ]
then
echo "Creating capture.sh"
echo '#!/bin/bash' > capture.sh
echo 'w=$1 && h=$2 && x=$3 && y=$4 && name=$5' >> capture.sh
echo 'size=${1}x$2 && pos="$x,$y"' >> capture.sh
echo 'if [ ! $(( $w % 2 )) -eq 0 ]; then ((w++)); fi #Nos aseguramos que la salida es par -_-' >> capture.sh
echo 'read -n1 -r -p "Press any key to continue..." key' >> capture.sh
echo 'ffmpeg -f x11grab -s $size -framerate 30 -i :0.0+$pos -vf scale="$w:-2" -pix_fmt yuv420p -preset slow -crf 25 -an $name.mp4' >> capture.sh
echo 'read -n1 -r -p "Press any key to continue..." key' >> capture.sh
chmod +x ./capture.sh
fi
xterm -e "./capture.sh $w $h $x $y Record"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment