Grab that screen!

Updated today: Sunday, September 4, 2011
Reason: I’ve altered a few tidbits here and there in the script, with the result of providing a better picture/end result but at the cost of a slightly increased filesize. For example: an hour of footage, this depends on the amount of fast moving objects, is equivalent to say: 1GB, not bad when one considers a ‘ripped’ DVD with an approx bitrate of 1400kb/s to be of size: ~ 1.5GB. Fwiw I record my desktop in “HD ready” (1280×720) quality now. 😉


There are times one wants to do a bit more than simply make a screenshot of one’s desktop. This is either to just prove a point or simply for the fun of it. Which can be done like so on afaik both windows and G(nu)/linux, Just press: (alt)+PrtSc and tada a picture of your desktop resides on your clipboard. Now in windows with the lack of a decent photo-editor (I’m not counting ‘paint’ here. :lol:) or while you perhaps use a stripped down version of windows at work? One then simply opens up a word doc or if ‘paint’ is present open that instead. Hit ‘paste (ctrl+v), use the save as to give your ‘screenshot’ a name, that’s all there’s to it. 😉 Use it with ‘alt’ for the current window and on its own for the whole desktop.

But since I am not on windows. I instead work with a rather flexible system that comes with a lot of interesting {features,goodies} in its default state; such as ‘gnome-screenshot‘. Therefore, I can do the following.

For the current window:

gnome-screenshot -b -w -d 2 -e shadow

For a selected region:

gnome-screenshot --area

And probably a whole lot more: man gnome-screenshot

Post production of any shot made this way and if needed!? I do with the ‘Gimp

No offense intended towards the following program!!! gtk-recordMyDesktop because in a lot of ways it is far more advanced than what I am about to show ye! Especially when it concerns choosing a region to record. My dislike has more to do with the theora (video) codec than it has to do with the program!

Its alternative and hence the reason for this quick post is simply to grab one’s screen: Howto.

  • Advantages!? A much smaller file size than when using aforementioned program. Quick to set up as an ‘add to panel’ {app,script}. More choices in regards to the used codecs and the container one wants to wrap {his,her} clip in.
  • Disadvantage(s): No sound but that can easily be dubbed in after. Also the “mandatory post editing” out of any unwanted shots such as filling in sudo prompts or at the end where I’ve to close the calling terminal. But can fairly easy be ‘fixed’ by running ‘‘ right after! 😉

OK, so here is the script:

# Modified: Today by E.L.F.
## Licensed as:
## Script-name -
set -e
#. "$HOME"/.bash_functions
## - How to screencast properly.
if [ "$USER" = root ];then echo -e "\tError: \""$USER"\" isn't allowed to use this script!";exit 0
else echo -e "\t${USER} may proceed.\n\tMay peace be with you.\n";fi
Color_Test=$(grep -i '\\033\[' "$HOME"/.bashrc)
if [ -n "$Color_Test" ];then echo -e ${Magenta}"\tOk, colors are defined."${Nc}
Nc="\033[0m" # No Color
echo -e ${White}"\tThey weren't, but now they are."${Nc}
## Monitor operates at 60hz.
echo -n "Enter name for output file: "
read Output
## The following line makes certain you can type a 'normal' sentence as filename.
## All this without 'violating' UNIX' restriction on spaces.
## I.e. 'This is my recording' becomes ''
Output=$(echo "$Output" |sed -e 's_ _._g')
## Change to a foldername of your convenience.
[ ! -d "$WD" ] && mkdir "$WD"
## Now you can press either 'minimize' or 'alt+f9' in my case
## To get the terminal out of your way.
## You have 2 seconds to do so.
sleep 2
## Adjust '-s 1366x716' to fit your purposes, same goes for this ':0.0+0,25'
ffmpeg -y -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1366x768 -i :0.0 \
-acodec pcm_s16le -alang eng \
-vcodec libx264 -vpre ultrafast -crf 18 -threads 0 -vlang eng \
-metadata title=$(basename "$Output" .mkv) \
-metadata artist="$USER" \
-metadata date="$(date +"%A, %B %-d, %Y")" \
-metadata publisher="$(echo "What is in a name anyway.")" \ # Change me.
-metadata copyright="$(echo "Attribution 3.0 Unported (CC BY 3.0)")" \ # Change me.
## '-s hd720' change this to suit your purposes.
-s hd720 "$WD"/"$OUTPUT"
exit 0

An example screen-recording (used the previous script that I had posted up here before.) can be seen here [Yes an 720p (HD ready) version is also available. 🙂 ]:

I have been fine-tuning my screen-recording capabilities, so be ready to get bored, quickly. 😉
But at least now I know how to grab only the portion of the screen I want and provide you with a saner resolution. 😉

An example with mpeg4 encoding. (21.1MB)

Seems OK with me and is the one I used with this script.

An example with x264 encoding. (51.0MB)

Smoother picture, but somewhat troublesome with faster moving pictures and larger than life filesize (approx 3GB for an whole hour!).

Enjoy and profit!?

PS: Time used aside from whatever it is you’re trying to record for pre and post production? No more then a few minutes of your time on a fairly modern computer. 😉

One thought on “Grab that screen!

Comments are closed.