j0h*_*j0h 25 command-line imagemagick image-processing gif
是否有命令可以获取 gif 中的帧数?我有一些 gif,我想将它们转换为数组,但我想根据我碰巧提供给我的程序的任何随机 gif 中的帧数来限制数组和数组的结构。我在想 imagemagick 可能有这样的选择,但我还没有找到。
pom*_*sky 26
如果你安装了 ImageMagick,你可以使用它的identify命令如下
identify /path/to/image.gif
Run Code Online (Sandbox Code Playgroud)
您将获得每一帧的详细信息。
正如steeldriver所建议的,您可以使用%n输出格式说明符直接获取序列中的图像数量,但令人讨厌的是,它似乎为每个图像打印一次。要获得一个号码,您可以这样做
identify -format "%n\n" path/to/file.gif | head -1
Run Code Online (Sandbox Code Playgroud)
L. *_*mes 19
Exiftool将列出帧计数作为其广泛输出的一部分。
这是动画 Gif 文件的命令和输出:
$ exiftool -b -FrameCount giphy.gif
33
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
受本文启发,使用此单行命令:
$ identify drop_caches.gif | wc -l
128
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请使用:
identify -verbose filename.gif
Run Code Online (Sandbox Code Playgroud)
该网站允许您上传您的文件.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
Run Code Online (Sandbox Code Playgroud)
FFmpeg方式:
ffprobe -v warning -show_frames qqq.gif | grep -c '\[/FRAME\]'
Run Code Online (Sandbox Code Playgroud)
Gif 视频是视频,因此视频分析工具也可能有所帮助。
less如果你已经ImageMagick安装,你也可以使用命令。
less +G image.gif
Run Code Online (Sandbox Code Playgroud)
总帧数是#括号中 的最后一个image.gif[#]...(从0开始);或者用以下方法计算:
less image.gif | wc -l
Run Code Online (Sandbox Code Playgroud)