-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
executable file
·73 lines (62 loc) · 2.06 KB
/
run.py
File metadata and controls
executable file
·73 lines (62 loc) · 2.06 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python
# Adapted from https://bitbucket.org/MattHawkinsUK/rpispy-video-capture-unit
import os
import time
import datetime
import RPi.GPIO as GPIO
import picamera
import config
def GetFileName():
filename = time.strftime("%Y%m%d_%H%M%S", time.gmtime())
return filename
print "Holiday Pi"
ButtonCounter = 0
# Setup GPIO pins
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(config.BUTTONGPIO, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
# Create camera object and setup
camera = picamera.PiCamera()
camera.framerate = config.VIDEO_FRAMERATE
camera.resolution = config.VIDEO_RESOLUTION
camera.led = False
camera.vflip = config.VIDEO_VFLIP
camera.rotation = config.VIDEO_ROTATE
print "Camera ready"
debounce = False
recording = False
need_thumbnail = True
poll_interval = 0.2
# Run until Control-C
try:
while True:
if recording:
if debounce or (GPIO.input(config.BUTTONGPIO)==1):
debounce = False
camera.wait_recording(poll_interval)
else:
print " Stop recording"
debounce = True
recording = False
camera.led = False
camera.stop_recording()
else:
if debounce or (GPIO.input(config.BUTTONGPIO)==0):
debounce = False
time.sleep(poll_interval)
else:
debounce = True
recording = True
filename = GetFileName()
start_time = time.time()
camera.led = True
if need_thumbnail:
need_thumbnail = False
camera.capture(os.path.join(config.VIDEO_PATH,'thumbnail.jpg'), use_video_port=True)
stamp = datetime.datetime.fromtimestamp(start_time).strftime('%H:%M:%S')
print 'Start recording : ' + stamp + ' : ' + filename + '.h264'
camera.start_recording(os.path.join(config.VIDEO_PATH,filename + '.h264'))
except KeyboardInterrupt:
camera.led = False
camera.close()
print "Camera closed"