USB camera frames freezes randomly in jetpack 6.2.1

Continuing the discussion from Select timeout error/warning when using usb camera:

Previously, I had found a workaround to almost eliminate the camera freeze issue while using orin nano jp 5.1.1. I had built opencv 4.5.4 with cuda and also modified the cap_v4l.cpp file to reduce the default select() timeout from 10s to 0.5s. This change made the video output almost undetectable when the camera freezes and I would immediately do self.cap.release() and then again self.cap.VideoCapture(‘/dev/video0’, cv2.CAP_V4L2) which was good workaround so that no one noticed the frame freeze(green color frame). The select(0 timeout issue was still present though!

Now we have procured new orin nano super with jp 6.2.1 and built opencv 4.10.0 the same way as i did for 4.5.4 in jp5.1.1 but, I’m facing the same issue(green screen) again even though the coding is same. My code continuously try to self.cap.release() and self.cap.VideoCapture(‘/dev/video0’, cv2.CAP_V4L2) when cap.read() doesnt return True.

I even tried using GSTREAMER (built with cuda in opencv 4.10.0) as :

device = “/dev/video0”
capture_width = 1920
capture_height = 1080
framerate = 30
self.pipeline = f’v4l2src device={device} ! video/x-raw, width={capture_width}, height={capture_height}, framerate={framerate}/1, format=(string)YUY2 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink’
self.cap = cv2.VideoCapture(self.pipeline, cv2.CAP_GSTREAMER)

but, even this leads to same issue. The video freezes at random times (can’t predict when or no known patterns found).
Below is the error from pycharm terminal. Im printing cap object released when i dont get frames from self.cap.read() and then reinitialise the videocapture object.


sudo dmesg:


Note: Using GSTREAMER pipeline is causing higher CPU consumption on all 6 cores than using v4l library. So, I dont want to try any workaround using GSTREAMER.

Note: Camera is connected to dev kit directly on USB port (only 1 camera we are using).

Cam details:


nvidia@nvidia-desktop:~$ v4l2-ctl --device=/dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture

[0]: 'YUYV' (YUYV 4:2:2)
	Size: Discrete 1920x1080
		Interval: Discrete 0.033s (30.000 fps)

Cam freeze video:

The error select() timeout kiran shows the opencv is my custom built from source! Not the regular one from pycharm or jetson pre-installed.


This time I need complete solution or at least a proper workaround. Else the procurement of new orin supers will be impacted for us losing our market competitions.

Please help. Happy to debug anything.

Thanks in advance.

Hi,
Please try

$ gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw, width=1920, height=1080, framerate=30/1, format=(string)YUY2" ! videoconvert ! "video/x-raw, format=(string)BGR" ! fakesink sync=0

The nvvidconv plugin is to convert video/x-raw to video/x-raw(memory:NVMM), or video/x-raw(memory:NVMM) to video/x-raw. It is not required in the pipeline.

Hi, I tried using the command:

It’s just running and I don’t know what we are trying to find out in this? Can you share a python code which actually shows video frames as well as any logs printing in terminal? That’d be good to investigate I mean if you are trying to see the root cause of this issue! When I get green screen, the camera controls were working fine. I had forgot to mention it. I have the zoom in and out button which when clicked zooms the camera lens IN / OUT but no video frames :(

Recent update

It stopped running after 1hr 16mins:
nvidia@nvidia-desktop:~$ gst-launch-1.0 v4l2src device=/dev/video0 ! “video/x-raw, width=1920, height=1080, framerate=30/1, format=(string)YUY2” ! videoconvert ! “video/x-raw, format=(string)BGR” ! fakesink sync=0
Setting pipeline to PAUSED …
Pipeline is live and does not need PREROLL …
Pipeline is PREROLLED …
Setting pipeline to PLAYING …
New clock: GstSystemClock
Redistribute latency…
1:16:32.7 / 99:99:99.:99.

Pls help !!! @DaneLLL

@DaneLLL I strongly suggest that my issue might be an issue described in this post E-con Systems See3CAM_CU135M freezing on Jetson Orin Nano - #12 by ShaneCCC

Can you please confirm and also let me know if I need to rebuild the uvc module again with exact building steps.

Hi,
The UVC driver is from upstream kernel so it is supposed to work well. You may apply the gstreamer pipeline to the sample and check if you can see camera preview:
V4l2src using OpenCV Gstreamer is not working in Jetson Xavier NX - #3 by DaneLLL

If the gst-launch-1.0 command works, the sample is supposed to work as well by replacing fakesink with appsink.

Thanks — I’ve already tested with gst-launch-1.0 . The problem still occurs after ~30–50 minutes of streaming, even without OpenCV. GST_DEBUG=3 shows truncated buffer and field = ANY warnings.

Other users reported this is resolved by rebuilding uvcvideo.ko with higher values for UVC_URBS and UVC_MAX_PACKETS. Can you confirm if JetPack 6.2.1 has these values tuned for high-bandwidth UVC cameras? I’m about to rebuild uvcvideo.ko now!!!

Hi,
We don’t touch upstream kernel. If you would like to customize kernel, please refer to

Kernel Customization — NVIDIA Jetson Linux Developer Guide

No data from Joystick Logitech-f710 - #10 by DaneLLL

Hi, i tried rebuilding the uvcvideo.ko kernel module by increasing UVC_URBS and UVC_MAX_PACKETS size to 100 and 64 respectively and it worked.

Not sure why those values are very less in linux OS not only in jetson but x86_64 arch also. Pls increase the default values in upcoming jetpacks.

To all those who are encountering frame freezing / select() timeout warning in opencv while using any HD/4K USB cameras, the above is the solution.

Thanks! like if my solution solved yours.