How to compress webcam stream


#1

We are using the Logitech C920 webcam for our driver camera this year and when we view it on smart dashboard, the stream is crisp and clear, but this is because it’s using a whole 14 Mbps of bandwidth! Is there any way we can compress the video stream in Java? We already checked the BW limit box when flashing our radio, but it doesn’t seem to be doing anything.


#2

Try updating the Radio Configuration Utility if you haven’t already. I think this was a bug that was fixed in one of the recent versions of the tool.

I’m guessing you’re using a USBCamera instance? Try camera.setVideoMode(VideoMode.PixelFormat.kMJPEG, WIDTH, HEIGHT, FPS);. (MJPEG is the default for the first parameter and the only thing the FIRST dashboards support AFAIK.)


#3

The setVideoMode function sets the camera configuration. While the stream to the FIRST dashboards is always MJPEG, the camera itself may run in YUYV or MJPEG capture mode. While you can set different compression (e.g. JPEG quality) than the camera itself provides through various means (e.g. slider on the Shuffleboard dashboard or set via code), you will see increased latency and dramatically increased CPU usage because the compression will be performed by software. Your best bet to decrease bandwidth is to run at the lowest resolution and FPS you can tolerate.


#4

Updating the radio configuration utility fixed the bandwidth limit not being in effect, but now we’re getting 1 fps at 640x360 using about .65 Mbps. What would be the best way to bring the fps up?


#5

I would also recommend converting your stream to the DS to black and white since color is not really necessary. One thing that I found with the WPILIB CameraServer and the c920 is that you need to set the size of the stream to be 640x360 or higher or else it will not work. Instead, we are for now using the LifeCam which has no problem going a lower size which allows us to get more frames. For our next comp though, we are creating an HTML stream on our rpi for the c920. Also, I am trying to take advantage of the built-in h264 encoding but there are scarce resources on that. In short, I’d recommend using greyscale for your DS stream and not using the c920 with the WPILIB stuff because of the issue I stated earlier.


#6

We actually found out a weird bug over the last competition. Our Windows 7 driverstation laptops don’t know how to handle the USB web cam stream in shuffleboard.

We would get about the same, 3-5 fps, at 320x240 resolution. An image so pixelated you could only sort of make out colors. In our competition, those laptops had a hard time connecting to the field as well.

We swapped it out for a Windows 10 (low-end HP laptop), and our stream was 640x480 at 22-25fps and just under 1mbps bandwidth.

No other changes, just a different network stack seemed to do better.


#7

I almost forgot to mention, you don’t need hd for FRC uses. Use something a lot smalller like 320x240.


#8

What camera are you guys using?


#9

Lifecams.