camera.split_recording不会在运行时生成文件

问题描述 投票:0回答:1

我正在录制视频,并希望定期将该视频保存到文件中。我使用split_recording命令。但问题是所有视频只有在stop_recording命令后出现在光盘上。

camera = PiCamera()
while (True):
    camera.start_recording('1.h264',format='h264')
    camera.wait_recording(5)

    for i in range(2, 5):
        camera.split_recording('%d.h264' % i, splitter_port=1)
        camera.wait_recording(2)

#All recording files appear only after belowline
camera.stop_recording() 

我的应用程序是安全摄像头,这意味着我可以运行相机几天,没有录制的文件会看到,只有当我停止录制时,录制的文件才会出现在此处。

如何在不停止摄像机录制的情况下将录制文件转储到文件中?

python stream raspberry-pi
1个回答
0
投票

您可能需要使用自定义输出对象,这里是来自documentation的片段

import picamera

class MyOutput(object):
    def __init__(self):
        self.size = 0

    def write(self, s):
        self.size += len(s)

    def flush(self):
        print('%d bytes would have been written' % self.size)

with picamera.PiCamera() as camera:
    camera.resolution = (640, 480)
    camera.framerate = 60
    camera.start_recording(MyOutput(), format='h264')
    camera.wait_recording(10)
    camera.stop_recording()

在这种情况下,MyOutput类需要打开一个文件,并以关闭文件的方式定义write函数。刷新功能也应该冲洗。例如,在MyOutput类的构造函数中,您可以将文件保持文件处理程序作为类变量打开,而写入/刷新函数则相应地写入并刷新文件处理程序。

[编辑]刚刚找到了类似问题的一个很好的答案:https://raspberrypi.stackexchange.com/a/31389

© www.soinside.com 2019 - 2024. All rights reserved.