Camera cropping oddly

What is the problem?

I have a Pi 3B+ and an old raspberry pi camera. I get weird behavior with OctoPi on both the old and new camera stacks. I'm currently on the new stack and using the latest Camera Streamer Control plugin. All the tests here are with WebRTC. MJPEG doesn't even seem to load at the higher resolutions for me at this point. The camera seems to get cropped with no way to use a lower resolution with the full frame output.

What did you already try to solve it?

I've tried different combinations of settings in /boot/camera-streamer/libcamera.conf

Here is some info from libcamera-hello about the camera:

libcamera-hello --list-cameras
Available cameras
-----------------
0 : imx219 [3280x2464] (/base/soc/i2c0mux/i2c@1/imx219@10)
    Modes: 'SRGGB10_CSI2P' : 640x480 [30.00 fps - (0, 0)/0x0 crop]
                             1640x1232 [30.00 fps - (0, 0)/0x0 crop]
                             1920x1080 [30.00 fps - (0, 0)/0x0 crop]
                             3280x2464 [30.00 fps - (0, 0)/0x0 crop]
           'SRGGB8' : 640x480 [30.00 fps - (0, 0)/0x0 crop]
                      1640x1232 [30.00 fps - (0, 0)/0x0 crop]
                      1920x1080 [30.00 fps - (0, 0)/0x0 crop]
                      3280x2464 [30.00 fps - (0, 0)/0x0 crop]


This seems to imply that I can specify something like 640x480 and have no crop. So here is the config for that:


PORT=8080

# The resolution to request on the camera sensor. Defaults to 1280x720.
WIDTH=640
HEIGHT=480

# The height to use for the video stream. Defaults to 720.
VIDEO_HEIGHT=720

# The height to use for the snapshots. Defaults to 1080.
SNAPSHOT_HEIGHT=1080

# The framerate to set on the camera. Defaults to 15fps.
FRAMERATE=30

# Additional options. By default enables continuous auto focus (if possible).
OPTIONS='--camera-options="AfMode=2" --camera-options="AfRange=2" --camera-hflip=1 --camera-vflip=1'

That leads to a deep crop:

Now I try with the largest resolution. Only difference to config:

WIDTH=3280
HEIGHT=2464

It loads maybe half of one frame then crashes:

Refreshing can't get more to load generally.

Notice though how much wider this larger resolution is. I'd like to use that resolution to get a non-cropped image but then stream it at a lower resolution.

Here is another try with 1920x1080:


PORT=8080

# The resolution to request on the camera sensor. Defaults to 1280x720.
WIDTH=1920
HEIGHT=1080

# The height to use for the video stream. Defaults to 720.
VIDEO_HEIGHT=1080

# The height to use for the snapshots. Defaults to 1080.
SNAPSHOT_HEIGHT=1080

# The framerate to set on the camera. Defaults to 15fps.
FRAMERATE=30

# Additional options. By default enables continuous auto focus (if possible).
OPTIONS='--camera-options="AfMode=2" --camera-options="AfRange=2" --camera-hflip=1 --camera-vflip=1'

It works, but is cropped:

I just want the full FOV at a lower resolution via OctoPi

Have you tried running in safe mode?

Yes

Did running in safe mode solve the problem?

Not really, no.

Systeminfo Bundle

octoprint-systeminfo-20230919192711.zip (112.6 KB)

Additional information about your setup

uname -a
Linux 3dprinter 6.1.21-v7+ #1642 SMP Mon Apr  3 17:20:52 BST 2023 armv7l GNU/Linux

cat /proc/cpuinfo
processor       : 0
model name      : ARMv7 Processor rev 4 (v7l)
BogoMIPS        : 44.80
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

processor       : 1
model name      : ARMv7 Processor rev 4 (v7l)
BogoMIPS        : 44.80
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

processor       : 2
model name      : ARMv7 Processor rev 4 (v7l)
BogoMIPS        : 44.80
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

processor       : 3
model name      : ARMv7 Processor rev 4 (v7l)
BogoMIPS        : 44.80
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

Hardware        : BCM2835
Revision        : a020d3
Serial          : 00000000bd5ea946
Model           : Raspberry Pi 3 Model B Plus Rev 1.3

