Page 1 of 1

import temporarilly stalls

Posted: 2013-05-19T07:00:24-07:00
by MagnusE
Dear ImageMagick users & developers,

I am using ImageMagick to import whole desktop screenshots in some of my bash scripts in order to take action when certain "visual patterns" appear on screen. I actually monitor a fullscreen window that runs a video. While importing the desktop there are freezes of the screen and mouse movement and in-window graphics/video movement is quit erratic. I guess this happens when import runs after each new iteration.

Could you please tell me if I can somehow prevent them ?

Example script:

Code: Select all

#!/bin/bash
while true
do
# sleep 1s -> it also happens when there is 1s (or more) sleep between each iteration, although at proportionally longer intervals
import -window root -crop 400x200+400+950 "screenshot.png"  && visgrep_pattern=$( visgrep -t 1000 "screenshot.png" "pattern.pat" "pattern.pat"  | sed "s/,/ /g" | cut -d' ' -f 1 ) ;
[[ "${visgrep_pattern}" != "" ]] && echo 'Pattern found'
done
Thank you very much in advance...


PS: System information:

Code: Select all

$ uname -a
Linux hostname 3.8.0-21-generic #32-Ubuntu SMP Tue May 14 16:16:16 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
$ import --version
Version: ImageMagick 6.7.7-10 2013-02-25 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=13.04
DISTRIB_CODENAME=raring
DISTRIB_DESCRIPTION="Ubuntu 13.04"


Re: import temporarilly stalls

Posted: 2013-05-19T07:39:03-07:00
by magick
Try -screen.

Re: import temporarilly stalls

Posted: 2013-05-19T09:56:48-07:00
by MagnusE
Thank you for your reply, magick.

"-screen" demands me having to click the "cross" in order to take the screenshot.

To illustrate the problem, while watching a flash video in a browser, using import to take 100 subsequent screenshot makes the video motion erratic. This is not happening with e.g. scrot. Furthermore, scrot seems to be quite faster (in taking screenshots)...

Code: Select all

$ time for i in {1..100}; do import -window root -crop 400x200+400+950 screenshot_with_imagemagick.png; done
real    0m55.304s                                                                                                                     
user    0m56.692s                                                                                                                     
sys     0m5.132s          

$ time for i in {1..100}; do scrot screenshot_with_scrot.png && convert -crop 400x200+400+950 screenshot_with_scrot.png{,}; done
real    0m25.704s
user    0m22.580s
sys     0m1.904s
Thank you very much again.

Re: import temporarilly stalls

Posted: 2013-05-19T10:01:22-07:00
by magick
You need -window root -screen.

Re: import temporarilly stalls

Posted: 2013-05-19T12:07:50-07:00
by MagnusE
Dear magick,

using -window -root -screen I have less frequent "pauses" in video playback of the underlying window, but it takes a lot longer to complete the iterations of 100 consecutive screenshots, so the total number of pauses is larger.

Specifically,
  • with import -window -root -screen I counted 93 small pauses with user and system time 1m30.180s and 0m4.088s respectively,
  • with import -window -root I counted 74 small pauses with user and system time 0m47.888s and 0m3.764s respectively, and
  • with scrot there were no pauses at all!, with user and system time 0m22.504s and 0m1.708s respectively.
So I guess I will use scrot for the specific script,...

After all the greatness of ImageMagick is not worth spending in taking screenshots. :D

Thanks again. ;)