Ama*_*can 5 python file raspberry-pi
video.h264.我已经尝试了我在网上找到的各种东西,但它们只会导致文件名显示部分代码。令人讨厌的是,它运行了一次,但将它保存到了我没想到的地方,在我意识到它起作用之前我更改了代码!
# Import Libraries
import os #Gives Python access to Linux commands
import time #Proves time related commands
import RPi.GPIO as GPIO #Gives Python access to the GPIO pins
GPIO.setmode(GPIO.BCM) #Set the GPIO pin naming mode
GPIO.setwarnings(False) #Supress warnings
# Set GPIO pins 18 as output pin
LEDReady = 18 #Red
GPIO.setup(LEDReady,GPIO.OUT)
GPIO.output (LEDReady,GPIO.HIGH)
from subprocess import call
call(["raspivid", "-o", "video.h264", "-t", "50000n"])
time.sleep(10) #Sleep for 10 seconds
GPIO.output (LEDReady,GPIO.LOW)
Run Code Online (Sandbox Code Playgroud)
添加DATE=$(date +"%Y-%m-%d_%H%M")
和更改为 $DATEvideo.h264会$DATE.h264导致语法错误。
诱人的是,我有一个名为 20180308_021941.h264 的文件,这正是我想要的,但我无法告诉你我是如何管理它的!
PS 红色 LED 亮起是为了让我可以判断 Raspberry Pi 是否正确启动并运行了 Python 脚本。
感谢您不厌其烦地阅读本文。
尝试添加这个
from datetime import datetime
date = datetime.now().strftime("%Y%m%d%H:%M:%S")
Run Code Online (Sandbox Code Playgroud)
然后将您的呼叫更改为此
videoFile = date + ".h264"
call(["raspivid", "-o", videoFile, "-t", "50000n"])
Run Code Online (Sandbox Code Playgroud)