B0321 camera gets ~13 FPS instead of 30 at 640x480 with OpenCV V4L2

Hi all, I’m stuck on a framerate issue with a B0321 module and hoping someone here has seen it.

At 640x480 I’m only getting around 13 fps, but with the same code I should be getting 30 fps. I tested the exact same code on B0292 and B0196 modules and those both hit ~30 fps. So I don’t think it’s the sensor — it looks more like the timing system on the B0321 chip. For reference, I understand the B0321 is basically the same as the B0292 apart from the extension cable.

Environment:

  • OpenCV (cv2) with the CAP_V4L2 backend
  • Modules: B0321 (problem), B0292 and B0196 (both fine)
  • Sensor: IMX219 8MP autofocus USB2.0 module
  • Resolution of interest: 640x480

Here’s the reproduction code I’m using:

import cv2
import time
# open video0
# cap = cv2.VideoCapture(2,cv2.CAP_GSTREAMER)
# cap = cv2.VideoCapture(2,cv2.CAP_FFMPEG)
cap = cv2.VideoCapture(2, cv2.CAP_V4L2)
# The control range can be viewed through v4l2-ctl -L
# print(cap.set(cv2.CAP_PROP_BRIGHTNESS, 64))
# print(cap.set(cv2.CAP_PROP_CONTRAST, 0))

cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
# cap.set(cv2.CV_CAP_PROP_FOURCC, cv2.CV_FOURCC('M', 'J', 'P', 'G'))

codec_code = cap.get(cv2.CAP_PROP_FOURCC)
print(codec_code)

print(cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640))
print(cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480))

