I'm trying to use the Arducam libcamera to get video from my Arducam 16 MP Autofocus camera on a Raspberry Pi 4, but I'm running into the issue that the quality is very low when retrieving 1920x1080 video (and images). In fact using any other resolution than the maximum that the camera offers, the quality is very low.
libcamera was installed by following the Arducam guide.
Using libcamera-still --list-cameras
, I get the following supported modes:
0 : imx519 [4656x3496] (/base/soc/i2c0mux/i2c@1/imx519@1a)
Modes: 'SRGGB10_CSI2P' : 1280x720 [120.00 fps - (1048, 1042)/2560x1440 crop]
1920x1080 [60.05 fps - (408, 674)/3840x2160 crop]
2328x1748 [30.00 fps - (0, 0)/4656x3496 crop]
3840x2160 [18.00 fps - (408, 672)/3840x2160 crop]
4656x3496 [9.00 fps - (0, 0)/4656x3496 crop]
To demonstrate the problem, I run the following command to capture two images. One 4656x3496 and one half as big (2328x1748):
libcamera-still --immediate --shutter 50000 --gain 1.5 --width 2328 --height 1748 -e png -o org_2328x1748.png && libcamera-still --immediate --shutter 50000 --gain 1.5 --width 4656 --height 3496 -e png -o org_4656x3496.png
If I then scale the 4656x3496 image to 2328x1748 on my computer, the result is a much sharper image than the 2328x1748 image delivered by the camera. This is true regardless of which program I use to scale the image. I don't understand why that happens. I've also noticed that the file size of the 4656x3496 image (15.6 MiB) is a lot bigger than 4x the file size of the 2328x1748 image (2.7 MiB). I think the small image should have been closer to 4 MiB in size.
Arducam support says it is a matter of finding the right libcamera arguments, so I'm hoping someone can be of help.
The output from executing the libcamera-still
command is the following:
pi@rpi:~ $ libcamera-still --immediate --shutter 50000 --gain 1.5 --width 2328 --height 1748 -e png -o org_2328x1748.png && libcamera-still --immediate --shutter 50000 --gain 1.5 --width 4656 --height 3496 -e png -o org_4656x3496.png
Preview window unavailable
[3:26:37.815366618] [4847] INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3730-67300b62
[3:26:37.851216285] [4849] WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[3:26:37.851259785] [4849] WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[3:26:37.868448913] [4849] WARN RPI raspberrypi.cpp:1274 Mismatch between Unicam and CamHelper for embedded data usage!
[3:26:37.868923575] [4849] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[3:26:37.869202646] [4849] INFO RPI raspberrypi.cpp:1398 Registered camera /base/soc/i2c0mux/i2c@1/imx519@1a to Unicam device /dev/media3 and ISP device /dev/media0
[3:26:37.870104137] [4847] INFO Camera camera.cpp:1029 configuring streams: (0) 2328x1748-BGR888 (1) 2328x1748-SRGGB10_CSI2P
[3:26:37.870498504] [4849] INFO RPI raspberrypi.cpp:763 Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a - Selected sensor format: 2328x1748-SRGGB10_1X10 - Selected unicam format: 2328x1748-pRAA
Still capture image received
Preview window unavailable
[3:26:39.086635744] [4855] INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3730-67300b62
[3:26:39.123343254] [4858] WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[3:26:39.123386606] [4858] WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[3:26:39.140987785] [4858] WARN RPI raspberrypi.cpp:1274 Mismatch between Unicam and CamHelper for embedded data usage!
[3:26:39.141479410] [4858] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[3:26:39.141723259] [4858] INFO RPI raspberrypi.cpp:1398 Registered camera /base/soc/i2c0mux/i2c@1/imx519@1a to Unicam device /dev/media3 and ISP device /dev/media0
[3:26:39.142604010] [4855] INFO Camera camera.cpp:1029 configuring streams: (0) 4656x3496-BGR888 (1) 4656x3496-SRGGB10_CSI2P
[3:26:39.142994210] [4858] INFO RPI raspberrypi.cpp:763 Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a - Selected sensor format: 4656x3496-SRGGB10_1X10 - Selected unicam format: 4656x3496-pRAA
Still capture image received
The images can be seen in this Google Drive folder. It contains the original images as well as the large image scaled down to 2328x1748 (scaled_4656x3496.png) with MS Paint. Notice that it is very sharp compared to org_2328x1748.png.
Adding --mode 4656:3496
results in high quality lower resolution images. For example:
libcamera-still --immediate --width 2328 --height 1748 -e png -o 2328x1748.png --mode 4656:3496
libcamera-still --immediate --width 1920 --height 1080 -e png -o 1920x1080.png --mode 4656:3496
It also works for libcamera-vid
. The framerate is limited by the selected sensor mode. So 9 fps is the max if the selected mode is 4656:3496, as specified by --list-cameras
:
libcamera-vid -o 1080p_3496_mode.h264 --width 1920 --height 1080 --framerate 9 --mode 4656:3496
I ended up using 3840:2160 mode which delivers sufficient quality and supports 18 fps.