1. 程式人生 > >用設定的時間快速對視頻進行截圖

用設定的時間快速對視頻進行截圖

apt jpeg math cli mage pen type div log

import PIL
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import math
import time
from moviepy.editor import VideoFileClip, concatenate_videoclips
clip1 = VideoFileClip("1.mp4")
begintime=0
endtime=int(clip1.duration)
step=60

font = ImageFont.truetype("C:\Windows\Fonts\Arial.ttf", 26)


for i in range(begintime, endtime,step):
print(i)
m, s = divmod(i, 60)
h, m = divmod(m, 60)
time_tuple = (2016, 11, 1, h, m, s, 2, 317, 0)
timestr=time.strftime("%H:%M:%S",time_tuple)
clip1.save_frame("./avcapture/frame"+str(i)+".jpeg", t=timestr) # frame at time t=1h

imageFile = "./avcapture/frame"+str(i)+".jpeg"
im1 = Image.open(imageFile)


draw = ImageDraw.Draw(im1)
draw.text((0, 0),timestr, (255, 0, 0), font=font)
draw = ImageDraw.Draw(im1) #Just draw it!


im1.save("./avcapture/target"+str(i)+".jpeg")

用設定的時間快速對視頻進行截圖