I have PC A & PC B. PC A is Raspberry Pi 3 b+, streaming video while open netcat listening port 8090 using this code:
PC B uses MPlayer to connect to PC A Port 8090 and open up the Video Stream, output is really awesome with low latency, the command:
But the thing is:
-> 1, Is there any Python lib or code can help me catch the streaming video and pipe it into GUI ? So i can add some info on my GUI while display the Video on background.
-> 2, Is there anyway to use the Mplayer as embed output inside my GUI? And then I can editing my GUI as I want and the video stream is playing on the background.
After a day, I've figured out the Solution for this.
For anyone who looking Solution, this will be your write-ups:
mkFIFO264.sh
#!/bin/bash
if [ -p fifo264 ]
then
rm fifo264
fi
mkfifo fifo264
nc -l -v -p <port> > fifo264
getStreamData.py
import numpy as np
import cv2
cap = cv2.VideoCapture('fifo264')
while(cap.isOpened()):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('< DroneName >',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
PC A (Raspberry Pi 3 Stream Server): You create a .sh file with this code:
#!/bin/bash
raspivid -t 0 -w <video_width> -h <video_height> -hf -ih -fps 60 -o - | nc <PC-B_IP> <port>