我制作了一个 raspi0 PIR cam 并试图让它写入我的网络存储设备。.py 写入驱动器,但除非我 ctrl C 并手动重新启动,否则只会重新保存同一个文件。
from picamera import PiCamera
import time
from time import sleep
import os
import sys
from datetime import datetime
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
pir_sensor = 17 #GPIO physical pin 11
GPIO.setup(pir_sensor, GPIO.IN, GPIO.PUD_DOWN)
current_state = 0
filename_part1="surv"
file_ext=".mp4"
now = datetime.now()
current_datetime = now.strftime("%d-%m-%Y_%H:%M:%S")
filename=filename_part1+"_"+current_datetime+file_ext
filepath="/mnt/local_share/Surveillance_Captures/"
def capture_video():
camera.start_preview()
camera.start_recording('/home/pi/python_code/capture/newvideo.h264')
camera.wait_recording(10)
camera.stop_recording()
camera.stop_preview()
def remove_file():
if os.path.exists("/home/pi/python_code/capture/newvideo.h264"):
os.remove("/home/pi/python_code/capture/newvideo.h264")
else:
print("file does not exist")
camera=PiCamera()
while True:
i = GPIO.input(17)
if i==1:
print("Motion Detected")
capture_video()
sleep(2)
res=os.system("MP4Box -add /home/pi/python_code/capture/newvideo.h264 /home/pi/python_code/capture/newvideo.mp4")
os.system("mv /home/pi/python_code/capture/newvideo.mp4 "+filepath+filename)
print("File Moved")
print("Scanning Sector")
sleep(2)
remove_file()