cat /boot/octopi.txt
### IMPORTANT: Looking for the camera settings? Those are now located
### in the camera-streamer directory! libcamera.conf to configure the Raspberry Pi
### camera and usb-default.conf to configure USB cameras. Read more about it here:
### https://faq.octoprint.org/camera-streamer-config

### Windows users: To edit this file use Notepad++, VSCode or SublimeText.
### Do not use Notepad or WordPad.

### MacOSX users: If you use Textedit to edit this file make sure to use
### "plain text format" and "disable smart quotes" in "Textedit > Preferences"

# Configuration of network monitoring
#
# This enables network monitoring for wifi connections with a simple ping test.
# If connection terminates by variable reasons system tries to restart the wifi connection to reestablish a connection.
# The connection test is done every minute.
# By default it is disabled (0 = off / 1 = on)
# destination_host can be an ip address or a hostname (for hostname ensure dns resosultion is working correctly)

enable_network_monitor=0

# Be sure to change this to match your network!
destination_host=192.168.1.1

### EXPERIMENTAL
# Support for different streamer types.
#
# Available options:
#   mjpeg [default] - camera-streamer
#   hls - FFMPEG HLS streamer
#camera_streamer=mjpeg


cat /etc/octopi_buildbase
2022-09-22-raspios-bullseye-armhf-lite.img

cat /etc/octopi_version
1.0.0

vcgencmd get_camera
supported=1 detected=0, libcamera interfaces=1

libcamera-hello --list-cameras  -v
Available cameras
-----------------
0 : imx219 [3280x2464] (/base/soc/i2c0mux/i2c@1/imx219@10)
    Modes: 'SRGGB10_CSI2P' : 640x480 [30.00 fps - (0, 0)/0x0 crop]
                             1640x1232 [30.00 fps - (0, 0)/0x0 crop]
                             1920x1080 [30.00 fps - (0, 0)/0x0 crop]
                             3280x2464 [30.00 fps - (0, 0)/0x0 crop]
           'SRGGB8' : 640x480 [30.00 fps - (0, 0)/0x0 crop]
                      1640x1232 [30.00 fps - (0, 0)/0x0 crop]
                      1920x1080 [30.00 fps - (0, 0)/0x0 crop]
                      3280x2464 [30.00 fps - (0, 0)/0x0 crop]

    Available controls for 3280x2464 SRGGB10_CSI2P mode:
    ----------------------------------------------------
    AeConstraintMode : [0..3]
    AeEnable : [false..true]
    AeExposureMode : [0..3]
    AeMeteringMode : [0..3]
    AnalogueGain : [1.000000..16.000000]
    AwbEnable : [false..true]
    AwbMode : [0..7]
    Brightness : [-1.000000..1.000000]
    ColourGains : [0.000000..32.000000]
    Contrast : [0.000000..32.000000]
    ExposureTime : [0..66666]
    ExposureValue : [-8.000000..8.000000]
    FrameDurationLimits : [33333..120000]
    NoiseReductionMode : [0..4]
    Saturation : [0.000000..32.000000]
    ScalerCrop : [(0, 0)/0x0..(65535, 65535)/65535x65535]
    Sharpness : [0.000000..16.000000]

cat /boot/config.txt
arm_64bit=0
# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# Automatically load overlays for detected cameras
camera_auto_detect=1

# Automatically load overlays for detected DSI displays
display_auto_detect=1

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2

# Disable compensation for displays with overscan
disable_overscan=1

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1

[all]

[pi4]
# Run as fast as firmware / board allows
arm_boost=1

[all]
# enable raspicam
start_x=1
gpu_mem=128

I used imgur for some photos since new folks can only have one embedded media.

Adding another info command:

