Skip to content

Instantly share code, notes, and snippets.

@pascalchevrel
Created January 17, 2017 12:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pascalchevrel/ac2adcb50de0b63c620a634ddefda944 to your computer and use it in GitHub Desktop.
Save pascalchevrel/ac2adcb50de0b63c620a634ddefda944 to your computer and use it in GitHub Desktop.
A bash script to screencast a window into a Gif with good quality
#! /usr/bin/env bash
# This script uses byzanz-record to generate an animated Gif for your interactions
# with a window
# usage:
# Record a window for 3 seconds and save to /home/foo/yo.gif
# byzanz-record-window 3 /home/foo/yo.gif
#
# without parameters, it defaults to 10s and a target file in /tmp/screencast.gif
#
# Sound notification to let one know when recording is about to start (and ends)
beep() {
paplay /usr/share/sounds/freedesktop/stereo/screen-capture.oga &
}
# Delay before starting
DELAY=3
# Duration
DURATION=10
if [ $# -gt 0 ]; then
DURATION=$1
fi
# File target
TARGET='/tmp/screencast.gif'
if [ $# -gt 1 ]; then
TARGET=$2
fi
echo Recording duration of ${DURATION}s to $TARGET.
echo Click on the window you want to record.
XWININFO=$(xwininfo)
read X <<< $(awk -F: '/Absolute upper-left X/{print $2}' <<< "$XWININFO")
read Y <<< $(awk -F: '/Absolute upper-left Y/{print $2}' <<< "$XWININFO")
read W <<< $(awk -F: '/Width/{print $2}' <<< "$XWININFO")
read H <<< $(awk -F: '/Height/{print $2}' <<< "$XWININFO")
echo Delaying $DELAY seconds. After that, byzanz will start
for (( i=$DELAY; i>0; --i )) ; do
echo $i
sleep 1
done
beep
byzanz-record --verbose --delay=0 --x=$X --y=$Y --width=$W --height=$H --duration=$DURATION $TARGET
beep
notify-send "Screencast created"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment