我正在制作一个执行 Python 脚本的 php 程序,其中相机正在录制。相机已插入 Raspberry Pi。这是 Python 脚本(我使用的是 Python3):
#import time
import datetime
import subprocess
import os
import sys
from picamera import PiCamera
T = 0
N = 0
A = 0
print("0")
TITLE = "maelan" #sys.argv[1]
S = 1 #sys.argv[2]
USER_NAME = "MaElAn" #sys.argv[3]
TIME = int(S)
#SRC = './src'
#DST = './mp4'
VIDEO_IN = TITLE + ".mp4"
PATH_VID = "/var/www/html/superv/public/user_" + USER_NAME + "/"
NEW_PATH_VID = PATH_VID + "exp_" + TITLE + "/"
#IMG = TITLE + "_" + str(T)
print("1")
if not os.path.exists(NEW_PATH_VID + "img"):
os.makedirs(NEW_PATH_VID + "img")
print("1.5")
if not os.path.exists(PATH_VID + "exp_" + TITLE):
os.system("mkdir " + PATH_VID + "exp_" + TITLE)
print("1.75")
VIDEO_OUT = NEW_PATH_VID + "compressed_" + TITLE + ".mp4"
#print (sys.argv)
print("2")
#os.system("/usr/bin/octave /home/pi/SOE/Frames/analyser.m")
CAMERA = PiCamera()
print("3")
CAMERA.resolution = (1280, 720)
CAMERA.framerate = 25
CAMERA.image_effect = "negative"
#CAMERA.start_preview()
CAMERA.start_recording(TITLE + ".h264")
#Horodatage dynamique
while T < TIME:
#CAMERA.capture("/home/pi/SOE/img/" + IMG + ".jpg")
NOW = datetime.datetime.now()
CAMERA.annotate_text = NOW.strftime("%Y-%m-%d %H:%M:%S " + TITLE)
CAMERA.wait_recording(1)
T = T + 1
CAMERA.stop_recording()
#CAMERA.stop_preview()
print("3")
我通过一个 php shell_exec 函数调用这个脚本。这是php代码:
$out=shell_exec('progVideo.py');
echo $out;
python 脚本执行良好,直到这一行:
CAMERA = PiCamera()
我觉得php没有权限访问插入Raspberry的相机。我做了chmod 777 /var/www
,chmod 777 /dev/vchiq
但没有任何效果。相机不记录任何东西。请帮助:)