# Cannot get USB cam to work in jetpack docker

**URL:** <https://forums.developer.nvidia.com/t/cannot-get-usb-cam-to-work-in-jetpack-docker/175686>\
**Category:** Jetson Nano\
**Tags:** docker, camera\
**Created:** [April 19, 2021, 7:41pm UTC](https://forums.developer.nvidia.com/t/cannot-get-usb-cam-to-work-in-jetpack-docker/175686 "2021-04-19T19:41:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradpr](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@bradpr](https://forums.developer.nvidia.com/u/bradpr)\
**Post date:** [April 19, 2021, 7:41pm UTC](https://forums.developer.nvidia.com/t/cannot-get-usb-cam-to-work-in-jetpack-docker/175686/1 "2021-04-19T19:41:20Z")

</div>

Hi  
Its been asked a million times, but none of the existing threads got my cam working.

SW version/tag:v2.0.1-r32.5.1

I’m going through the introductory courseware for a second time.

My first time throug, was able to get everything working on the CSI Pi ribbon camera, but when I try from my USB webcam, I get the following:

!ls -ltrh /dev/video\*  
crw-rw---- 1 root video 81, 0 Apr 19 19:20 /dev/video0

from jetcam.usb\_camera import USBCamera

#TODO change capture\_device if incorrect for your system  
camera = USBCamera(width=224, height=224, capture\_width=640, capture\_height=480, capture\_device=0)

* * *

RuntimeError Traceback (most recent call last)  
/usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/usb\_camera.py in **init** (self, \*args, \*\*kwargs)  
23 if not re:  
—\> 24 raise RuntimeError(‘Could not read image from camera.’)  
25

RuntimeError: Could not read image from camera.

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last)  
 in   
2  
3 #TODO change capture\_device if incorrect for your system  
----\> 4 camera = USBCamera(width=224, height=224, capture\_width=640, capture\_height=480, capture\_device=0)

/usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/usb\_camera.py in **init** (self, \*args, \*\*kwargs)  
26 except:  
27 raise RuntimeError(  
—\> 28 ‘Could not initialize camera. Please see error trace.’)  
29  
30 atexit.register(self.cap.release)

RuntimeError: Could not initialize camera. Please see error trace.

I ran the following to get info on my cam:

v4l2-ctl -d /dev/video0 --list-formats-ext

ioctl: VIDIOC\_ENUM\_FMT  
Index : 0  
Type : Video Capture  
Pixel Format: ‘MJPG’ (compressed)  
Name : Motion-JPEG  
Size: Discrete 1920x1080  
Interval: Discrete 0.040s (25.000 fps)  
Size: Discrete 3840x2160  
Interval: Discrete 0.040s (25.000 fps)  
Interval: Discrete 0.050s (20.000 fps)  
Interval: Discrete 0.067s (15.000 fps)  
Interval: Discrete 0.100s (10.000 fps)  
Interval: Discrete 0.200s (5.000 fps)  
Size: Discrete 3264x1836  
Interval: Discrete 0.040s (25.000 fps)  
Size: Discrete 2592x1944  
Interval: Discrete 0.040s (25.000 fps)  
Size: Discrete 2048x1536  
Interval: Discrete 0.040s (25.000 fps)  
Size: Discrete 1280x720  
Interval: Discrete 0.040s (25.000 fps)  
Size: Discrete 800x600  
Interval: Discrete 0.040s (25.000 fps)  
Size: Discrete 640x480  
Interval: Discrete 0.040s (25.000 fps)  
Size: Discrete 320x240  
Interval: Discrete 0.040s (25.000 fps)

```
    Index : 1
    Type : Video Capture
    Pixel Format: 'YUYV'
    Name : YUYV 4:2:2
            Size: Discrete 1280x720
                    Interval: Discrete 0.100s (10.000 fps)
            Size: Discrete 800x600
                    Interval: Discrete 0.050s (20.000 fps)
            Size: Discrete 640x480
                    Interval: Discrete 0.040s (25.000 fps)
            Size: Discrete 320x240
                    Interval: Discrete 0.040s (25.000 fps)

```

I was really pleased I got the CSI device to work without any fuss, but this USB cam is a real pain.  
Any help is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [April 20, 2021, 3:38am UTC](https://forums.developer.nvidia.com/t/cannot-get-usb-cam-to-work-in-jetpack-docker/175686/3 "2021-04-20T03:38:48Z")

</div>

Hi,  
It looks like you need to set _framerate_. The gstreamer string is  
[jetcam/usb\_camera.py at master · NVIDIA-AI-IOT/jetcam · GitHub](https://github.com/NVIDIA-AI-IOT/jetcam/blob/master/jetcam/usb_camera.py)

```auto
'v4l2src device=/dev/video{} ! video/x-raw, width=(int){}, height=(int){}, framerate=(fraction){}/1 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink'.format(self.capture_device, self.capture_width, self.capture_height, self.capture_fps)

```

Please add _framerate_ and try again.

---

<div class="post-metadata">

**Author:** ![bradpr](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@bradpr](https://forums.developer.nvidia.com/u/bradpr)\
**Post date:** [April 20, 2021, 7:45pm UTC](https://forums.developer.nvidia.com/t/cannot-get-usb-cam-to-work-in-jetpack-docker/175686/4 "2021-04-20T19:45:35Z")

</div>

Thank you, DaneLLL  
I have a few follow-ups

1. How were you able to determine that this is what was causing the failure?
2. That looks like the code line from usb\_camera.py, so do I define framerate as a property when defining camera= in the notebook code? I attempted adding “framerate=x/1” to the camera= line in the notebook, trying 20,25, and 30 for x. None of those worked.
3. I’ve noticed if I try to run any v4l2src commands from a shell running in the docker, it doesn’t work, but it is recognized by my host. I’m not familiar enough with docker containers to know if anything need to happen to extend v4l2src to the container

Thanks

---

<div class="post-metadata">

**Author:** ![bradpr](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@bradpr](https://forums.developer.nvidia.com/u/bradpr)\
**Post date:** [April 20, 2021, 8:17pm UTC](https://forums.developer.nvidia.com/t/cannot-get-usb-cam-to-work-in-jetpack-docker/175686/5 "2021-04-20T20:17:50Z")

</div>

One other item, Cheese does recognize the camera. Can I leverage the information that Cheese has to make it work under the docker image?

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [April 20, 2021, 8:30pm UTC](https://forums.developer.nvidia.com/t/cannot-get-usb-cam-to-work-in-jetpack-docker/175686/6 "2021-04-20T20:30:28Z")

</div>

About cheese failure, you may check [this](https://forums.developer.nvidia.com/t/libv4l2-nvargus-so-source-code/168303/19).

---

<div class="post-metadata">

**Author:** ![bradpr](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@bradpr](https://forums.developer.nvidia.com/u/bradpr)\
**Post date:** [April 29, 2021, 3:25am UTC](https://forums.developer.nvidia.com/t/cannot-get-usb-cam-to-work-in-jetpack-docker/175686/8 "2021-04-29T03:25:58Z")

</div>

Adding framerate didn’t help. I began digging deeper into gstreamer, but ultimately decided to just buy a logitech usb cam. I’d like to troubleshoot this, but it looks like more trouble than its worth.

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [April 29, 2021, 6:51pm UTC](https://forums.developer.nvidia.com/t/cannot-get-usb-cam-to-work-in-jetpack-docker/175686/9 "2021-04-29T18:51:34Z")

</div>

You may try to see if you can just display your camera with gstreamer.  
Be sure you have at least USB2 speed for your camera using `lsusb -t`.  
Better try without any other USB device than mouse and keyboard.  
Be aware that if going through a lower speed USB hub, that will limit your camera speed.  
Be sure to have enough power supply for the camera.

From the logs above, your camera can provide MJPEG or YUYV 4:2:2. Let’s first try the lowest resolution and framerate.

```auto
# Raw mode YUYV 4:2:2, using YUY2 format for gstreamer
gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, format=YUY2, width=320, height=240, framerate=25/1 ! xvimagesink

# MJPEG mode
gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg, width=320, height=240, framerate=25/1 ! jpegparse ! nvv4l2decoder mjpeg=1 ! nvvidconv ! xvimagesink

```

---

<div class="post-metadata">

**Author:** ![nadeemm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nadeemm/32/367020_2.png) [@nadeemm](https://forums.developer.nvidia.com/u/nadeemm)\
**Post date:** [October 15, 2021, 3:37am UTC](https://forums.developer.nvidia.com/t/cannot-get-usb-cam-to-work-in-jetpack-docker/175686/10 "2021-10-15T03:37:27Z")

</div>

Closed on October 15, 2021, 3:37am UTC


