HOWTO: Time-lapse capture your Linux desktop

OR: Playing with my scrot

I’ve been playing with my scrot relentlessly for the past two or three days. Literally non-stop for hours a time. I’ve even been making videos and then putting those videos on YouTube.

/innuendo

Scrot – SCReen shOT – is a FOSS screen capture utility that cleaves to the old Unix philosophy: It does one thing and does it very well indeed. And that is take screenshots. So get your freaking mind out of the gutter, dear reader(s).

It’s cool, I can wait.

Done? Great.

Scrot is something I’ve used for my screen capturing since 2003 or so, and while I’ve previously bowed to scrot’s scripting prowess, it has only been in the last four days that I’ve discovered another fun use for scrot: Simple, lite (resource-wise) time-lapse capture of my desktop. You can do it at home with just scrot and mplayer.

HOWTO:

 

  1. Get scrot and mplayer on your system if you don’t already have them. Under Ubuntu, conveniently, it is:

         apt-get install scrot mplayer

  2. Type or copy and paste this command into the terminal while in the folder where you would like to capture the images

    while [ 1 ]; do scrot -q 100 $(date +%Y%m%d%H%M%S).jpg; sleep 1; done

    gives you an unending loop. Scrot will literally loop taking screensots until you finally decide to kill the program. As a quick rule of thumb, you need between 900 and 1,200 still images per minute of footage (60 seconds@15 FPS=900; 60 seconds@20 FPS=1,200). This does seem like a whole lot of still images, but at ~300 stills per 10 minutes, you’ll generate (300x6) 1,800 per hour.
    So about two hours of recording will net you a video that will go along very nicely to your average song track.

  3. Make a list for mencoder to read:

         ls -1tr *.jpg > files.txt

    Simple, eh?

  4. Stitch together your still images with mencoder. While I noted my own preferences aloud yesterday, you really are free to look at mencoder’s options – and I freely encourage you to do this. So far as I can gather, mencoder can do anything you ask of it…if you know the correct account.
    Encoding your video as-is (video raw, like still raw) is great for quality, but takes up a respectable chunk of hard-disk space. I settled on encoding with h.264 because it gave me a great balance of file-size and quality. Your frames per second in the video matter for two reasons: 1. Controlling video length (for fitting it to a soundtrack), and 2. controlling playback speed. Do you want events to whizz past, or be slower and more followable?

    mencoder -ovc x264 -oac mp3lame -audiofile basket_case.mp3 -mf w=1400:h=900:fps=20:type=jpg 'mf://@files.txt' -o screenlapse.avi

    I strongly encourage you to look up documentation on mencoder (such as here) so you can experiment and determine a solution that best fits your own needs.

And that’s it. For your pleasure, here’s one I made earlier:

7 Comments:

Randy

Commented Monday May 30, 2011 at 00:18

Just a stupid question, but what do I use for the [mark][screenlapse] brackets? if I just copy and paste those lines into terminal I get this:

“[mark][screenlapse]: command not found”

Thanks in advance.

Mark

Commented Monday May 30, 2011 at 11:26

Whoops, sorry Randy. You are seeing my Bash prompt there (PS1="[u][W] # ") as well. You just need to go with this:

while [ 1 ]; do scrot -q 100 $(date +%Y%m%d%H%M%S).jpg; sleep 1; done

I’ve updated the original post to correct this. :)

Randy

Commented Tuesday May 31, 2011 at 03:55

All right, just one more thing, this line didn’t work-
ls -1tr *.jpg > files.txt
-kept getting gt: command not found errors

I changed it to ” ls -1tr *.jpg > files.txt ” and got working results.

Also, to everyone using this script, cd to a empty, disposable directory first, as it is a very messy script.

Mark

Commented Tuesday May 31, 2011 at 13:22

Sorry again Randy, I have that fixed too. This post was imported from my old Tumblr blog, and formatting was pretty fecked by the conversion. I’ve been quashing little things like this since the move. What literally snuck into that command was a right bracket HTML symbol.

I’m glad you weren’t using my camera-import script or I would probably be responsible for your hard disk catching fire. :)

I ran through and double-checked the other commands. In order:

  1. Create a directory:

    mdkdir Screenlapse && cd Screenlapse

  2. Run this for as long as you want it/need it. Ctrl+c to cancel.

    while [ 1 ]; do scrot -q 100 $(date +%Y%m%d%H%M%S).jpg; sleep 1; done

  3. Your next step is to list all of the images and dump them into a folder:

    ls -1tr *.jpg > files.txt

  4. Your final step is to compile all of this (along with a suitable .mp3 soundtrack into a video. Make sure the music file (underlined) exists at the path specified:

    mencoder -ovc x264 -oac mp3lame -audiofile ./basket_case.mp3 -mf w=1400:h=900:fps=20:type=jpg 'mf://@files.txt' -o screenlapse.avi

Mike Henke

Commented Monday May 27, 2013 at 23:50

mencoder $(ls -t *.jpg | tac | awk ‘{ print “mf://” $1; }’) -mf fps=4 -o test.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800

Brandon

Commented Thursday May 30, 2013 at 19:18

Curious as I got this to work fine, but I am not that savvy with the coding. What would the code be to make a screen capture to happen every 30 seconds or so?

Mark

Commented Friday May 31, 2013 at 07:09

sleep is an in-build shell command that sleeps for n seconds. sleep 1, sleep for one second. sleep 5, sleep for five seconds.

Change n as needed.

Say something witty:

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>