1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| from moviepy.editor import VideoFileClip from PIL import Image from pathlib import Path root_path=Path(__file__).parent mp4_file=root_path/'运动.mp4' pic_file=root_path/'运动.jpg' mp4_clip=VideoFileClip(str(mp4_file)) width,height=mp4_clip.size during=mp4_clip.duration frame_list=[] for i in range(1,int(during),6): frame=mp4_clip.get_frame(t=i) frame_list.append(frame) mp4_clip.close() frame_list=frame_list[::-1] height+=(len(frame_list)-1)*100 img_result=Image.new('RGB',(width,height)) for i,frame in enumerate(frame_list): img=Image.fromarray(frame) top=(len(frame_list)-i-1)*100 img_result.paste(im=img,box=(0,top)) img.close() img_result.save(pic_file) img_result.close()
|