The goal is to stream video from a Raspberry Pi (Raspivid/H.264) over the network and into an OpenCV application running on a laptop.
The open CV capture is as follows (C++):
cv::VideoCapture cap;
cap.open("cam_1"); // cam_1 is a FIFO
cv::Mat frame;
while(1){
cap >> frame;
cv::imshow("", frame);
cv::waitKey(10);
}
The FIFO Stream is created as follows:
mkfifo cam_1
Once the OpenCV program is running, the netcat listener is started:
ncat --recv-only --keep-open --verbose --listen 5001 > cam_1
Once the netcat listener is running on the laptop, the stream is started from the Raspberry Pi
raspivid --verbose --nopreview -b 2000000 --timeout 0 -o - | ncat 192.168.LAPTOP.IP 5001
or, for debugging purposes, a local file on the laptop can be streamed into netcat:
cat video.h264 | nc 192.168.LAPTOP.IP 5001
Both of which give the following error:
Unable to stop the stream: Inappropriate ioctl for device (ERROR)icvOpenAVI_XINE(): Unable to initialize video driver.
What is interesting is that if I start the Netcat listener on the laptop, then kill it with CTRL+C, and then start it again before starting the video stream, with either method... then the video plays properly.
I cannot figure out why starting the netcat listener and then killing it, and then starting again has an affect or what the affect is. I have considered that possibly I need to echo an EOF or BOF into the FIFO before the video, I am unsure of what that syntax would be.
I have tried all flavors of Netcat.