我最近得到了Raspberry Pi的攝像頭模塊。通過他們找到的循環緩衝區示例工作here (code shown below.)Raspberry Pi攝像頭捕獲循環緩衝區並跟隨(x)秒數
我的目標是保存內建在「stream = picamera.PiCameraCircularIO(camera,seconds = 20)」中的20秒緩衝區,但也要繼續記錄30秒。我在他們的例子中添加的主要內容是在引腳17上的GPIO輸入之後的「time.sleep(30)」。當我運行它時,它有時產生一個文件,但該文件從不可播放。我很感謝您提供的任何建議或建議。
代碼:
import io
import time
import picamera
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, GPIO.PUD_UP)
with picamera.PiCamera() as camera:
stream = picamera.PiCameraCircularIO(camera, seconds=20)
camera.start_recording(stream, format='h264')
GPIO.wait_for_edge(17, GPIO.FALLING)
time.sleep(30)
camera.stop_recording()
for frame in stream.frames:
if frame.header:
stream.seek(frame.position)
break
with io.open('/home/pi/Desktop/video.h264', 'wb') as output:
while True:
data = stream.read1()
if not data:
break
output.write(data)