Permalink
Browse files

Adding config options; handling errors from fswebcam (re-getting photo)

  • Loading branch information...
morphex committed Sep 18, 2018
1 parent 03615bb commit 8c8b84fc46fd0863e7487039700ddc361f266c9a
Showing with 40 additions and 6 deletions.
  1. +2 −2 README.md
  2. +15 −0 config.py
  3. +23 −4 surveil.py
View
@@ -7,6 +7,6 @@ Note: On demoboards ffmpeg may use some time to compile a video, the system
I'm running has 4 cores, which enables several videos to be compiled at once
without bogging down the system.
Todo: FIX framerate so that VLC can play the video; currently using mpv to
play videos created.
Todo:
Add seconds to timestamp
View
@@ -7,4 +7,19 @@
# My webcam is upside-down, so I rotate it 180 degress (: :)
ROTATE = 180
# Length of generated video
VIDEO_MINUTES = 5
# Frames to skip before capturing image
#
# If surveil reports a lot of errors from fswebcam like this:
#
# GD Error: gd-jpeg: JPEG library reports unrecoverable error: Unsupported
# marker type 0x28Captured frame in 0.00 seconds.
#
# Try increasing the SKIP_FRAMES, up to 20
#
SKIP_FRAMES = 10
# Input selected, fswebcam -i argument
INPUT = "0"
View
@@ -20,10 +20,10 @@
_INDEX_VIDEO = 0
# (60) is one minute of images, (60 * 10) is 10 minutes
VIDEO_IMAGES = (60 * 3) / SLEEP_SECONDS
VIDEO_IMAGES = (60 * config.VIDEO_MINUTES) / SLEEP_SECONDS
# 20 KBs minimum; corrupt images are small
MINIMUM_IMAGE_SIZE = 1024 * 20
# 5 KBs minimum; corrupt images are small
MINIMUM_IMAGE_SIZE = 1024 * 5
def test_dependencies():
try:
@@ -156,7 +156,26 @@ def setup_video():
_time = time.time()
filename = '%08i.jpg' % _INDEX
path = 'images/%s' % filename
os.system('fswebcam --rotate %i -d %s %s' % (config.ROTATE, DEVICE, path))
while 2:
process = subprocess.Popen(['fswebcam', '-S', str(config.SKIP_FRAMES),
'--jpeg', str(95),
'--rotate', str(config.ROTATE), '-d', DEVICE,
'-i', config.INPUT,
path], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
#print(process)
process.wait()
output = process.stderr.read() + process.stdout.read()
output = str(output)
#print(type(output))
#print((output,))
if output.lower().find('error') > -1:
print("fswebcam reported error: ")
print(output)
# So we don't spam the system with repeated requests
time.sleep(1)
else:
break
for video in glob.glob("video??????"):
try:
os.stat(video + "/done.txt")

0 comments on commit 8c8b84f

Please sign in to comment.