# time.sleep(2)
print(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
print(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(cap.set(cv2.CAP_PROP_FPS, 30))

print(cap.set(cv2.CAP_PROP_AUTOFOCUS, 1))
# time.sleep(2)
print(cap.set(cv2.CAP_PROP_AUTOFOCUS, 0))
# time.sleep(2)

print(cap.get(cv2.CAP_PROP_AUTOFOCUS))

# print(cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 3))
# time.sleep(2)

print(cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1))
# It depends on the capture api you are using. If you are using CAP_V4L2, then automatic exposure is set to 'on' with value 3 and 'off' with value 1.
print(cap.set(cv2.CAP_PROP_EXPOSURE, 157))
print(cap.get(cv2.CAP_PROP_AUTO_EXPOSURE))
print(cap.get(cv2.CAP_PROP_EXPOSURE))
time.sleep(2)

print(cap.set(cv2.CAP_PROP_AUTO_WB , 0))
# time.sleep(2)

print(cap.get(cv2.CAP_PROP_AUTO_WB ))

# used to record the time when we processed last frame
prev_frame_time = 0

# used to record the time at which we processed current frame
new_frame_time = 0

while (True):
    ret, frame = cap.read()

    font = cv2.FONT_HERSHEY_SIMPLEX
    new_frame_time = time.time()
    fps = 1/(new_frame_time-prev_frame_time)
    prev_frame_time = new_frame_time
    fps = int(fps)
    fps = str(fps)
    cv2.putText(frame, fps, (7, 70), font, 3, (100, 255, 0), 3, cv2.LINE_AA)

    cv2.imshow('frame', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

Is this fixable on my end (firmware/settings), or is it something specific to this module? Any ideas would be appreciated.

Thanks for the detailed report — the fact that the same code and same settings give ~30 fps on B0292/B0196 but ~13 fps on B0321 is a strong signal, so let’s narrow it down.

A couple of quick questions first:

  • Can you confirm the device node you’re opening in the failing case (/dev/video2 in your snippet)?
  • What does v4l2-ctl -d /dev/video2 -L show for the controls?
  • What fps do you see if you request MJPEG + 640x480 with v4l2-ctl directly, bypassing OpenCV entirely? That helps separate an OpenCV/V4L2 negotiation issue from a module-side one.

Also, one thing to try: there’s a firmware build that targets timing/framerate behavior on these modules. I’ve sent you the firmware package through private message — please check it and try the update.

Start with those and let us know what you see.

OK, tried the firmware. Unfortunately it did not solve the problem — I’m still getting around 13 fps instead of 30.

To recap what I’m seeing: with this B0321 module I get ~13 fps at 640x480, but with the same code on B0292 and B0196 I get ~30 fps. That’s why I keep thinking it’s the timing system on the B0321 rather than the sensor.

Here’s the v4l2-ctl -L output for the controls:

$ v4l2-ctl -d /dev/video2 -L
User Controls

   brightness 0x00980900 (int)    : min=0 max=255 step=1 default=128 value=128
   contrast 0x00980901 (int)    : min=0 max=255 step=1 default=128 value=128
Camera Controls

   auto_exposure 0x009a0901 (menu)   : min=0 max=3 default=3 value=1 (Manual Mode)
   exposure_time_absolute 0x009a0902 (int)    : min=1 max=5000 step=1 default=156 value=157
   auto_exposure_bias 0x009a0903 (int)    : min=-4 max=4 step=1 default=0 value=0
   auto_focus 0x009a090c (bool)   : default=1 value=0
   focus_absolute 0x009a090a (int)    : min=0 max=1023 step=1 default=0 value=0

Anything else you want me to test? I was hoping the firmware would fix it, but no luck so far.

Thanks for sticking with it. Since the firmware didn’t change anything, let’s get the raw capability report from the driver — this is usually the most revealing:

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

And please also try a capture that skips OpenCV completely, e.g.:

v4l2-ctl -d /dev/video2 --set-fmt-video=width=640,height=480,pixelformat=MJPG --stream-mmap --stream-count=120 --stream-to=/dev/null --verbose

The reported fps in that --verbose output is generated by the driver itself. If the driver also reports ~13 fps there, we can rule out OpenCV, and if the formats list claims 30 fps for 640x480 MJPG then we have a mismatch between what the module advertises and what it actually delivers.

Paste both outputs and we’ll go from there.

Here’s the --list-formats-ext output for the B0321:

$ v4l2-ctl -d /dev/video2 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
	Type: Video Capture

	[0]: 'MJPG' (Motion-JPEG, compressed)
		Size: Discrete 640x480
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 3264x2448
			Interval: Discrete 0.066s (15.000 fps)
	[1]: 'YUYV' (YUYV 4:2:2)
		Size: Discrete 640x480
			Interval: Discrete 0.100s (10.000 fps)

So the driver claims 30 fps at 640x480 MJPG. But when I do the raw v4l2 capture:

$ v4l2-ctl -d /dev/video2 --set-fmt-video=width=640,height=480,pixelformat=MJPG --stream-mmap --stream-count=120 --stream-to=/dev/null --verbose
>>> streaming starts ...
	120 frames in ~9.2s  (~13.0 fps)

It reports ~13 fps — same as OpenCV. So it’s not OpenCV. Same command on the B0292 gives ~30 fps.

Quick extra data point: I re-ran the raw v4l2 capture a few times on the B0321 and it’s consistently ~13 fps (12.8–13.2). Same command on B0292 at 640x480 MJPG is ~30 fps every time. Nothing in userspace is different — just the module.

That’s really useful. Since both OpenCV and raw v4l2 agree at ~13 fps, and the formats list advertises 30 fps, this points at the module/driver side rather than anything in your capture code.

A few more things worth ruling out before we conclude it’s the module:

  1. Swap the B0321 onto a different USB port/host (preferably a direct port, not a hub) — extension cables + hubs can sometimes cause enough retries to drag MJPEG delivery down.
  2. Re-run the raw v4l2 capture at 640x480 YUYV and at 1280x720 MJPG. If 1280x720 MJPG also comes in around ~13, that’s a module-wide behavior, not a 640x480-only quirk.
  3. If you have it, test the B0321 board with a shorter/different extension cable if that’s mechanically possible — since the extension cable is the main difference from the B0292.

Can you try those and post the numbers?

Tried the suggestions:

  1. Different USB port (direct, no hub): still ~13 fps, no change.
  2. Raw v4l2 captures:
    • 640x480 MJPG: ~13 fps
    • 1280x720 MJPG: ~13 fps
    • 640x480 YUYV: ~10 fps (matches the advertised 10 fps for YUYV)
  3. I can’t easily swap the extension cable — it’s fixed to this module.

So basically every MJPEG mode on this B0321 tops out around 13 fps no matter the resolution, while YUYV matches its advertised rate. B0292 and B0196 give ~30 fps in MJPEG with the identical code and identical control settings. I’m fairly convinced this unit’s timing/framerate is off.

Thanks — that gives us a pretty clear picture, so here’s the current summary of where we’ve landed:

What we established:

  • The B0321 delivers ~13 fps in MJPEG (640x480 and 1280x720), while --list-formats-ext advertises 30 fps for those modes.
  • The same behavior shows up both through OpenCV (CAP_V4L2) and through raw v4l2-ctl --stream-mmap, so the capture code, FourCC, resolution, FPS, autofocus/exposure/WB settings are not the cause.
  • Identical settings on B0292 and B0196 give ~30 fps, so the difference tracks the module itself, not the sensor or the software.
  • The firmware update did not change the framerate — still ~13 fps.
  • MJPEG is affected across resolutions; YUYV matches its advertised 10 fps, so it looks specific to the MJPEG/timing path rather than a global USB throughput cap.

Conclusion so far: this looks like a module-side timing/framerate issue on this particular B0321 rather than anything fixable in software or settings. Since the firmware didn’t resolve it and the other modules behave correctly, there isn’t a userspace workaround we can offer right now.

I’ve sent you a follow-up through private message so we can take this further with the hardware team. If you get any additional numbers (for example a re-test after swapping cables or hosts), please post them here and we’ll update the thread.