我正在使用raspivid和netcat将RaspberryPi Zero的视频流传输到我的PC:
raspivid -t 0 -n -w 320 -h 240 -hf -fps 30 -o - | nc PC_IP PORT
现在,我要逐帧分析RaspberryPi上的视频以进行对象检测。 Raspi必须对对象检测做出反应,因此在流式传输视频时,我必须对Pi进行分析。
我的想法是使用tee
命令创建一个命名管道,并在python程序中读取此命名管道以获取帧:
mkfifo streampipe
raspivid -t 0 -n -w 320 -h 240 -hf -fps 30-o - | tee nc PC_IP PORT | streampipe
但是这不起作用,它显示为sh1: 1: streampipe: not found
我的python程序如下所示:
import subprocess as sp
import numpy
FFMPEG_BIN = "ffmpeg"
command = [ FFMPEG_BIN,
'-i', 'streampipe', # streampipe is the named pipe
'-pix_fmt', 'bgr24',
'-vcodec', 'rawvideo',
'-an','-sn', # we want to disable audio processing (there is no audio)
'-f', 'image2pipe', '-']
pipe = sp.Popen(command, stdout = sp.PIPE, bufsize=10**8)
while True:
# Capture frame-by-frame
raw_image = pipe.stdout.read(640*480*3)
# transform the byte read into a numpy array
image = numpy.fromstring(raw_image, dtype='uint8')
image = image.reshape((480,640,3)) # Notice how height is specified first and then width
if image is not None:
analyse(image)...
pipe.stdout.flush()
有人知道如何执行此操作吗?
感谢您的回答。
tee
命令将stdin
复制到stdout
,并一路复制到您提到的任何其他文件:
ProcessThatWriteSTDOUT | tee SOMEFILE | ProcessThatReadsSTDIN
或制作两份副本:
ProcessThatWriteSTDOUT | tee FILE1 FILE2 | ProcessThatReadsSTDIN
您的nectcat
命令不是文件,而是一个过程。因此,您需要使您的流程看起来像一个文件-名为““流程替换”] >>,您可以这样操作:
ProcessThatWriteSTDOUT | tee >(SomeProcess) | ProcessThatReadsSTDIN
因此,要拍摄长篇故事,您需要更多类似的东西:
raspivid ... -fps 30-o - | tee >(nc PC_IP PORT) | streampipe