freezing when reading from gstreamer

asked 2020-07-14 14:00:42 -0500


I've recently encountered an issue where the function seems to freeze when reading a gstreamer pipeline. The stream seems to work in a glitchy manner for a few seconds, then it freezes completely. After debugging a bit I found it always freezes on the line.

The capture line is:

cap_receive = cv2.VideoCapture('udpsrc port=5004 caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)MP4V-ES" ! rtpmp4vdepay ! decodebin ! videoconvert ! appsink', cv2.CAP_GSTREAMER)

The while loop where I read and process the frames (there was more image processing but even this simple code still 'breaks'):

while (cap_receive.isOpened()):

    status, frame =

    if not status:
        print('empty frame')

    timestamp =
    cv2.putText(frame, timestamp.strftime(
        "%A %d %B %Y %I:%M:%S%p"), (10, frame.shape[0] - 10),
                cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1)

    (flag, encodedImage) = cv2.imencode(".jpg", frame)

    if not flag:

    yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' +
           bytearray(encodedImage) + b'\r\n')

This works fine on a windows PC capturing directly from webcam (cv2.VideoCapture(0)), but it doesn't work when trying to capture from the gstreamer pipeline on a microcontroller running Debian 10.4. My opencv version is 4.1.0

Anyone else encounter this issue or know any workarounds? I also tried 'grab' and 'retrieve' with the same results.

edit retag flag offensive close merge delete


I don't know, but while it freezes on that line, things may have failed elsewhere. I'd try without the yield command

mvuori gravatar imagemvuori ( 2020-07-15 08:46:19 -0500 )edit