Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- from subprocess import Popen, PIPE
- import random
- import time
- import datetime
- fps, duration, ColorDuration = 2, 30, 0.5
- start = time.time()
- duration += 1
- width, height = 1080, 720
- LastPercent = 0
- p = Popen(['ffmpeg','-loglevel' ,'quiet', '-y', '-f', 'image2pipe', '-vcodec', 'mjpeg', '-r', str(fps), '-i', '-', '-vcodec', 'libx264', '-qscale', '5', '-r', str(fps), '-filter:v', "setpts=" + str((fps*ColorDuration)) + "*PTS",'-preset','veryfast', 'video.mp4'], stdin=PIPE)
- for i in range(int(duration/ColorDuration)):
- Float = i/(duration/ColorDuration)
- r=random.randrange(255)
- g=random.randrange(255)
- b=random.randrange(255)
- im = Image.new("RGB", (width, height), (r,g,b))
- im.save(p.stdin, 'JPEG')
- percent = int(round((Float)*100, 0))
- if(LastPercent != percent):
- Time = time.time()-start
- TimeLeft = (((duration/ColorDuration)/i)*Time)-Time
- print(str(percent) + "%... Time left: " +time.strftime("%H hours, %M minutes and %S seconds!", time.gmtime(TimeLeft)))
- LastPercent = percent
- p.stdin.close()
- p.wait()
- print("Time elapsed: "+ time.strftime("%H hours, %M minutes and %S seconds!", time.gmtime(time.time()-start)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement