-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton-camcorder.py
76 lines (64 loc) · 2.2 KB
/
button-camcorder.py
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
74
75
76
# =====================================================================================
# camcorder-night.py
# =====================================================================================
# Copyright 2014 Justin Cano
# http://www.jcano.me
#
# Python script to record video clips to an external mounted USB NTFS hard drive.
# This script is intended to operate the camera using a button mechanism that acts as a
# switch.
# Click button to begin recording, click again to stop.
#
# Video files saved as .h264 named by their timestamp
# Filename: video_<month>-<day>-<year>_<weekday><day>_<hour><min><sec>.h264
# Format: MM-DD-YY_DayDD_hhmmss
# Example: 06-27-14_Thurs27_221834 => Thursday, June 27 2014 at 10:18pm
#
# License: GPL v3 (http://www.gnu.org/licenses/gpl-3.0.txt)
#
# External PiCam resources:
# http://www.raspberrypi.org/documentation/usage/camera/python/README.md
# http://www.raspberrypi.org/learning/python-picamera-setup/
# http://makezine.com/projects/tutorial-raspberry-pi-gpio-pins-and-python/
# =====================================================================================
import time
import datetime
import sys
import picamera
import RPi.GPIO as GPIO
HOUR = 3600 # in seconds
# Setup camera
camera = picamera.PiCamera()
camera.resolution = (1920, 1080) # HD resolution
#LED = 17
#GPIO.setmode(GPIO.BCM)
#GPIO.setup(LED, GPIO.OUT)
BUTTON = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON, GPIO.IN, GPIO.PUD_UP)
def stopRecording(channel):
print "Stopping recording..."
camera.stop_recording()
camera.stop_preview()
print "Recording stopped."
sys.exit()
GPIO.add_event_detect(BUTTON, GPIO.RISING, callback=stopRecording, bouncetime=300)
def main():
# Create timestamp
date = datetime.datetime.now()
#GPIO.output(LED, GPIO.HIGH)
label = date.strftime('%m-%d-%y_%a%b%d_%H%M%S')
filename = '/media/usbhdd/video_' + label + '.h264'
print 'recording video clip', label
# Start recording
camera.start_preview()
camera.start_recording(filename)
camera.led = True
# Record for an hour
time.sleep(HOUR)
# Stop recording
camera.stop_recording()
camera.stop_preview()
if __name__ == "__main__":
while True:
main()