Skip to content

Instantly share code, notes, and snippets.

@intfrr
Forked from nihal111/byzanz-record-window.sh
Last active July 15, 2019 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intfrr/8ba078d620483ac3e3bd5a0b7d033893 to your computer and use it in GitHub Desktop.
Save intfrr/8ba078d620483ac3e3bd5a0b7d033893 to your computer and use it in GitHub Desktop.
A script to ease usage of byzanz, a tool for recording GIFs in Linux.
#!/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)
# Byzanz Gif Maker
#
# Byzanz is an awesome tool for recording GIFs on Linux. It is light and gives an output directly to a gif file. The colors go off often, but the small file size makes up for it.
#
### Installing
# (From [this AskUbuntu answer](http://askubuntu.com/questions/107726/how-to-create-animated-gif-images-of-a-screencast#answer-123515))
#
#### 11.10 to 13.10
#
#Unfortunately support has been dropped and you can no longer find any packages for Ubuntu that wont break your system and have missing unsatisfiable dependencies.
#
#Fortunately Debian still maintains the package for Sid and the GIT repository still exists.
#
#If you want to go ahead and install the .deb file from Sid (works in Ubuntu 11.10, just tested, no warranties!), download it from the Debian packages page and install it with sudo dpkg -i.
#
#Also, one of our esteemed moderators has ported the Debian package to a PPA making it easier to install, you can add it to your system and install Byzanz by opening a terminal and typing
#
# sudo add-apt-repository ppa:fossfreedom/byzanz
# sudo apt-get update && sudo apt-get install byzanz
#
### 14.04 and above
#
#Byzanz is now available from the universe repository
#
# sudo apt-get install byzanz
#
#
## Usage
#
#Usage directly from the package requires a lot of parameters and argument typing in the terminal. However, a great fellow went ahead and made a script to make it easy and added GUI features to it.
#
#(From [this AskUbuntu answer](http://askubuntu.com/questions/107726/how-to-create-animated-gif-images-of-a-screencast#answer-201018))
#
#+ Add [this script](https://gist.github.com/intfrr/8ba078d620483ac3e3bd5a0b7d033893) to the $PATH of your Linux (`/usr/bin/` would work).
#+ Save the script as `byzanz-record-window` and run `sudo chmod +x byzanz-record-window` inside that directory to grant execution permission to the script.
#+ Run the script from the terminal as easily as calling out `byzanz-record-window`.
#+ You can change the delay and other default values by editing the script.
# Time and date
TIME=$(date +"%Y-%m-%d_%H%M%S")
# Delay before starting
DELAY=5
# 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"
# Send to gyazo
gyazo $FOLDER/GIFrecord_$TIME.gif
# Send to imgur
# https://github.com/intfrr/imgur.sh
imgur $FOLDER/GIFrecord_$TIME.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment