-
Notifications
You must be signed in to change notification settings - Fork 0
/
camerav5.py
62 lines (53 loc) · 1.81 KB
/
camerav5.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
#!/usr/bin/python3
import picamera
from picamera import PiCamera
import time
from datetime import datetime
from subprocess import Popen
print("\nPiCamServer Camera Backend v5\n")
print("Streams video to rtsp://[pi-ip]:8554/ | Captures to pics/[timestamp].jpg")
print("Ctrl-C quits.\n")
#configNow = input("Configure session settings now (y/n)? ").lower()
stream = input("Should I stream video or take pictures (v/p)? ").lower()
preview = input("Should I display a local video preview (y/n)? ").lower()
#http://www.raspberry-projects.com/pi/pi-hardware/raspberry-pi-camera/streaming-video-using-vlc-player
#http://www.diveintopython.net/scripts_and_streams/stdin_stdout_stderr.html
#Ouput video (record) => stream => stdout => | => cvlc livestream => browser
if stream == "v":
print("Running...")
try:
if preview == "y":
live = Popen(["./livestream.sh"])
elif preview == "n":
live = Popen(["./livestream(nprev).sh"])
finally:
print("\n\nExiting...")
live.terminate()
elif stream == "p":
length = float(input("How long should I run (in minutes): "))*60
interval = float(input("How often should I take a picture (in seconds): "))
print("Running...")
camera = PiCamera()
camera.annotate_background = picamera.Color('black')
camera.rotation = 180
camera.resolution = (640, 480)
counter = 0
try:
if preview == "y":
camera.start_preview()
while counter <= length:
#nice-looking timestamp for overlay
timestamp = datetime.now().strftime("%m-%d-%Y_%H:%M:%S")
camera.annotate_text = timestamp
#seconds since unix epoch for filename
filetime = str(int(time.time()))
path = 'pics/' + filetime + '.jpg'
camera.capture(path, use_video_port=True)
time.sleep(interval)
counter += interval
finally:
print("Exiting...")
if preview == "y":
camera.stop_preview()
else:
print("Invalid input!")