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:WindowsFontsArial.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")