/usr/bin/camera-streamer --camera-list_options --camera-type=libcamera
/usr/bin/camera-streamer Version: 0.2.5 (41d8dfd)
[1:13:17.911508828] [17580]  INFO Camera camera_manager.cpp:297 libcamera v0.0.5+82-2783c8d8
[1:13:17.962245110] [17581]  WARN RPI vc4.cpp:383 Mismatch between Unicam and CamHelper for embedded data usage!
[1:13:17.963283879] [17581]  INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/imx219@10 to Unicam device /dev/media3 and ISP device /dev/media0
device/libcamera/device.cc: CAMERA: Device path=/base/soc/i2c0mux/i2c@1/imx219@10 opened
[1:13:17.964384628] [17580]  INFO Camera camera.cpp:1033 configuring streams: (0) 1920x1080-NV12
[1:13:17.965111621] [17581]  INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 1920x1080-SBGGR10_1X10 - Selected unicam format: 1920x1080-pBAA
[1:13:17.968182770] [17580]  INFO Camera camera.cpp:1033 configuring streams: (0) 1920x1080-NV12 (1) 1920x1080-SBGGR10_CSI2P
[1:13:17.968833980] [17581]  INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 1920x1080-SBGGR10_1X10 - Selected unicam format: 1920x1080-pBAA
device/buffer_list.c: CAMERA:capture: Using: 1920x1080/NV12, buffers=3, bytesperline=1920, sizeimage=0.0MiB
device/buffer_list.c: CAMERA:capture: Opened 3 buffers. Memory used: 8.9 MiB
device/buffer_list.c: CAMERA:capture:1: Using: 1920x1080/BG10, buffers=3, bytesperline=2400, sizeimage=0.0MiB
device/buffer_list.c: CAMERA:capture:1: Opened 3 buffers. Memory used: 7.4 MiB
device/v4l2/device.c: SNAPSHOT: Device path=/dev/video11 fd=28 opened
device/buffer_list.c: SNAPSHOT:output:mplane: Using: 1920x1080/NV12, buffers=3, bytesperline=1920, sizeimage=3.0MiB
device/buffer_list.c: SNAPSHOT:output:mplane: Opened 3 buffers. Memory used: 0.0 MiB
device/buffer_list.c: SNAPSHOT:capture:mplane: Using: 1920x1080/MJPG, buffers=3, bytesperline=0, sizeimage=0.8MiB
device/buffer_list.c: SNAPSHOT:capture:mplane: Opened 3 buffers. Memory used: 2.2 MiB
device/v4l2/device.c: VIDEO: Device path=/dev/video11 fd=32 opened
device/buffer_list.c: VIDEO:output:mplane: Using: 1920x1080/NV12, buffers=3, bytesperline=1920, sizeimage=3.0MiB
device/buffer_list.c: VIDEO:output:mplane: Opened 3 buffers. Memory used: 0.0 MiB
device/buffer_list.c: VIDEO:capture:mplane: Using: 1920x1080/H264, buffers=3, bytesperline=0, sizeimage=0.8MiB
device/buffer_list.c: VIDEO:capture:mplane: Opened 3 buffers. Memory used: 2.2 MiB
device/device.c: CAMERA: Setting frame interval_us=0 for FPS=30
device/v4l2/device_options.c: SNAPSHOT: The 'compression_quality=80' was failed to find.
device/v4l2/device_options.c: VIDEO: Configuring option 'Repeat Sequence Header' (009909e2) = 1
device/v4l2/device_options.c: VIDEO: Configuring option 'Video Bitrate Mode' (009909ce) = 0
device/v4l2/device_options.c: VIDEO: Configuring option 'Video Bitrate' (009909cf) = 2000000
device/v4l2/device_options.c: VIDEO: Configuring option 'Repeat Sequence Header' (009909e2) = 5000000
device/v4l2/device_options.c: VIDEO: Configuring option 'H264 I-Frame Period' (00990a66) = 30
device/v4l2/device_options.c: VIDEO: Configuring option 'H264 Level' (00990a67) = 11
device/v4l2/device_options.c: VIDEO: Configuring option 'H264 Profile' (00990a6b) = 4
device/v4l2/device_options.c: VIDEO: Configuring option 'H264 Minimum QP Value' (00990a61) = 16
device/v4l2/device_options.c: VIDEO: Configuring option 'H264 Maximum QP Value' (00990a62) = 32
device/links.c: ?: Link 0: CAMERA:capture[1920x1080/NV12/3] => [SNAPSHOT:output:mplane[1920x1080/NV12/3], VIDEO:output:mplane[1920x1080/NV12/3]]
device/links.c: ?: Link 1: SNAPSHOT:capture:mplane[1920x1080/MJPG/3] => [SNAPSHOT-CAPTURE, STREAM-CAPTURE]
device/links.c: ?: Link 2: VIDEO:capture:mplane[1920x1080/H264/3] => [VIDEO-CAPTURE]

