Webcam Lag while using Octoprint - Could Use Some Help!

Logitech C922

The live video works but lags 6 to 8 seconds only while viewing through Octoprint. There is no noticeable lag when live-viewing with an Logitech app (e.g., Logitech G Hub). Note: I have tested and do not have a lag when using the raspberry pi camera (v2.1).

Tried different resolutions, searched this forum for solution, upgraded from Raspberry Pi 3B+ to 4B (4 gb), reinstalled Octoprint. Currently using 1280x720 at 15 fps.

Logs octoprint log.log (98.4 KB) **)

**Octoprint version 1.4.0

I am wondering if there are some commands I could do with SSH in Octoprint to better configure this web cam with Octoprint. I am very new to SSH but am starting to play around with it and thought there might be a solution to my issue.

I guess your camera is running in YUV mode which causes higher cpu load and needs more processing.

Enter v4l2-ctl --list-formats in ssh and post the output here. Maybe we can change something to make it more responsive.

I am in the middle of a long print job ( due to finish about 2:00AM). As soon as I finish, I will ssh into Octoprint and let you know what mode I am running (tomorrow morning). Thanks!

Robert Ray

Now I have to show you how inexperienced I am in SSH commands. I use PuTTY to log in to SSH. After putting in my username and password, the command line starts with 'pi@ octopi'. When I type in "v4l2-ctl --list-formats" in SSH, it tells me 'command not found'. I tried adding 'sudo' in front and it said the same thing. I tried "nano mjpg-streamer/start.sh" (suggested by an article concerning making adjustments to the camera focus). It gave me a new command line but when I typed in either "v4l2-ctl --list-formats" or "sudo v4l2-ctl --list-formats", it still said 'command not found'. I just do not know my way around this SSH environment yet. So could you please elaborate a bit more on what I need to type in and if I need to CD into something else first. Sorry for the confusion.

I'm having a hard time determining if its the letter I (v4I2), the lowercase letter L or the numeral 1 (v412) in these posts.

v4l2-ctl is a command inside the package named v4l-utils. To install it, use:

sudo apt-get install v4l-utils

If the package is already installed, apt-get will tell you.

nano mjpg-streamer/start.sh

This should open the nano editor with the file displayed at the top of the screen and some command hints at the bottom. To exit nano, type ctrl-X (that's the ctrl key and the X key at the same time). If you made changes to the file, use ctrl-O to write out the changes first.

When you login with PuTTY using the username pi and the password raspberry or the password you changed it to, you are in the home directory for the user pi. Use pwd to print your working directory. Use cd ~ to return to this home directory if you have wandered off somewhere else. Use ls, ls -l, or ls -la to see the files in the current directory (those are lowercase letter L).

Thanks for the tips! When I entered v4l2-ctl --list-formats, I got the following output:
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture
[0]: 'YUYV' (YUYV 4:2:2)
[1]: 'MJPG' (Motion-JPEG, compressed)

Hope this is what you were asking for. Let me know what you think I should do. Thanks again!

From my reading, it appears I may be running in YUYV mode as PrintedWeezl suggested. Is there a way (command) that I can designate which mode I want to run through SSH in OctoPrint? Thanks.

Did you edit your octopi.txt in the boot partition?
If yes what did you write into the camera_usb_options line?

Sorry to hear you were sick. Thanks for the reply. Yes I did edit the octopi.txt file. I put “-r 1280x720 -f 20” on that line. I tried different settings but the result was always the same. I have attached a screenshot of that file in case you are curious about other settings.

It should run with mjpg then. If there were a -y it would use YUYV.
Maybe there is something to enforce mjpg. I'll ask around tomorrow and let you know then.

Thanks. It’s so weird. As far as I can tell, it only lags when using Octoprint. Using any other webcam software, it plays just fine.

Robert Ray

I got nothing new unfortunately.
Your camera should run in mjpg mode and I don't see any way to reduce the lag.
Maybe playing with the quality helps but I doubt it

Update: I'm not sure why but all of a sudden the camera is not lagging anymore. I really haven't made any changes but on my latest print, the camera is not lagging. Another mystery for the books. Thanks for your help. I have learned quite a bit more about configuring this camera and how it works with Octopi while playing with your suggestions.

Well at least it works now :woman_shrugging:
You're welcome :slight_smile: