Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest image capture for screenshot command line tool

I am trying to find the fastest possible way to take fullscreen consecutive screenshots in GNU/linux without any human intervention. So far I get:

$ time for i in {1..10}; do import -window root test-$i.png; done
real    0m9.742s
user    0m11.324s
sys     0m0.584s

$ time for i in {1..10}; do scrot test-$i.png; done
real    0m1.686s
user    0m1.528s
sys     0m0.060s

However, I would like something even faster than scrot. The system times have been taken in a decent (hardware-wise) desktop PC (running Ubuntu Linux). The funny thing is that it hosts a kvm machine (CrunchBang Linux) that returns:

$ time for i in {1..10}; do import -window root test-$i.png; done
real    0m7.591s
user    0m6.096s
sys     0m0.196s

$ time for i in {1..10}; do scrot test-$i.png; done
real    0m2.921s
user    0m2.440s
sys     0m0.120s

Hence, ImageMagick is faster but scrot slower!?! Hard Disk I/O doesn't seem to influence speed since I get almost identical timings.

What do you recommend for dramatically (or less dramatically) improving speed?

Thank you!

like image 943
Konstantinos Avatar asked Apr 11 '14 23:04

Konstantinos


2 Answers

The times your experiencing are probably influenced by transcoding the screen-image into a friendly PNG, or JPEG, format. Just use X's xwd (X dump display utility) to, literally, dump the screen from RAM to disk. Only convert the raw XWD files to another format when your ready to view/process them.

# Capture
time for i in {1..10}; do xwd -root -silent -out test-$i.xwd; done

# When ready to view
 mogrify -format PNG -path ./pngs test-*.xwd

You can even speed up the xwd process by only dumping a specific window; which, can be calculation beforehand.

like image 56
emcconville Avatar answered Nov 14 '22 20:11

emcconville


In my case I found scrot with jpeg compression the fastest:

time scrot test.jpg 
scrot test.jpg  0.05s user 0.01s system 72% cpu 0.084 total
time xwd -root -silent -out test.xwd
xwd -root -silent -out test.xwd  0.18s user 0.05s system 88% cpu 0.252 total
like image 34
Chris Stryczynski Avatar answered Nov 14 '22 20:11

Chris Stryczynski