CAMERA Properties:
- property: SensorSensitivity (00000009, type=Float) = 1.000000
- property: SystemDevices (0000000a, type=Integer64) = [ 20749, 20750, 20738, 20739, 20740 ]
- property: ScalerCropMaximum (00000008, type=Rectangle) = (680, 692)/1920x1080
- property: ColorFilterArrangement (0000000b, type=Integer32) = 0
- property: PixelArrayActiveAreas (00000007, type=Rectangle) = [ (8, 8)/3280x2464 ]
- property: PixelArraySize (00000005, type=Size) = 3280x2464
- property: Rotation (00000002, type=Integer32) = 0
- property: Location (00000001, type=Integer32) = 2
- property: UnitCellSize (00000004, type=Size) = 1120x1120
- property: Model (00000003, type=String) = imx219

CAMERA Options:
- available option: ScalerCrop (00000016, type=Rectangle): [(680, 692)/64x64..(680, 692)/1920x1080]
- available option: Sharpness (00000013, type=Float): [0.000000..16.000000]
- available option: Contrast (0000000a, type=Float): [0.000000..32.000000]
- available option: AeConstraintMode (00000004, type=Integer32): [0..3]
                0: Normal
                1: Highlight
                2: Shadows
                3: Custom
- available option: NoiseReductionMode (00000027, type=Integer32): [0..4]
                0: Off
                1: Fast
                2: HighQuality
                3: Minimal
                4: ZSL
- available option: AeMeteringMode (00000003, type=Integer32): [0..3]
                0: CentreWeighted
                1: Spot
                2: Matrix
                3: Custom
- available option: Brightness (00000009, type=Float): [-1.000000..1.000000]
- available option: FrameDurationLimits (00000019, type=Integer64): [21020..11767556]
- available option: AnalogueGain (00000008, type=Float): [1.000000..10.666667]
- available option: Saturation (00000011, type=Float): [0.000000..32.000000]
- available option: AeEnable (00000001, type=Bool): [false..true]
- available option: AwbEnable (0000000c, type=Bool): [false..true]
- available option: ColourGains (0000000f, type=Float): [0.000000..32.000000]
- available option: ExposureValue (00000006, type=Float): [-8.000000..8.000000]
- available option: AwbMode (0000000d, type=Integer32): [0..7]
                0: Auto
                1: Incandescent
                2: Tungsten
                3: Fluorescent
                4: Indoor
                5: Daylight
                6: Cloudy
                7: Custom
- available option: ExposureTime (00000007, type=Integer32): [75..11766829]
- available option: AeExposureMode (00000005, type=Integer32): [0..3]
                0: Normal
                1: Short
                2: Long
                3: Custom

SNAPSHOT Options:
- available option: videobframes (009909ca, type=1): [0..0]
- available option: videogopsize (009909cb, type=1): [0..2147483647]
- available option: videobitratemode (009909ce, type=3): [0..1]
                0: Variable Bitrate
                1: Constant Bitrate
- available option: videobitrate (009909cf, type=1): [25000..25000000]
- available option: sequenceheadermode (009909d8, type=3): [0..1]
                0: Separate Buffer
                1: Joined With 1st Frame
- available option: repeatsequenceheader (009909e2, type=2): [0..1]
- available option: forcekeyframe (009909e5, type=4): button
- available option: h264minimumqpvalue (00990a61, type=1): [0..51]
- available option: h264maximumqpvalue (00990a62, type=1): [0..51]
- available option: h264iframeperiod (00990a66, type=1): [0..2147483647]
- available option: h264level (00990a67, type=3): [0..15]
                0: 1
                1: 1b
                2: 1.1
                3: 1.2
                4: 1.3
                5: 2
                6: 2.1
                7: 2.2
                8: 3
                9: 3.1
                10: 3.2
                11: 4
                12: 4.1
                13: 4.2
                14: 5
                15: 5.1
- available option: h264profile (00990a6b, type=3): [0..4]
                0: Baseline
                1: Constrained Baseline
                2: Main
                4: High

