在Python中提取每个GIF帧之间的延迟

2024-09-30 03:22:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用Python开发一个从HTML文件创建视频的程序。 HTML文件可能包含一个动画GIF,我需要在最后的视频中保留动画。在

受以下GitHub要点中提供的方法的启发,我已经成功地从gifhub中提取了每一帧:

https://gist.github.com/revolunet/848913

import os
from PIL import Image


def extractFrames(inGif, outFolder):
    frame = Image.open(inGif)
    nframes = 0
    while frame:
        frame.save( '%s/%s-%s.gif' % (outFolder, os.path.basename(inGif), nframes ) , 'GIF')
        nframes += 1
        try:
            frame.seek( nframes )
        except EOFError:
            break;
    return True


extractFrames('ban_ccccccccccc.gif', 'output')

我用这些帧替换了HTML中的GIF源代码,并使用PhantomJS生成了最终视频的所有帧。在

现在,我需要获得源GIF文件中每个帧的持续时间,以便在视频的相应帧中重现它。在

我在Python中找不到实现这一点的方法。在


Tags: 文件方法imageimport视频oshtml动画

热门问题