Updated libcamera-vid has changed focus parameter

I updated my Pi OS today, which also requires updating the Arducam versions and the camera driver. I have the Hawkeye 64mp. Once updated, the camera is working again…but the focus controls have changed from what I formerly was able to use.

Formerly (before the upgrade), I used the following command to set the focus prior to running a live stream which was then fed to YouTube:
v4l2-ctl --device /dev/v4l-subdev1 --set-ctrl focus_absolute=400

“400” was a value I had determined through trial and error to give the sharpest image on my stream. This V4L2 control was working just fine, and it allowed me to modify the focus prior to starting a libcamera-vid stream. (In the libcamera-vid command, I would disable the auto-focus, so whatever value I set prior with the command above would remain active.)

However, AFTER this upgrade, “400” is completely out of focus! Has something changed in the driver or in the libcamera library that would cause this? Or has the “autofocus-mode” command changed in some way? I use that parameter to disable focus on the libcamera-vid startup.

1 Like

More info that might be helpful –

1). Prior to the update, when using the “v4l2-ctl” command on sub-device “v4l-subdev1”, I could set the “absolute_focus” as stated earlier, AND I could read back the value (with “get-ctrl”) to confirm that it worked. The returned value would always be correct – the same as what I set with “set-ctrl.”
But now, regardless of what value I SET, the return value is always “68”, which is very blurry and out of focus.

2). Even if I use the “autofocus-mode auto” parameter with libcamera-vid, the video is still blurry. The auto-focus feature doesn’t seem to be working.

1 Like

Hi
Are you burning the camera to Bookworm OS for now?

I’m on Bullseye.

$ uname -a
Linux church-pi4 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux

$ libcamera-vid --version
libcamera-apps build: 6437a8e7ddbc-intree-dirty 19-07-2023 (10:32:20)
libcamera build: v0.0.0+4367-ad9428b4

1 Like

Hi,
Please open another termimal and run the command “dmesg -w” to watch the focus motor driver when you use the “autofocus-mode auto” parameter with libcamera-vid.
Besides, it would be appreciated if you can provide us with the screenshot of libcamera at that moment.

1 Like

I ran the “dmesg -w” while the libcamera-vid started with “–autofocus-mode auto”…but no new messages appeared.

Is it possible to roll back to the previous driver for now? I need to run a good recording Sunday morning (for our church livestream), but I don’t think I’ll have time to fix this before then.

Attached are three screenshots. The “focus-before” images are clearly better than the “focus-after” file, which is how it looks now after the latest update.

Nothing has changed in my automated scripts. I have been livestreaming for the past year or more with this 64mp camera. The camera settings were identical for all three screenshots.

Please also consider my earlier comment about changes to /dev/v4l-subdev1. This used to allow me to precisely set the focus value, but now it doesn’t work. Has something changed with respect to V4L2?



1 Like

Here is a sample from today – very fuzzy. I noticed that, despite my attempts to assign the focus value, as I had previously done, the value of /dev/v4l-subdev1 “focus_absolute” is 68. Since I had been previously using values in the range 390-410, “68” is terribly out of focus. It seems that ‘libcamera-vid’ is locking in this value when it starts streaming. That is, I can set the value to 400…but as soon as libcamera-vid starts running, the value changes to 68.

I’m going to attempt to revert back to a previous version, unless you have some other suggestion.

It would really be nice if there was a way to modify the focus control “on-the-fly” while libcamera-vid is running. But to the best of my knowledge, once it starts, it locks into a focus setting. If you have a way to modity it while it runs, please let me know. I would love to be able to fine-tune my recordings and improve them while they are streaming.

Hi
Please try the commands below to control the focus manually:
https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/Libcamera-User-Guide/#for-arducam-16mp64mp-autofocus-camera

1 Like

Hello, Dion.

Yesterday, I already started looking into those additional parameters, and I did discover that I can use the “lens-position” parameter to achieve the desired focusing that I previously had. Through trial and error, I managed to get reasonable focus with a value of “5.7 - 5.8”. However, I can never get a good focused shot if I use just the “–autofocus-mode auto” parameter.

On the attached samples, the filenames are suffixed with the value I found in /dev/v4l2-subdev1 “focus_absolute” AFTER taking the still snapshot. I provide them here for reference, to show that proper values for my particular environment should be in the 380-400 range. Those values always show up for a focused image, and that agrees with my findings in the past (before this latest update). I was typically using 395 for most of my recordings.

At your request, I also ran tests for “autofocus-on-capture” and that did work – the image is focused, and the resulting “focus_absolute” value is 384, which is similar to my previous range.

I also ran a test with “autofocus-range normal” – it did NOT focus well, and the resulting value was 290. A test with “autofocus-range macro” did slightly better (336), but it was still out of focus.

====
I can work with these new methods, but I’m curious as to why it changed behavior. I did not see any documentation or warnings that the older methods no longer worked when attempting focus.
For the present time (until your next update, at least), I will modify my scripts to use “lens-position” instead of relying on the V4L2 “/dev/v4l-subdev1 focus_absolute” method.

At the risk of being redundant and repetitive, after this latest update to your libcamera library, I cannot “SET” (via “set-ctrl”) the focus with “focus_absolute” . . . but I am able to READ (via “get-ctrl”) the value, if I use “–lens-position” to set it.

Here are some more screenshots of tests made today. Again, the suffix number represents the value in “focus_absolute” that was READ immediately after the snapshot was taken.




1 Like

Hi,
In the older focus method, it uses CDAF which you can set the focus value with v4l2 command. However,after you update the OS, for now, you are using the PDAD which does not support setting focus value with v4l2 command. Anyway, with the “lens-position” parameter, you can get a clear image.

1 Like

Thank you, Dion.

But do you have any suggestions on how to fix the auto-focus mode? My camera will not properly auto-focus. Yes, I can manually set the “lens position” and force the focus, but there may be times when I still need that auto-focus feature to work.

Have there been any reports of other users having this same problem? It almost seems like a show-stopper, that is, a reason to abandon the Arducam camera. I bought this when it was first introduced, thinking it would have a superior sharpness and clarity. But since the video function can’t even use the full 64mp resolution, and since it doesn’t support any kind of HDR, my videos are not significantly better than the traditional Raspberry Pi 5mp camera (which I used prior to this camera).

1 Like

Hi
I have a question. Did you install the libcamera from Arducam via the commands below? If not, please install it and try the autofocus function again.
https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/Libcamera-User-Guide/#getting-started

For raspberry pi, the highest resolution for encoding video is 1080P. As regard to HDR, you can consider Raspberry Pi camera module 3(imx708 camera module).

1 Like

Dion, thanks for the info. Happy New Year, as well!

I did use the exact method you show here. After any OS update, if the camera doesn’t work, I download the latest install script, as shown, then run those “dev” and “apps” options.

I will try running this again, but it will be later this week.

1 Like

Hi,
Okay, looking forward to your feedback.