Code I am working with
Create video stream on raspberry pi:
Code: Select all
raspivid -fps 40 -h 1088 -w 1920 -n -t 0 -0 - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=192.168.1.124 port=5000
Code: Select all
import cv2
import time
import numpy as np
from threading import Thread
class VideoGet():
def __init__(self):
self.cap = cv2.VideoCapture('tcpclientsrc host=192.168.1.124 port=5000 ! gdpdepay ! rtph264depay ! \
decodebin ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
self.grabbed, self.frame = self.cap.read()
self.stopped = False
def start(self):
Thread(target=self.get, args=()).start()
return self
def get(self):
while not self.stopped:
if not self.grabbed:
self.stop()
else:
self.grabbed, self.frame = self.cap.read()
def stop(self):
self.stopped = True
def BarrelDistortion():
#define the distortion matrices here
def main():
cap = VideoGet().start()
gst_out = "appsrc ! videoconvert ! queue ! x264enc ! queue ! rtph264pay ! tcpserversink host=192.168.1.250 port=6000"
out = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, 40, (1920, 1088), True)
frames=[]
start = time.time()
BarrelDistortion()
while True:
frame = cap.frame
#apply the distortion to the frame, calling the processed frame dst
out.write(dst)
cv2.imshow("Test", dst)
frames.append(dst)
if cv2.waitKey(1) == 27:
break
cap.stop()
out.release()
cv2.destroyAllWindows()
stop=time.time()
print("FPS: ", str(len(frames) / (stop-start)))
if __name__ == "__main__":
main()
Code: Select all
gst-launch-1.0 -v tcpclientsrc host-192.168.1.250 port=6000 ! rtph264depay ! avdec_h264 ! video convert ! autovideosink sync=false
Code: Select all
ERROR: from element /GstPipeline:pipeline0/GstTCPClientSrc:tcpclientsrc0:
Internal data stream error.
Additional debug info:
gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:pipeline0/GstTCPClientSrc:tcpclientsrc0:
streaming stopped, reason error (-5)