I have the following code which I can run normally to record video, using python3 button_led_video.py
, however when I put it into /etc/rc.local
the camera no longer records video. Here is the python3
script:
#!/usr/bin/python3
from gpiozero import Button
from gpiozero import LED
from picamera import PiCamera
from datetime import datetime
from time import sleep
# setup camera and button
camera = PiCamera()
button = Button(4)
led = LED(17)
# recording flag
is_recording = 0
try:
# calibrate the camera
camera.start_preview()
print("CALIBRATING...")
sleep(2)
print("READY TO RECORD!")
print()
while True:
if (button.value == True) and (is_recording == 0):
print("RECORDING")
x = datetime.now().strftime('%Y-%m-%d-%H-%m-%s')
camera.start_recording('video-' + x + '.h264')
is_recording = 1
led.on()
elif (button.value == False) and (is_recording == 1):
print("DONE RECORDING!")
camera.stop_recording()
is_recording = 0
led.off()
except KeyboardInterrupt:
print("INTERRUPTED!")
button.close()
camera.close()
led.close()
Here is how I have it in /etc/rc.local
: sudo python3 /path/to/file.py &
When I make file.py executable
and add the above line to /etc/rc.local
, following a reboot (when I would expect the script to run on its own) I am able to get the LED to light up but nothing happens with the camera (no new video files appear after pressing, holding, and then releasing the button). If I try to run rc.local
manually at this point by simply running /etc/rc.local
I get an error that ends with: picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources
I am totally stuck on this, as it works outside of /etc/rc.local
reliably. Can someone tell me what I am doing incorrectly? I am trying to get a point and shoot video camera going here and this is problem is cramping my style.
camera.close()
aftercamera.stop_recording()
with no improvement in symptoms. video file still does not appear though script appears to be running.