VIDEO Options:
- available option: videobframes (009909ca, type=1): [0..0]
- available option: videogopsize (009909cb, type=1): [0..2147483647]
- available option: videobitratemode (009909ce, type=3): [0..1]
                0: Variable Bitrate
                1: Constant Bitrate
- available option: videobitrate (009909cf, type=1): [25000..25000000]
- available option: sequenceheadermode (009909d8, type=3): [0..1]
                0: Separate Buffer
                1: Joined With 1st Frame
- available option: repeatsequenceheader (009909e2, type=2): [0..1]
- available option: forcekeyframe (009909e5, type=4): button
- available option: h264minimumqpvalue (00990a61, type=1): [0..51]
- available option: h264maximumqpvalue (00990a62, type=1): [0..51]
- available option: h264iframeperiod (00990a66, type=1): [0..2147483647]
- available option: h264level (00990a67, type=3): [0..15]
                0: 1
                1: 1b
                2: 1.1
                3: 1.2
                4: 1.3
                5: 2
                6: 2.1
                7: 2.2
                8: 3
                9: 3.1
                10: 3.2
                11: 4
                12: 4.1
                13: 4.2
                14: 5
                15: 5.1
- available option: h264profile (00990a6b, type=3): [0..4]
                0: Baseline
                1: Constrained Baseline
                2: Main
                4: High

Ahh i thought of something:

sudo service camera-streamer stop

then running

libcamera-hello --list-cameras  -v

Available cameras
-----------------
0 : imx219 [3280x2464] (/base/soc/i2c0mux/i2c@1/imx219@10)
    Modes: 'SRGGB10_CSI2P' : 640x480 [103.33 fps - (1000, 752)/1280x960 crop]
                             1640x1232 [41.85 fps - (0, 0)/3280x2464 crop]
                             1920x1080 [47.57 fps - (680, 692)/1920x1080 crop]
                             3280x2464 [21.19 fps - (0, 0)/3280x2464 crop]
           'SRGGB8' : 640x480 [103.33 fps - (1000, 752)/1280x960 crop]
                      1640x1232 [41.85 fps - (0, 0)/3280x2464 crop]
                      1920x1080 [47.57 fps - (680, 692)/1920x1080 crop]
                      3280x2464 [21.19 fps - (0, 0)/3280x2464 crop]

    Available controls for 3280x2464 SRGGB10_CSI2P mode:
    ----------------------------------------------------
    AeConstraintMode : [0..3]
    AeEnable : [false..true]
    AeExposureMode : [0..3]
    AeMeteringMode : [0..3]
    AnalogueGain : [1.000000..10.666667]
    AwbEnable : [false..true]
    AwbMode : [0..7]
    Brightness : [-1.000000..1.000000]
    ColourGains : [0.000000..32.000000]
    Contrast : [0.000000..32.000000]
    ExposureTime : [75..11766829]
    ExposureValue : [-8.000000..8.000000]
    FrameDurationLimits : [47183..11767556]
    NoiseReductionMode : [0..4]
    Saturation : [0.000000..32.000000]
    ScalerCrop : [(0, 0)/64x64..(0, 0)/3280x2464]
    Sharpness : [0.000000..16.000000]

This looks like more full results.

Now with this config:


### Options for libcamera based cameras (PiCam, Arducam, ...)

# The port on which the webcam server for the camera should listen on. If you have only
# one camera, leave at 8080. If you have more, change to 8081, 8082, etc. The primary
# camera will be considered the one with 8080.
PORT=8080

# The resolution to request on the camera sensor. Defaults to 1280x720.
WIDTH=1640
HEIGHT=1232

# The height to use for the video stream. Defaults to 720.
VIDEO_HEIGHT=1232

# The height to use for the snapshots. Defaults to 1080.
SNAPSHOT_HEIGHT=1232

# The framerate to set on the camera. Defaults to 15fps.
FRAMERATE=30

# Additional options. By default enables continuous auto focus (if possible).
OPTIONS='--camera-options="AfMode=2" --camera-options="AfRange=2" --camera-hflip=1 --camera-vflip=1'

It seems like its working!

Though I'm still a bit confused tbh.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.