Reputation: 2028
There are delays in my gstreamer pipeline using OpenCV. I want to read rtsp stream, get frames, modify them and then output in a new rtsp/tcp/udp streams.
Delay results that produces my pipeline in opencv:
The code below reads rtsp stream and output to tcp these frames. But OpenCV gives me delay during streaming rtsp camera example as well as using videotestsrc. Can someone help and explain what to do with my pipeline to make it work as fast as possible?
I want to get speed compared to gst-launch. There are no artifacts with delay and slowing using gst-launch compared to OpenCV
gst-launch-1.0 -v rtspsrc location=rtsp://170.93.143.139/rtplive/470011e600ef003a004ee33696235daa ! decodebin ! videoconvert ! x264enc ! mpegtsmux ! tcpserversink port=8554 host=0.0.0.0
P.S This is the only one working pipeline that I could get with free rtsp camera. btw, I could not stream into rtsp, only to tcp
import cv2
import time
cap = cv2.VideoCapture('rtspsrc location=rtsp://170.93.143.139/rtplive/470011e600ef003a004ee33696235daa ! decodebin ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
f_width = int(cap.get(3))
f_height = int(cap.get(4))
f_fps = int(cap.get(5))
print(f_width, f_height, f_fps)
out = cv2.VideoWriter('appsrc ! videoconvert ! x264enc ! mpegtsmux ! tcpserversink port=8554 host=0.0.0.0', cv2.CAP_GSTREAMER,0, 20, (f_width,f_height), True)
while cap.isOpened():
read_start = time.time()
ret, frame = cap.read()
read_end = time.time() - read_start
print('read:', read_end)
print(ret)
if ret:
out_start = time.time()
out.write(frame)
out_wtite = time.time() - out_start
print('write', out_wtite)
print('-'*10)
cap.release()
out.release()
The speed results on my PC for cap read and write.
----------
read: 0.06638693809509277
write 0.00010824203491210938
----------
read: 0.06541061401367188
write 0.00011515617370605469
----------
read: 0.06638312339782715
write 0.00010037422180175781
----------
read: 0.06667900085449219
write 0.00010275840759277344
----------
read: 0.066192626953125
write 0.00012063980102539062
----------
read: 0.06572628021240234
write 9.441375732421875e-05
----------
read: 0.0661618709564209
write 0.00011110305786132812
Thanks for any help and suggestions.
Upvotes: 0
Views: 3076
Reputation: 2028
I have found the solution: Just minimize x264enc bitrate and minimize writing fps and all works as a charm. Believe it'll help someone
Upvotes: 3