Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. from picamera import PiCamera
  2. import datetime
  3. import time
  4. import os
  5.  
  6. camera = PiCamera()
  7.  
  8. lightOnTime = datetime.time(8,0,0)
  9. lightOffTime = datetime.time(23,0,0)
  10.  
  11. VIDEO_DAYS = 20
  12. FRAMES_PER_HOUR = 60
  13. frameCount = 0
  14. FRAMES = FRAMES_PER_HOUR * 24 * VIDEO_DAYS
  15. lightState = 0
  16. def capture_frame(frame):
  17.  
  18. with picamera.PiCamera() as cam:
  19. time.sleep(2)
  20. cam.capture('frame%03d.jpg' % frame)
  21.  
  22. while (frameCount < FRAMES):
  23.  
  24. if lightState == 0:
  25.  
  26. if datetime.datetime.now().time() < lightOffTime and datetime.datetime.now().time() > lightOnTime:
  27. print("Lights on!")
  28. lightState = 1
  29.  
  30. else:
  31. continue
  32.  
  33.  
  34. else:
  35. if lightState == 1:
  36. today = datetime.datetime.today().date()
  37. todayStr = today.isoformat()
  38.  
  39. if not os.path.exists(todayStr):
  40. os.mkdir(todayStr)
  41. print(frameCount)
  42. camera.capture(todayStr+'/image'+str(frameCount).zfill(4)+'.jpg')
  43. frameCount = frameCount + 1
  44. time.sleep(45)
  45. if datetime.datetime.now().time() > lightOffTime:
  46. print ("Lights out!")
  47. lightState = 0
  48. frameCount = 0
  49. cd todayStr
  50. for filename in os.listdir(todayStr):
  51. if (filename.endswith(".mp4")
  52. os.system("ffmpeg -i {0} -f image2 -vf fps=fps=1 output%d.png".format(filename))
  53. else:
  54. continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement