Cap_gstreamer.cpp file not found

Good morning,

When using OpenCV (4.1.1) on a jetson AGX Xavier and implementing the cap_prop_fourcc command to alter the video streams format the following warning shows up and crashes the program:

It seems as if the file cap_gstreamer.cpp could not be located, which is very well possible as the automatically specified path shown in the image above does not exist. The particular file does exist somewhere else on the system however, though I am unable to find any possibility to change the path at which the file is searched.

I require the gstreamer property for the VideoWriter handle in OpenCV as OpenCV auto loads my webcam stream in YUYV format, and i require the webcams MJPG format.

Best regards,

Ruud

Hi,
After installation through SDKManager, there is an OpenCV 4.1.1 installed and it enabled gstreamer. You may try the default package.

Or you can re-install it by running the script:

1 Like

Hi @DaneLLL,

unfortunately this did not solve anything for me. I have attempted doing a fresh install prior as well, with no success however.

It did, however change the path at which it searches for the cap_gstreamer.cpp file. While the file is now present at the specified path I get exactly the same warning (unhandled property)

Hi,
Looks like the issue is not in building OpenCV but in running an OpenCV application? There is a sample demonstrating VideoCapture() and VideoWriter():


FYR.

Correct,

OpenCV builds fine, the program I am trying to run builds fine too.

With the following code I am able to launch my application (gstreamer warning still appears but doesnt kill the app):

However, once I remove the comment tags for the FOURCC format handler the application crashes.

My camera supports 1920x1080 in both YUYV and MJPG format (with a different framerate though).

If i run the following pipeline command in my terminal the image appears fine in the pop up window:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! image/jpeg, width=1920, height=1080, framerate=30/1, format=MJPG ! jpegdec ! xvimagesink

So it must be OpenCV related… I just can’t figure out how or what.

I have resolved my own issue after trying out several possibilities and stumbling on the solution.

In order to be able to change the format of the webcam image you need a different backend, OpenCV automatically loads the first backend it finds. When you ‘force’ this to be the V4L2 backend by changing the following line:

cap = new cv::VideoCapture(index, cv::CAP_V4L2);

The warnings dissapear and the image is processed properly.

@DaneLLL thank you very much for the quick responses and support today!


The first warning is normal. A live stream has no duration so current position cannot be computed.
The second says you are trying to set an unsupported property for this capture device.

It looks surprizing you are using videoWriter::fourcc for a video capture.
Anyway for a MJPG camera, you would use gstreamer API leveraging HW decoder rather than V4L API:

const char* gst_str = "v4l2src device=/dev/video0 ! image/jpeg, width=1920, height=1080, framerate=30/1, format=MJPG ! nvv4l2decoder mjpeg=1 ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink";
cv::VideoCapture cap(gst_str, cv::CAP_GSTREAMER);
if (!cap.isOpened ()) {
    std::cout << "Error: Cv::VideoCapture.open() failed" << std::endl;
    return 1;
}
else
    std::cout << "Cam opened  (backend: " << cap.getBackendName () << ")" << std::endl;

unsigned int width = cap.get (cv::CAP_PROP_FRAME_WIDTH);
unsigned int height = cap.get (cv::CAP_PROP_FRAME_HEIGHT);
float fps = cap.get (cv::CAP_PROP_FPS);
std::cout << " VideoCapture framing : " << width << " x " << height << "@" << fps << " FPS" << std::endl;

If this doesn’t work, try adding jpegparse between v4l2src and nvv4l2decoder.
If it works but with low framerate, try adding option io-mode=2 to v4l2src.

1 Like