How to speed up identify on images with multiple frames?

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
0xJohny
Posts: 2
Joined: 2013-08-14T09:29:53-07:00
Authentication code: 6789

How to speed up identify on images with multiple frames?

Post by 0xJohny »

When I run identify on animated GIF, or MP4 video, the execution time can go up to minutes, as it is identifying every single frame.

The command I want to run is:

Code: Select all

identify -format "%Q %m %n %w %h" image.gif
  • %Q - compression quality
  • %m - image format
  • %n - number of frames
  • %w - width
  • %h - height
I know that I can speed it up by specifying only one frame in path (image.gif[0]), but that would mean that %n would always return 1, and I need that value. ImageMagick is really inefficient in this. For example, even simple 'identify -format "%n" image.gif' is doing the identification process on every single frame, as opposed to just returning the requested total number of frames.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to speed up identify on images with multiple frames?

Post by snibgo »

Does "-ping" help?
snibgo's IM pages: im.snibgo.com
0xJohny
Posts: 2
Joined: 2013-08-14T09:29:53-07:00
Authentication code: 6789

Re: How to speed up identify on images with multiple frames?

Post by 0xJohny »

Doesn't seem to. Tried:

Code: Select all

identify -format "%n" -ping test.mp4
And it was as long as before (over a minute). Also tried other simple formats like %w, and same result. (I'm using ImageMagick 6.8.6-7 Q8)

How is -ping supposed to work? The documentation doesn't say much...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to speed up identify on images with multiple frames?

Post by snibgo »

As I understand it, "-ping" tells IM to read the metadata, but not to read and decode the actual image data. I always put it as the first argument:

Code: Select all

identify -ping -format "%n" test.mp4
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to speed up identify on images with multiple frames?

Post by snibgo »

For basic metadata of MP4 and other video, I use ffmprobe.

Code: Select all

D:\pictures\20130713>%FFM%ffprobe -show_streams d:\pictures\20130523\gopr0006.mp4
:
width=1920
height=1080
:
r_frame_rate=30000/1001
:
duration=1133.565767
:
The number of frames is the duration (seconds) multiplied by the frame rate (frames per second).

1133.565767 * 30000/1001 = 33973.00000999001 frames.

exiftool also works on MP4 files, but seems to give less precision.

exiftool works well for GIF files, giving an exact frame count.
snibgo's IM pages: im.snibgo.com
Post Reply