Videocapture failed to allocate buffers on release - V4l2src

I’m using a v4l2sink in gstreamer to tee a video stream that I can access in OpenCV. This works when I open the videocapture device and get frames, however at some point I want to release the capture device and reopen it later in the program. When I release the device, I get the following errors:

[ WARN:7] global /tmp/build_opencv/opencv/modules/videoio/src/cap_gstreamer.cpp (488) isPipelinePlaying OpenCV | GStreamer warning: unable to query pipeline state
[ WARN:7] global /tmp/build_opencv/opencv/modules/videoio/src/cap_gstreamer.cpp (1761) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Failed to allocate a buffer

I open the capture device like so:

cap = cv2.VideoCapture("v4l2src device=/dev/video3 ! nvvidconv ! video/x-raw(memory:NVMM) ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink drop=1 max-buffers=2")

release it like by using cap.release() and my gstreamer pipeline is:

"gst-launch-1.0 v4l2src device=/dev/video2 ! video/x-raw,format=YUY2,width=2560,height=720,framerate=60/1 ! tee name=t ! queue ! xvimagesink sync=0 brightness=50 t. ! queue ! v4l2sink device=/dev/video3"

I create the v4l2loopback device using:

sudo modprobe v4l2loopback video_nr=3 max_buffers=2

I had to specify max_buffers=2 because I was facing the same issue as this post: Gstreamer v4l2src failed to allocate buffer when run on a Jetson Nano where I got the failed to allocate buffers error at the start.

The main issue arises when I try to reopen the pipeline and capture device, because gstreamer gives me a reason not negotiated error

For this use-case, it would need other users to share experience. v4l2loopback is a 3rdparty software stack and may not work properly in certain cases.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.