Imagemagick significantly slow(er) screen grab

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Sepero
Posts: 1
Joined: 2012-04-10T06:41:48-07:00
Authentication code: 8675308

Imagemagick significantly slow(er) screen grab

Post by Sepero »

I was using imagemagick to capture screenshots in a program of mine, but I've since switched to using scrot because for some reason it appears nearly 5-10 times faster on average. I don't know if imagemagick can be improved in this way or not, but when taking 1 shot per second, it really adds up. I understand that scrot is a simpler program, so I expect it to a degree, but this large of a time difference?

I created a script to compare the time speeds of both programs taking a simple full screenshot. (script listed at end of post)

Code: Select all

./timetrial.sh
Simple Capture Times
Magick                        Scrot
real    0m0.774s              real    0m0.184s
real    0m0.863s              real    0m0.107s
real    0m0.603s              real    0m0.098s
real    0m0.688s              real    0m0.102s
real    0m0.840s              real    0m0.112s
real    0m0.850s              real    0m0.098s
real    0m0.873s              real    0m0.097s
real    0m0.860s              real    0m0.099s
real    0m0.849s              real    0m0.105s
real    0m0.564s              real    0m0.098s

In other testing with capture and resize, there appears to be almost no performance boost for running imagemagick in a single command verses 2 commands. (Which makes scrot faster, even if we need to resize later with image magick)

Code: Select all

import -window root -resize 75% test.jpg
VS

Code: Select all

import -window root test.jpg&& convert test.jpg -resize 75% test.jpg

Imagemagick and scrot are both written in C, so perhaps some middle ground could be met? If the time issue is based on cross platform compatibility, perhaps a .config file could be created once imagemagick knows what type of system it's on??

This was the script used to compare times:

Code: Select all

#!/usr/bin/env bash
# timetrial.sh

function capturemagick {
  import -window root test.jpg
}

function capturescrot {
  scrot test.jpg
}

LOOP=10
SCROTTIME=""
MAGICKTIME=""
echo "Simple Capture Times"
echo "Magick                        Scrot"
for i in $(seq $LOOP)
do
  MAGICKTIME=$((time (capturemagick) 2>&1) | grep "real")
  SCROTTIME=$((time (capturescrot) 2>&1) | grep "real")
  echo "$MAGICKTIME              $SCROTTIME"
done
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Imagemagick significantly slow(er) screen grab

Post by magick »

Chances are scrot reads directly from the frame buffer, whereas ImageMagick reads the screen through the X11 API for cross-platform compatibility. We are not inclined to write code specific to the Linux framebuffer so in this case we recommend scrot if your requirements are time critical.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Imagemagick significantly slow(er) screen grab

Post by anthony »

You must remember Imagemagick is a General Image processor, for a large variety of formats, OSs, and techniques.

In general any program designed for a specific specialized task will beat a generalized program, such as ImageMagick.

ImageMagick is general one-stop shop.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply