I have a python script to record a .mp4 file with picamera2 which executes and save correctly when run through the editor (thonny) and through the terminal. However, when I schedule it through crontab to run at boot (or through bash.rc) the script runs (I hear the camera click on) but no file is saved in either the home directory or the directory that I've called in the python script. Is there some piece that I'm missin in cron to get it to actually save?
#!/usr/bin/python3 import time import os from picamera2 import Picamera2 from picamera2.encoders import H264Encoder from picamera2.outputs import FfmpegOutput timestr = time.strftime("%Y%m%d-%H%M%S") picam2 = Picamera2() video_config = picam2.create_video_configuration() picam2.configure(video_config) os.chdir('/media/pi/USB/VIDEO') encoder = H264Encoder(10000000) output = FfmpegOutput(timestr+'.mp4', audio=True, ) picam2.start_recording(encoder, output) time.sleep(10) picam2.stop_recording()
I've also tried getting putting this into a shell script and scheduling the shell to run in cron. Same issue - the shell will run the python script successfully and save a file appropriately when executed from terminal, but not when scheduled:
cd / cd home/pi/ /usr/bin/python3 /home/pi/VideoPythonTest.py cd /
@reboot sh /home/pi/launcher.sh