Arducam libcamera low quality in low resolution video/images - raspberry-pi
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.
Related
What causes my IMX519 Camera to produce errors when used?
My IMX519 Camera Sensor work on a preview through libcamera-still -t 0 but get these erros when initialized with libcamera-still -t 0 --viewfinder-width 2328 --viewfinder-height 1748 --autofocus It worked just fine on my previous interaction with the camera. Made X/EGL preview window [0:02:01.198729637] [1994] INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3897-c3c878a9 [0:02:01.206417698] [1996] WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519' [0:02:01.206492559] [1996] WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database [0:02:01.236208388] [1996] WARN RPI raspberrypi.cpp:1280 Mismatch between Unicam and CamHelper for embedded data usage! [0:02:01.237247694] [1996] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0 [0:02:01.237511562] [1996] INFO RPI raspberrypi.cpp:1404 Registered camera /base/soc/i2c0mux/i2c#1/imx519#1a to Unicam device /dev/media3 and ISP device /dev/media4 [0:02:01.238618960] [1994] INFO Camera camera.cpp:1035 configuring streams: (0) 2328x1748-YUV420 [0:02:01.239157063] [1996] INFO RPI raspberrypi.cpp:765 Sensor: /base/soc/i2c0mux/i2c#1/imx519#1a - Selected sensor format: 2328x1748-SRGGB10_1X10 - Selected unicam format: 2328x1748-pRAA Segmentation fault
How do I make the pi-topCEED screen work with Android Things
When I try Android Things DP3 with the pi-topCEED, the boot screen isn't displayed properly: How can I configure Android Things w/ the appropriate display parameter: Resolution: 1366x768 Refresh rate: 60hz
Mount the sdcard image boot partition # on my system mount /dev/sdb1 /mnt/disk Append the following value to config.txt # Define new custom HDMI mode <width> <height> <refresh_rate> hdmi_cvt 1366 768 60 # Select HDMI DMT mode (computer screen) hdmi_group=2 # Select custom mode defined earlier hdmi_mode=87 Unmount and eject your sdcard umount /dev/disk sync (Source, Previous Answer)
Monitor resolution with raspberry pi 2 and NOOBS
I got some trouble with my monitor resolution on my new pi2 with an Philips 284E5QHAD. The monitor can handle full hd but my pi2 seems not to do it. Thats my basic config (/boot/config.txt) #middle overclocking arm_freq=900 core_freq=250 sdram_freq=450 over_voltage=2 # GPU RAM upgrade gpu_mem=128 # Set sdtv mode to PAL (as used in Europe) sdtv_mode=2 sdtv_aspect=3 # Force the monitor to HDMI mode so that sound will be sent over HDMI cable hdmi_drive=2 # Set monitor resolution #overscan_left=0 #overscan_right=0 #overscan_top=0 #overscan_bottom=0 disable_overscan=1 That's the settings that I tried to use without success: Test1 hdmi_group=1 | hdmi_mode=16 Test2 hdmi_group=2 | hdmi_mode=32 Test3 hdmi_group=2 | hdmi_mode=82 All with the same result. Did someone got an idea for me?
I reinstalled the image and it worked with only disable_overscan=1
Accessing real frame buffer of PCI card
I am trying to access the framebuffer on my systems VGA controller card. lscpi -vn gives: 00:02.0 0300: 8086:2a02 (rev 0c) (prog-if 00 [VGA controller]) Subsystem: 1028:022f Flags: bus master, fast devsel, latency 0, IRQ 45 Memory at fea00000 (64-bit, non-prefetchable) [size=1M] Memory at e0000000 (64-bit, prefetchable) [size=256M] I/O ports at eff8 [size=8] Expansion ROM at <unassigned> [disabled] Capabilities: [90] MSI: Enable+ Count=1/1 Maskable- 64bit- Capabilities: [d0] Power Management version 3 Kernel driver in use: i915 Now, I access the device and I get: fb_base = pci_resource_start( devp, 0 ); **output: FEA00000** fb_size = pci_resource_len( devp, 0 ); **output: 1MB** So the range of framebuffer is FEA00000 - FEB00000 But from the lspci -vn output This region is non prefetchable. Does that mean I am not pointing to the frame buffer at all. Is my framebuffer at address E0000000: The driver currently using the resource is the Intel i915 So maybe when I request region or IRQ it can clash if not shared by that driver. If I remove the i915 rmmod it to insmod my driver, will my screen go blank. Please help. Thanks.
How can I convince ffserver to save a locally-sourced webcam stream to a file in high resolution AND stream it in lower resolution?
We have a remote Linux machine, accessible over VPN, which has a USB webcam. We want to use this for video conferencing, but we also want to store the stream for archiving. Since the streaming bandwidth is limited, it makes sense to capture the stream on the same machine as the webcam and rsync that across after-the-fact, rather than trying to capture the streamed content, which is necessarily going to be poor quality. We're trying to use ffmpeg and ffserver to achieve this, but with little success. Most of the articles on the internet either deal with just streaming a webcam, or rebroadcasting a remote stream. We found we had to recompile ffserver because of a missing "my_addr->sin_family = AF_INET;" in the version of ffserver.c we had been using, since fixed in git. Here's the ffserver.conf we're trying to use: Port 43688 BindAddress 127.0.0.1 MaxHTTPConnections 2000 MaxClients 1000 MaxBandwidth 1000 CustomLog - NoDaemon <Feed feed.ffm> ReadOnlyFile /tmp/feed.ffm FileMaxSize 20M ACL allow 127.0.0.1 </Feed> <Stream stream.mp4> Feed feed.ffm Format mp4 VideoSize qvga VideoGopSize 12 VideoHighQuality Video4MotionVector VideoCodec libx264 VideoBitRate 100 VideoBufferSize 40 VideoFrameRate 5 VideoQMin 3 VideoQMax 31 AudioCodec libfaac AudioBitRate 32 AudioChannels 2 AudioSampleRate 22050 ACL allow localhost </Stream> When we fire this up, we get the error: Unable to create feed file '/tmp/feed.ffm' as it is marked readonly Fair enough, but this is not what is implied in the docs. Changing the directive to: File /tmp/feed.ffm allows ffserver to fire up and appear to sit and wait for ffmpeg to connect to it. However, when we fire up ffmpeg with the command: ffmpeg -f alsa -i pulse -r 16000 -f video4linux2 -s qvga -i /dev/video0 -r 5 -f mp4 -vcodec libx264 -sameq -acodec libfaac -ab 32k http://127.0.0.1:43688/feed.ffm then the webcam lights up and ffserver acknowledges the connection with the messages: New connection: POST /feed.ffm [POST] "/feed.ffm HTTP/1.1" 200 0 but after a few seconds we get the errors: [mp4 # 0x264b160] muxer does not support non seekable output Could not write header for output file #0 (incorrect codec parameters ?) We've tried various other formats (mpeg, mpegts, avi) and codecs (mpeg1video, mpeg2video, mpeg4), all without success. Moreover, we were under the impression that ffserver could reencode input format to a lower resolution for streaming, but if the stream resolution doesn't match the feed resolution, we get an error about the resolutions not matching. Has anyone ever managed to get this working correctly? I've read about vlc being able to do something like this, but the vlc command lines are well nigh impenetrable. Thanks! Dominic
The problem is mp4. There is no streaming in mp4, which is basically Moov-Atoms. mp4 can wrap rtsp urls, but not around. so switch to mpegts, or use rtsp with a sdp file for the connection details.
To stream, I used the asf-format which worked well :) Also I might add that the quality of the video probably will be pretty bad due to the VideoBitRate 100 Which gives the server only 100 kbit/sec to serve the stream. When streaming in good quality I use VideoBitRate 1024 for a 640x480 Video.