有没有一个命令可以获取gif图像中的帧数?
我有一些gif图像,我想将它们转换为数组,但我想根据任意输入的gif图像的帧数来限制数组的结构和大小。我曾考虑过使用ImageMagick这样的工具,但目前还没有找到相应的选项。
identify
命令。identify /path/to/image.gif
%n
输出格式指定符获取序列中的图像数量,但令人讨厌的是它似乎会为每个图像打印一次。要获得一个单独的数字,您可以执行以下操作:identify -format "%n\n" path/to/file.gif | head -1
$ exiftool -b -FrameCount giphy.gif
33
gif 的完整 exiftool 输出:
$ exiftool giphy.gif
ExifTool Version Number : 10.10
File Name : giphy.gif
Directory : .
File Size : 2.1 MB
File Modification Date/Time : 2018:04:22 21:00:42-04:00
File Access Date/Time : 2018:04:22 21:01:03-04:00
File Inode Change Date/Time : 2018:04:22 21:00:52-04:00
File Permissions : rw-rw-r--
File Type : GIF
File Type Extension : gif
MIME Type : image/gif
GIF Version : 89a
Image Width : 500
Image Height : 281
Has Color Map : Yes
Color Resolution Depth : 7
Bits Per Pixel : 7
Background Color : 127
Animation Iterations : Infinite
XMP Toolkit : Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27
Creator Tool : Adobe Photoshop CS6 (Macintosh)
Instance ID : xmp.iid:C312DB1DA6A311E5B8F5D2BA262E999D
Document ID : xmp.did:C312DB1EA6A311E5B8F5D2BA262E999D
Derived From Instance ID : xmp.iid:C312DB1BA6A311E5B8F5D2BA262E999D
Derived From Document ID : xmp.did:C312DB1CA6A311E5B8F5D2BA262E999D
Frame Count : 33
Duration : 2.31 s
Image Size : 500x281
Megapixels : 0.141
grep
来筛选exiftool
的输出:每个字段都可以独立打印出来:exiftool dev/slack-emojinator/gifs/yj_batsu.gif -FrameCount
和exiftool dev/slack-emojinator/gifs/yj_batsu.gif -b -FrameCount
只是为了获取值。 - muruexiftool
程序可以在libimage-exiftool-perl
软件包中找到,并且可以通过apt install libimage-exiftool-perl
进行安装。在Arch Linux(2021)上,它可以在perl-image-exiftool
软件包中找到。 - Rudy Matela受到这篇文章的启发,使用以下一行命令:
$ identify drop_caches.gif | wc -l
128
更多详细信息,请使用以下链接:
identify -verbose filename.gif
.gif
文件,并对其进行多种分析,包括帧数。
convert
工具可以将您的.gif
转换为单独的.png
图像,每个帧都有一个图像:$ convert -verbose -coalesce drop_caches.gif drop_caches.png
drop_caches.gif[0] GIF 470x940 470x940+0+0 8-bit sRGB 256c 177KB 0.090u 0:00.099
drop_caches.gif[1] GIF 13x1 470x940+398+704 8-bit sRGB 256c 177KB 0.080u 0:00.089
drop_caches.gif[2] GIF 306x620 470x940+144+130 8-bit sRGB 256c 177KB 0.080u 0:00.089
(... SNIP ...)
drop_caches.gif=>drop_caches-125.png[125] GIF 470x940 470x940+0+0 8-bit sRGB 255c 50.3KB 27.100u 0:24.890
drop_caches.gif=>drop_caches-126.png[126] GIF 470x940 470x940+0+0 8-bit sRGB 254c 48.9KB 27.320u 0:25.089
drop_caches.gif=>drop_caches-127.png[127] GIF 470x940 470x940+0+0 8-bit sRGB 254c 48.9KB 27.480u 0:25.269
ffprobe -v warning -show_frames qqq.gif | grep -c '\[/FRAME\]'
less +G image.gif
image.gif[#]...
中括号中的最后一个#
(从0开始计数);或者可以使用以下方法进行计算:less image.gif | wc -l