python截取视频的某一部分,转为gif,作为视频的预览
from moviepy.editor import * def samllVideoGif(_videoPath, _videoGifPath): # _videoPath = "C:\\Users\\sswc\\Desktop\\gai2\\public\\showPdf\\6f3db1f9-e247-4aa5-bca7-93bae62a0079.mp4" # _videoGifPath = "C:\\Users\\sswc\\Desktop\\gai2\\public\\showPdf\\6f3db1f9-e247-4aa5-bca7-93bae62a0079.gif" # clip = (VideoFileClip(_videoPath).subclip(1, 3).resize(0.1)) # 现在切割T = 4和6秒之间的剪辑 resize等比缩放 subclip截取很多秒 clip = (VideoFileClip(_videoPath).subclip(1, 30).resize(1)) clip.write_gif(_videoGifPath) # gif将有30 fps