Python,我如何获得gif框架 [英] Python, how i can get gif frames
问题描述
我正在寻找一种获取gif帧数的方法.我正在Google,StackOverflow和任何其他网站上搜索,但我只发现垃圾!有人知道该怎么做吗?我只需要简单数量的gif框架.
I am looking some kind method to get gif frames number. I am looking on Google, StackOverflow and any other sites and I find only rubbish! Someone know how to do it? I need only simple number of gif frames.
推荐答案
您使用哪种方法加载/操纵框架?您在使用PIL吗?如果没有,我建议您检查一下: Python Imaging Library ,尤其是
Which method are you using to load/manipulate the frame? Are you using PIL? If not, I suggest checking it out: Python Imaging Library and specifically the PIL gif page.
现在,假设您正在使用PIL读取gif,那么确定要查看的帧是一件非常简单的事情. seek 将转到特定的帧,而 tell 将返回您正在查看的帧.
Now, assuming you are using PIL to read in the gif, it's a pretty simple matter to determine which frame you are looking at. seek will go to a specific frame and tell will return which frame you are looking at.
from PIL import Image
im = Image.open("animation.gif")
# To iterate through the entire gif
try:
while 1:
im.seek(im.tell()+1)
# do something to im
except EOFError:
pass # end of sequence
否则,我相信您只能通过查找直到引发异常(EOFError)来找到gif中的帧数.
Otherwise, I believe you can only find the number of frames in the gif by seeking until an exception (EOFError) is raised.
这篇关于Python,我如何获得gif框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!