replay.py 979 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 18 18:34:40 2018

@author: Antoine Lima, Leo Reynaert, Domitille Jehenne
"""

import picamera
import settings import Settings

class Replay():
	def __init__(self):
		self.cam = picamera.PiCamera()
		self.cam.resolution = Settings['picam.resolution']
		self.cam.framerate = Settings['picam.fps']
		self.cam.hflip = Settings['picam.hflip']
		self.cam.vflip = Settings['picam.vflip']
		self.format = Settings['picam.format']
		self.continue_recording = False
		self.stream = picamera.PiCameraCircularIO(self.cam, seconds=Settings['replay.duration'])
	
	def capture(self, fileToSave):
		self.cam.start_recording(self.stream, self.format)
		self.continue_recording = True
		
		try:
			while self.continue_recording:
				self.cam.wait_recording(1)
		finally:
			self.cam.stop_recording()
			
		self.stream.copy_to(fileToSave)
		self.cam.close()
		self.stream.close()

	def stop():
		self.continue_recording = False