5

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!

Konstantinos
  • 4,096
  • 3
  • 19
  • 28
  • 1
    have you try with [framebuffer directly](http://stackoverflow.com/questions/1645181/taking-a-screen-shot-of-an-embedded-linux-framebuffer)? – j-p Apr 12 '14 at 00:05
  • This may seem promising. So far I only grab a blank terminal (not the X)... I will update a question/answer as soon as I work this out. Many thanks! – Konstantinos Apr 12 '14 at 00:45

2 Answers2

5

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.

emcconville
  • 23,800
  • 4
  • 50
  • 66
  • Thank you very much for your answer. `xwd` is indeed faster (~37%) compared to `scrot` and returns `real: 0m1.249s, user: 0m0.636s, sys: 0m0.252s`. I will have it in mind for the future. However, I need the `png` files quite immediately. Using `xwd` with `mogrify` together is considerably slower: (real: 0m3.151s, user: 0m2.276s, sys: 0m0.360s). – Konstantinos Apr 14 '14 at 22:38
  • 1
    That sound right. If instant PNG is a requirement, you can roll your own solution with libpng & optimize for speed with LLVM. But that might just shave 5~10% of what you experiencing with scrot. There's alot of examples of low-level GPU encoders out there, but again, the development time my not be worth 0.2s improvement. OpenMP might be the way to go with Imagemagick, see [this answer](http://stackoverflow.com/questions/17659916/imagemagick-only-uses-one-core/17755692#17755692) to use all your CPU cores. – emcconville Apr 15 '14 at 01:38
2

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
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286