Monday, March 2, 2015

Record Screen as Animated GIF in Ubuntu with Byzanz

http://www.maketecheasier.com/record-screen-as-animated-gif-ubuntu

We have previously shown you how to record your screen as an animated GIF in Windows and Mac OS X, but what about Linux? If you are a Linux user and are looking for ways to record your screen as an animated GIF, byzanz is the app for you.
Byzanz is a simple command line tool to record a running X desktop to an animation suitable for presentation in a web browser, which in this case, refers to an animated GIF. While the support and development stopped years ago, the current version is still working well on Ubuntu 14.10.
For Ubuntu 14.04 and above, Byzanz is available in the Universe Repository. To install, simply search for it in Ubuntu Software Center,or use the command:
sudo apt-get install byzanz
For Fedora, you can use the command:
sudo yum install byzanz
The command to use Byzanz is byzanz-record. To get started, open a terminal and type:
byzanz-record -d DURATION --delay=DELAY -x X-COORDINATE -y Y-COORDINATE -w WIDTH -h HEIGHT FILENAME
The texts in uppercase are the options that you need to change. Change the DURATION to the length of time to record the animation. The DELAY option is optional, and when set will delay for the specified time before the recording starts. The X-COORDINATE and Y-COORDINATE refer to the location on the screen for it to start capturing and the WIDTH and HEIGHT is the size of the recording. For example, to record the whole desktop for 10 seconds with a 5 second delay, use the command:
byzanz-record -d 10 --delay=5 -x 0 -y 0 -w 1440 -h 900 desktop-animation.gif
byzanz-record
Note: you can add the -v flag to get it to display the progress of the recording.
By default, you will need to specify the coordinates of the recording area and the width and height for byzanz to work. Won’t it be great if there is a GUI tool that you can use to record a window? Thanks to user Rob W and MHC on AskUbuntu, here is the bash script that you can use as a GUI for Byzanz.
Open a text editor and paste the following code to it:
#!/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"
Save the script as “byzanz-gui” (or any other name that you prefer) to your Home folder without any extension.
Next, grant the script executable permission:
chmod +x byzanz-gui
Lastly, execute the script:
./byzanz-gui
In the window that pops up, enter the duration for the recording and click OK.
byzanz-window-gui-specify-duration
You will notice that your mouse cursor has become a crosshair. Click on the window that you want to record. It will start the recording with a 10 second delay.
byzanz-window-gui-recording
You can find the animated GIF in your Pictures folder.
There is also another script that allows you to capture a region instead of a window. However, for that to work, it requires xrectsel which you have to download, compile and install manually. For that, we won’t cover the script in this tutorial.
Byzanz is not the only tool that can record your screen as an animated GIF, but it is one that can do the job well. While it doesn’t come with a beautiful user interface like other screen recording tools for Windows and Mac, being a command line tool gives it the benefit of customizability and can be easily extended with simple bash script.

No comments:

Post a Comment