Libcamera post processing and Arducam autofocus conflict


Got your 16MP autofocus camera working fine (ish) on a headless RPi Pi 3 A+ running 64-bit Bullseye, piping libcamera-vid to ffmpeg for a youtube live stream. I want to display date and time, so thought I could use post processing and as per the RPi instructions for ‘Building libcamera and libcamera-apps’ I got the annotate_cv.json display to work (NB there are no date and time directives yet - RPi are working on this). However, the autofocus no longer works - i.e. when using ‘–autofocus’ in the libcamera-vid command. Presumably, there’s some conflict between what Arducam want configured and what RPi recommend for ‘Building libcamera and libcamera-apps’. All help very welcome.

NB I don’t actually know what I’m doing - I’m just following all the instructions!


Have you tried applying this patch?

Thanks for prompt response. Sorry, I’m coming at this from a ‘maker’ perspective so will need guidance on how to apply a patch. I can follow instructions diligently, though! If it’s relevant, the RPi in question is in an outbuilding with the camera looking at a swallows nest - i.e. the RPI is headless. Many thanks.

The normal versions of libcamera and libcamera-apps do not have autofocus function, the autofocus function is added by ourselves and only exists in the version we provide, so you need to use the libcamera binary provided by us, if you want to recompile libcamera-apps the patch we provided needs to be applied, and the autofocus option has been added to this patch.
How to use patch:
patch -p1 -i <path to patch>

I have a fork with this patches applied:

You can find here a documentation how to buld libcamera-apps:
Raspberry Pi Documentation - Camera.

sudo apt install -y cmake libboost-program-options-dev libdrm-dev libexif-dev
git clone
cd libcamera-apps
mkdir build
cd build
make -j4

Now you can start the apps with e.g. ./libcamera-vid in the build directory.

On my system I have not done the last two steps to avoid problems with the programs installed by the system:

sudo make install
sudo ldconfig

Apologies, this isn’t working for me - please be patient with my level of technical knowledge! Thanks.

I clicked the patch file link, saved the contents to ‘/home/pi/arducam_patch_001.patch’, then ‘sudo chmod 777 arducam_patch_001.patch’, then ‘patch -p1 -i /home/pi/arducam_patch_001.patch’ (and tried ‘sudo patch -p1 -i /home/pi/arducam_patch_001.patch’). This is what I see:

$ patch -p1 -i /home/pi/arducam_patch_001.patch
can’t find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:

|diff --git a/apps/libcamera_still.cpp b/apps/libcamera_still.cpp
|index 6f68f2c…61bc1d7 100644
|— a/apps/libcamera_still.cpp

+++ b/apps/libcamera_still.cpp

File to patch:

I then tell it the file path again and then see:

patching file /home/pi/arducam_patch_001.patch
Hunk #1 FAILED at 181.
1 out of 1 hunk FAILED – saving rejects to file /home/pi/arducam_patch_001.patch.rej
can’t find file to patch at input line 22
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:

|diff --git a/apps/libcamera_vid.cpp b/apps/libcamera_vid.cpp
|index 61a159a…4fb5b23 100644
|— a/apps/libcamera_vid.cpp

+++ b/apps/libcamera_vid.cpp

File to patch:

And so on. Please advise what to do. Thanks.

Thanks for that. Just wanted to point out that I’m using a headless RPi 3 A+ and want Opencv, so the procedure is somewhat different. E.g.


should be:


and ‘make -j4’ needsa to be ‘-j1’ (also the memory swap file needs upping to 1Gb). There are other changes - see the RPi instructions.

The main point though, is that’s the procedure I followed (i.e. I followed the RPi instructions) and that’s how I’ve ended up with a conflict where the Arducam autofocus no longer works.

The impotent part is that I have a version with the patches already applied and it compiled fine on my RPi4.
To get that you have to use
git clone
and not
git clone

And yes, it would me much nicer, if arducam could provide up to date deb files, or get the changes merged into the official version.

