Advertisement
bela333

Untitled

Aug 3rd, 2015
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. from PIL import Image
  2. from subprocess import Popen, PIPE
  3. import random
  4. import time
  5. import datetime
  6.  
  7. fps, duration, ColorDuration = 2, 30, 0.5
  8. start = time.time()
  9.  
  10. duration += 1
  11. width, height = 1080, 720
  12.  
  13. LastPercent = 0
  14.  
  15. 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)
  16. for i in range(int(duration/ColorDuration)):
  17. Float = i/(duration/ColorDuration)
  18. r=random.randrange(255)
  19. g=random.randrange(255)
  20. b=random.randrange(255)
  21. im = Image.new("RGB", (width, height), (r,g,b))
  22. im.save(p.stdin, 'JPEG')
  23. percent = int(round((Float)*100, 0))
  24. if(LastPercent != percent):
  25. Time = time.time()-start
  26. TimeLeft = (((duration/ColorDuration)/i)*Time)-Time
  27. print(str(percent) + "%... Time left: " +time.strftime("%H hours, %M minutes and %S seconds!", time.gmtime(TimeLeft)))
  28. LastPercent = percent
  29. p.stdin.close()
  30. p.wait()
  31. 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