Universal screen capturing with scrot, imagemagick and ffmpeg

2013-01-23
#ffmpeg #bash #scrot

You can record your screen using only command line in Linux. Workflow will look like: Create a bunch of screenshots -> Crop screenshots -> Make a movie from images.

§ Making screenshots

scrot is command line screen capturing tool. It’s basic usage is very simple:

$ scrot

or

$ scrot <filename>.png

if you want to specify output filename.

Let’s write script, which captures screen every 0.5 seconds and write result to screenshots/00000N.png (filename with leading zeros):

#!/bin/bash

t=0

while true; do
    scrot screenshots/`printf "%06g\n" $t`.png
    sleep 0.5
    t=`expr $t + 1`
done

exit 0

§ Cropping screenshots

We will use magrify utility from ImageMagick package:

$ for file in $(ls); do mogrify -crop <width>x<height>+<x_shift>+<y_shift> ${file}; done

You can determine width, height, x_shift, y_shift values by adjusting rectangular selection tool in GIMP or in any image viewer.

§ Creating movie from images

We will use ffmpeg for it. Here is command:

ffmpeg -qscale 1 -r 20 -b 9600 -i %06d.png <output_file>.mp4

ffmpeg is no longer supported in Ubuntu 14.04, you may use avconv:

avconv -qscale 1 -r 20 -b 9600 -i %06d.png <output_file>.mp4