OpenCV + GStreamer: Error pushing buffer to GStreamer pipeline

Viewed 478

I am using OpenCV to capture a frame from a v4l2 camera (on a RaspberryPi 4), process it, and then stream it to tcp://0.0.0.0:7000 using GStreamer. This is the call to VideoWriter:

stream_writer = cv2.VideoWriter(
    'appsrc ! videoconvert ! ' \
    'v4l2h264enc extra-controls="controls,video_bitrate_mode=0" ! ' \
    'video/x-h264,level=(string)4 ! h264parse ! matroskamux ! ' \
    'tcpserversink host=0.0.0.0 port=7000 ',
    cv2.CAP_GSTREAMER,
    0,
    25,
    (640, 480)
)

When writing I just do a simple stream_writer.write(frame).

The stream would perfectly if it wouldn't break every so often. This could be after an hour or a few days. This is the error I get:

[ WARN:0] global /tmp/opencv-4.4.0/modules/videoio/src/cap_gstreamer.cpp (1665) writeFrame OpenCV | GStreamer warning: Error pushing buffer to GStreamer pipeline

Because this happens so rarely I can't even properly debug the problem. I managed to get the error when I was in debug mode. There, calling stream_writer.isOpened() returned True. So I can't use this to try to restart the VideoWriter. Unfortunately I didn't manage to reproduce the error with GST_DEBUG=4 set, so I can't give more details.

I also tried to disconnect and reconnect the Pi from the network, to try to force the error. No avail. GStreamer reconnects even after a 5 minute network timeout.

I would be extremely grateful, if anyone has any idea on what would be the cause of the problem. Or even how to force it again, to inspect it further.

0 Answers
Related