0

I'm streaming a video from a Raspberry Pi over a gstreamer pipeline. I read this stream on a desktop using OpenCV and gstreamer. Everything works great, except that the receiver does not know when the stream is finished.

The receiver code is essentially the same as in convert gstreamer pipeline to opencv in python

My problem is if I don't quit the receiver by typing 'q', cap_receive.read() never seems to return False as its retval when the sender is done.

gst_str_simple = "udpsrc port=5000 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! avdec_h264 ! videoconvert ! appsink"

recv_cap = cv2.VideoCapture(gst_str_simple, cv2.CAP_GSTREAMER)

if not recv_cap.isOpened():
    print('VideoCapture not opened')
    exit(0)

while True:
    ret, frame = recv_cap.read()

    if not ret:
        print('empty frame')
        break

    cv2.imshow('receive', frame)
    if cv2.waitKey(1)&0xFF == ord('q'):
        break

recv_cap.release()

Can I write an empty frame at the sender to make this happen? Or any other way to make the receiver terminate automatically? Maybe a timeout?

Thanks

cbasavaraj
  • 105
  • 1
  • 5

2 Answers2

0

Solution :

  1. RTP or Media Inactivity Timers/Timeout Create a Timer and terminate the call after some interval if you are not receiving any data from the network.

  2. RTCP BYE - msg handling (https://www.freesoft.org/CIE/RFC/1889/32.htm) Make sure your Server is supporting RTCP protocol.

mail2subhajit
  • 1,106
  • 5
  • 16
0

if anyone looks at this, there was a simple solution I didn't think of earlier. I still don't know when the stream terminates by looking at the cv2 cap (recv_cap), but as I am using http requests between the Pi and the desktop anyway, once I receive a 'finish' message from the Pi, I just set a self.done = True in the main thread (note: the receiver is being run as a separate thread.), and exit the loop on this condition.

cbasavaraj
  • 105
  • 1
  • 5