Thanks for this. I’ll try starting from scratch again and this time will do as you suggest - ‘supertobi’, not ‘raspberrypi’ in the git clone. Assuming that works, the last part I’m after is date/time format directives in the annotate_cv_stage, as per this:

Do you have any thoughts on this? I see davidplowman (RPi engineer who kindly agreed the need for the new directives) is doing stuff on supertobi github too and wondered how one ‘lobbies’ for updates?

No, davidplowman does not do stuff on my fork, but in the main branche. But I just merged the changes from davidplowman into my fork. I haven’t tested if it still builds, but I see no reason why it should not.

Thank you very much - post processing and autofocus now working together. Re the annotate_cv-stage date/time format directives, presume that’s an ‘as and when’ job for the RPi engineers. The only other issue is with libcamera-vid cpu usage gradually increasing to 100% - compared to raspivid, libcamera-vid might be more powerful but it’s not simple to use! Thanks again.

EDIT: I’m not very good at reading the github web pages and can now see that the annotate_cv-stage date/time format directives are available - thanks to whoever did that!

FYI: I’ve updated my fork to the latest version of libcamera-apps.

Hey all – I’m running the new 64MP autofocus camera with a pi4. I use the pi for a host of things at work but realized I could replace my old dashcam with this pi since it has nothing better to do when I’m not using it. I’ve been trying to make sense of how exactly to get the date/time on my videos (I’m not streaming, just recording straight to video via libcamera and then converting with mkvmerge via a bash script).

So it looks like the annotate_cv is the way to go, and based on my googling @oldgit you’ve been the spearhead of getting this working for your swallow cam. I’m even more of an amateur than you, lol.

So two things – I assume that @supertobi 's fork did the trick for getting that to work, because as best I can tell this far the arducam version of libcamera doesn’t seem to support the annotate_cv (admittedly I could be doing something wrong – it also seems to not have libav as an option for codec, but with the rpi certain, as you’ve both discussed here, the autofocus controls are missing).

The other thing is that arducam, within the last week or so, has further updated their version to include the option to set the focus at a fixed distance using --afmode to set the autofocus mode (auto/continuous/manual) and --manualfocus to set the specific value for the focus. @supertobi does your fork automatically pull these updates?

I’d greatly appreciate any help you all could offer!

No, do you know if this patches are somewhere available? @wong any hints?

What I do is to update from time to time my fork to keep it up to date with the latest libcamera-apps version. That is something I think arducam could/should do. So I’m doing there job for free. :roll_eyes:

I’m really annoyed about arducam that they:

  1. don’t try harder to push there patches upstream. (Or if they do don’t talk about it.)
  2. don’t have at least there own up-to-date public fork, but only provide patches from time to time.
  3. don’t publish status updates here in the forum.

If they don’t improve how they work together with the upstream project they are just a electronic scrap producing company. :disappointed_relieved: And that is really sad because the hardware is nice.

In this thread is mentioned that 0.0.10 has the manual focus settings.

I only noticed the changes in the settings because it might attempt to get libav working, I tried installing the raspberry pi version of lib camera, but obviously that messed up the auto focus settings. But when I went back, the previous settings that I had for auto focus didn’t work, because they changed the parameters in the new version. --autofocus and --continue-autofocus don’t work with .10, but unless I miss something I didn’t say anything about this change in the official documentation.

EDIT - posted the wrong link before


You can refer to our official documentation


Are the patches online?


Please wait, I will organize a meeting to discuss the suggestions you mentioned above. The patch will be updated to you in these two days


We will create a new repository to manage this, please wait a moment, it won’t be long.

Unless there is a special usage, all our updates are pulled from the official previous commits, which are guaranteed to be the latest. We will also add relevant update instructions in the new repository.

If you have a better suggestion, you can also tell me.I’ll reply on this thread when I’m done.


Thanks, that would be really helpful.

Even better is of course to bring your patches upstream. Then there would be no need for any special repository. (In the long run less work for everyone.)

1 Like