-
Notifications
You must be signed in to change notification settings - Fork 0
/
camcorder-day.py
53 lines (48 loc) · 1.64 KB
/
camcorder-day.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
# =====================================================================================
# camcorder-day.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 DAY TIME hours, after sunrise and
# before 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
def main():
date = datetime.datetime.now()
if sun.daytime(date):
camera.led = True
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:
camera.led = False
time.sleep(MINUTE)
if __name__ == "__main__":
while True:
main()