Raspberry pi视频流到主机并同时保存?

时间:2019-04-28 18:04:39

标签: python raspberry-pi streaming

我正在使用picamera从树莓派向我的主机流式传输。现在,我正在尝试将流式传输的素材保存到视频文件中。我也想保存在主机上流式传输的素材。

我研究了cv2.VideoCapture,但是它需要图像或文件作为参数,因为它正在传输数据(字节),所以我没有。

这是到目前为止我得到的:

# Start a socket listening for connections on 0.0.0.0:8000 (0.0.0.0 means
# all interfaces)
server_socket = socket.socket()
server_socket.bind(('0.0.0.0', 8000))
server_socket.listen(0)

# Accept a single connection and make a file-like object out of it
connection = server_socket.accept()[0].makefile('rb')

try:
    # Run a viewer with an appropriate command line. Uncomment the mplayer
    # version if you would prefer to use mplayer instead of VLC
    cmdline = [[os.path.join("C:/", "Program Files", "VideoLAN", "VLC", "vlc.exe")], '--demux', 'h264', '-']
    #cmdline = ['mplayer', '-fps', '25', '-cache', '1024', '-']
    player = subprocess.Popen(cmdline, stdin=subprocess.PIPE)
    while True:
        # Repeatedly read 1k of data from the connection and write it to
        # the media player's stdin
        data = connection.read(1024)
        if not data:
            break
        player.stdin.write(data)
finally:
    connection.close()
    print("connection closed")
    server_socket.close()
    player.terminate()```


0 个答案:

没有答案