Skip to content

Instantly share code, notes, and snippets.

@felipemfp
Created August 19, 2016 10:02
Show Gist options
  • Save felipemfp/35a852c4517e6b7c90f1e1460a3e41b3 to your computer and use it in GitHub Desktop.
Save felipemfp/35a852c4517e6b7c90f1e1460a3e41b3 to your computer and use it in GitHub Desktop.

Usage

Save one/all of the following two scripts in a folder within your $PATH. Here's an example on using the first script to make a screencast of a specific window.

  1. Run byzanz-record-window 30 -c output.gif
  2. Go to the window (alt-tab) you want to capture. Click on it.
  3. Wait 10 seconds (hard-coded in $DELAY), in which you prepare for recording.
  4. After the beep (defined in the beep function), byzanz will start.
  5. After 30 seconds (that's the meaning of 30 in step 1), byzanz ends. A beep will be broadcast again.
  6. I included the -c flag in byzanz-record-window to illustrate that any arguments to my shell script are appended to byzanz-record itself. The -c flag tells byzanz to also icnlude the cursor in the screencast.

How to create animated GIF images of a screencast?

#!/bin/bash
# AUTHOR: (c) Rob W 2012, modified by MHC (http://askubuntu.com/users/81372/mhc)
# NAME: GIFRecord 0.1
# DESCRIPTION: A script to record GIF screencasts.
# LICENSE: GNU GPL v3 (http://www.gnu.org/licenses/gpl.html)
# DEPENDENCIES: byzanz,gdialog,notify-send (install via sudo add-apt-repository ppa:fossfreedom/byzanz; sudo apt-get update && sudo apt-get install byzanz gdialog notify-osd)
# Time and date
TIME=$(date +"%Y-%m-%d_%H%M%S")
# Delay before starting
DELAY=10
# Standard screencast folder
FOLDER="$HOME/Pictures"
# Default recording duration
DEFDUR=10
# Sound notification to let one know when recording is about to start (and ends)
beep() {
paplay /usr/share/sounds/freedesktop/stereo/message-new-instant.oga &
}
# Custom recording duration as set by user
USERDUR=$(gdialog --title "Duration?" --inputbox "Please enter the screencast duration in seconds" 200 100 2>&1)
# Duration and output file
if [ $USERDUR -gt 0 ]; then
D=$USERDUR
else
D=$DEFDUR
fi
# Window geometry
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")
# Notify the user of recording time and delay
notify-send "GIFRecorder" "Recording duration set to $D seconds. Recording will start in $DELAY seconds."
#Actual recording
sleep $DELAY
beep
byzanz-record -c --verbose --delay=0 --duration=$D --x=$X --y=$Y --width=$W --height=$H "$FOLDER/GIFrecord_$TIME.gif"
beep
# Notify the user of end of recording.
notify-send "GIFRecorder" "Screencast saved to $FOLDER/GIFrecord_$TIME.gif"
#!/bin/bash
# Delay before starting
DELAY=10
# Sound notification to let one know when recording is about to start (and ends)
beep() {
paplay /usr/share/sounds/KDE-Im-Irc-Event.ogg &
}
# Duration and output file
if [ $# -gt 0 ]; then
D="--duration=$@"
else
echo Default recording duration 10s to /tmp/recorded.gif
D="--duration=10 /tmp/recorded.gif"
fi
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 $D
beep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment