-
Notifications
You must be signed in to change notification settings - Fork 0
/
camcorder-night.py
59 lines (53 loc) · 1.76 KB
/
camcorder-night.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
# =====================================================================================
# camcorder-night.py
# =====================================================================================
# Copyright 2014 Justin Cano
# http://www.justincano.com
#
# Python script to record video clips to an external mounted USB NTFS hard drive.
# This script is intended to operate the camera at NIGHT TIME hours, before sunrise and
# after sunset.
# Use time.sleep() record for desired amount of time
#
# 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
#
# External PiCam resources:
# http://www.raspberrypi.org/documentation/usage/camera/python/README.md
# http://www.raspberrypi.org/learning/python-picamera-setup/
# =====================================================================================
import time
import datetime
import picamera
import RPi.GPIO as GPIO
import sun
MINUTE = 60 # in seconds
HOUR = 3600 # in seconds
RECORDING_LENGTH = HOUR # 3600 seconds
camera = picamera.PiCamera()
camera.resolution = (1920, 1080) # HD resolution
LED = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED, GPIO.OUT)
def main():
date = datetime.datetime.now()
if sun.nighttime(date):
camera.led = True
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
camera.start_recording(filename)
time.sleep(HOUR) # record for an hour
camera.stop_recording()
else:
GPIO.output(LED, GPIO.LOW)
camera.led = False
time.sleep(MINUTE)
if __name__ == "__main__":
while True:
main()