I am having a strange problem with the Pi Camera.
My little program does the following:
- The camera uses PiCameraCircularIO to continuously record 20 sec
- Once I click a button, the previous 20 seconds will be saved to a file on the flash drive
- After that, the circular IO continues. If I would click again, a new 20 sec interval will be saved.
This is the code:
It is just the code from Basic Recipes Pi Camera. I must be doing something obvious wrong...
Code: Select all
import io import random import picamera import RPi.GPIO as GPIO import time btnPressed = False GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP) def write_now(): global btnPressed input_state = GPIO.input(17) if input_state == False: btnPressed = True return btnPressed def write_video(stream): print('Writing video!') with stream.lock: # Find the first header frame in the video for frame in stream.frames: if frame.frame_type == picamera.PiVideoFrameType.sps_header: stream.seek(frame.position) break # Write the rest of the stream to disk with io.open('motion.h264', 'wb') as output: output.write(stream.read()) with picamera.PiCamera() as camera: stream = picamera.PiCameraCircularIO(camera, seconds=5) camera.start_recording(stream, format='h264') try: while True: camera.wait_recording(1) if write_now(): btnPressed = False write_video(stream) finally: camera.stop_recording()
Thanks for the help!