I'm using the Pi camera to record 30 seconds of footage, triggered by an IR break beam sensor. This is running on a Pi 3 B+. I've soldered in all the wiring using an Adafruit Perma-Proto Pi Hat. My problem is that at some point I started recording choppy video when I triggered a recording and for the life of me I can't figure out what may have changed it. It was recording perfectly for weeks. Now, it seems like the buffer for processing video is depleted not long after it starts recording and because of this it starts dropping frames(just a guess). Here are the things I've tried to rectify the problem:

  1. Increased GPU memory
  2. Decreased video resolution
  3. Running program on different pi
  4. Running program with different proto pi hat
  5. Reverting back to using a breadboard instead of proto pi hat
  6. Trying a different pi camera

I think I've done everything that I can to feel sure that it isn't a hardware issue. I'm trying to avoid completely reinstalling raspian but I'm willing to do it if need be. Has anyone else had a similar problem or a suggestion for a solution to my problem?

# Imports
from picamera import PiCamera
import time
import RPi.GPIO as GPIO
import datetime 
import logging

# Variables
camera = PiCamera()
BEAM_PIN = 4                                # Pin we are using to read the IR break beam switch
LED_PIN = 17                                # Pin we are using to activate the LED
log_time = datetime.datetime.now().strftime('%m%d%y')
#create logger
logger = logging.getLogger('myapp')
logger.setLevel(logging.DEBUG) # log all escalated at and above DEBUG

# Setup the GPIO
GPIO.setmode(GPIO.BCM)                 # GPIO layout mode      
GPIO.setup(BEAM_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Setup the gpio pin we are reading from as a pullup input

# Loop checking the switch
while True:
    # Read the switch value
    input = GPIO.input(BEAM_PIN)

    # If the GPIO reading goes from high to low, record for 30 secs
    if input != 1:
        #define time format for filenames and log output
        now = time.localtime(time.time())      #Variable plugged into asci time to allow for readable date print out 
        timestamp = datetime.datetime.now().strftime("%m%d%y_%H%M%S") #Variable to update name of video files with current date and time
        #add a file handler
        hdlr = logging.FileHandler('/media/pi/Lexar/log/{}.log'.format(log_time))
        # create a formatter and set the formatter for the handler
        formatter = logging.Formatter('%(asctime)s %(message)s')
        #add the handler to the logger
        logger.info('Lamprey Detected!')
        camera.start_recording('/media/pi/Lexar/test_video/{}.h264'.format(timestamp)) #Recording video file to Lexar thumb drive
        time.sleep(0.05) #Debounce wait
  • What code are you using to do the Pi Camera recording?
    – CoderMike
    Mar 4, 2019 at 20:31
  • I'm using python 3
    – kemistree4
    Mar 4, 2019 at 20:49
  • 1
    The question is to show us the code, not just the language...
    – Dirk
    Mar 4, 2019 at 22:42
  • ah i see. I've updated the post with my code
    – kemistree4
    Mar 4, 2019 at 23:57
  • 1
    I ended up doing a fresh install of debian and it seems to have fixed the problem. The only thing that I can think is that I was attempting to record using the circular buffer last week, enabling me to record some of footage before a trigger was tripped. Maybe that buffer never got purged and was limiting how much video I could store? I assumed that anything in the buffer would go away with a shutdown cycle but is there the possibility that I'm wrong?
    – kemistree4
    Mar 5, 2019 at 0:00


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.