Can't change raw resolution in Bookworm

I’m about to release a new version of my DSuper8 software.

The main improvement is the possibility of capturing jpg, raw-dng images or both simultaneously. Also included is a new dark theme (so trendy lately) for the GUI.

However, after upgrading my RPi4 to Bookworm, I ran into an unexpected problem:

Once the software is started, it is impossible to change the resolution of raw captures. On the contrary, the change in the resolution of the jpg captures works normally.

In the previous version of Raspberry Pi OS Bullseye everything worked as expected.

After multiple trials and tests I have not been able to solve the problem, so I have made a query in the picamera2 forum: Can't change raw resolution in Bookworm · raspberrypi/picamera2 · Discussion #838 · GitHub

Has any Bookworm and picamera2 user observed any similar anomaly?

Best regards

hmmm… - I think I do see the same issue. Here’s my code for a resolution change:

# modes for HQ camera
rawModes   = [{"size":(1332,  990),"format":"SRGGB10"},
              {"size":(2028, 1080),"format":"SRGGB12"},
              {"size":(2028, 1520),"format":"SRGGB12"},
              {"size":(4056, 3040),"format":"SRGGB12"}]

def setMode(self,para):

    # stop the camera
    self.stop()        
    time.sleep(0.2)
    
    self.mode  = int(para)

    config = self.camera_configuration()
    
    config['raw']          = self.rawModes[self.mode]
    config['main']         = {"size":self.rawModes[self.mode]['size'],'format':'RGB888'}

    self.configure(config)
    
    self.start()
    logStatus('Video mode is now: %d'%self.mode)

and if I am requesting “mode 2” instead of the inital “mode 3”, my logfile looks like this:

Mon Oct 30 18:25:49 2023 [        5 ms]:  Camera Init, standard tuning file
[0:01:32.426400589] [1842]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+52-a858d20b
[0:01:32.536584939] [1885]  WARN RPiSdn sdn.cpp:39 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
[0:01:32.541924217] [1885]  INFO RPI vc4.cpp:387 Registered camera /base/soc/i2c0mux/i2c@1/imx477@1a to Unicam device /dev/media3 and ISP device /dev/media0
Mon Oct 30 18:25:49 2023 [      162 ms]:  Creating still configuation
{'format': 'SRGGB10_CSI2P', 'size': (1332, 990)} 10552.216507177034
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1080)} 8179.837719298245
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1520)}[0:01:32.581384431] [1842]  
INFO Camera camera.cpp:1213 configuring streams: (0) 4056x3040-RGB888 (1) 4056x3040-SBGGR12
[0:01:32.582330189] [1885]  INFO RPI vc4.cpp:549 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 4056x3040-SBGGR12_1X12 - Selected unicam format: 4056x3040-BG12
 7096.0
{'format': 'SRGGB12_CSI2P', 'size': (4056, 3040)} 0.0
Mon Oct 30 18:25:55 2023 [     5542 ms]:  Config finished
Mon Oct 30 18:25:56 2023 [     1239 ms]:  Camera started
{'format': 'SRGGB10_CSI2P', 'size': (1332, 990)} 10552.216507177034
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1080)} 8179.837719298245
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1520)} 7096.0
{'format': 'SRGGB12_CSI2P', 'size': (4056, 3040)} 0.0
[0:02:53.655856869] [1881]  INFO Camera camera.cpp:1213 configuring streams: (0) 2028x1520-RGB888 (1) 4056x3040-SBGGR12
[0:02:53.708354124] [1885]  INFO RPI vc4.cpp:549 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 4056x3040-SBGGR12_1X12 - Selected unicam format: 4056x3040-BG12
Mon Oct 30 18:27:11 2023 [    74823 ms]:  Video mode is now: 2
Mon Oct 30 18:27:11 2023 [        2 ms]:  >   set_mode :  2

The selected sensor format is in both cases `4056x3040-SBGGR12_1X12, which is wrong.

Additional info: I had a quick look in the picamera2 manual and did not find any indication that something changed here. Multiple mode-switches which worked previously seem no longer working either.

2 Likes

Thanks for your answer.

If I find a solution I will post it in this same thread.

Cheers

can’t reproduce:

import os
import picamera2 as pc2
import time

class PicameraTest:
    def __init__(self):
        self.picamera2 = pc2.Picamera2()
        self.rawModes = [
            {"size":(1332,  990),"format":"SRGGB10"},
            {"size":(2028, 1080),"format":"SRGGB12"},
            {"size":(2028, 1520),"format":"SRGGB12"},
            {"size":(4056, 3040),"format":"SRGGB12"}
        ]

    def setMode(self, para):
        # stop the camera
        self.picamera2.stop()       
        time.sleep(0.2)

        config = self.picamera2.create_still_configuration(raw={})     
        config['raw'] = self.rawModes[int(para)]
        config['main'] = {"size":self.rawModes[int(para)]['size'], 'format':'RGB888'}

        self.picamera2.configure(config)
        
        self.picamera2.start()
        print('Video mode is now: %d' % int(para))
        request = self.picamera2.capture_request()
        request.save_dng(str(int(para)) + ".dng")
        request.release()
   
    def stop(self):
        self.picamera2.stop()
        
def main():
    # Print OS version
    os_version = os.popen('cat /etc/os-release').read()
    print(os_version)
    
    cam_test = PicameraTest()
    for i in range(len(cam_test.rawModes)):
        cam_test.setMode(i)
        time.sleep(0.1)  
    
     # Test modes in reverse order
    for i in reversed(range(len(cam_test.rawModes))):
        cam_test.setMode(i)
        time.sleep(0.1) 
        
    cam_test.stop()
    print("Test completed!")

if __name__ == "__main__":
    main()

output:

python playground/raw.py 
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

[13:14:48.686884019] [49017]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+52-a858d20b
[13:14:48.735091973] [49025]  WARN RPiSdn sdn.cpp:39 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
[13:14:48.738268576] [49025]  INFO RPI vc4.cpp:387 Registered camera /base/soc/i2c0mux/i2c@1/imx477@1a to Unicam device /dev/media0 and ISP device /dev/media1
{'format': 'SRGGB10_CSI2P', 'size': (1332, 990)} 0.0
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1080)} 1396.121212121212
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1520)} 1340.2320574162677
{'format': 'SRGGB12_CSI2P', 'size': (4056, 3040)} 2227.2320574162677
[13:14:48.950545490] [49017]  INFO Camera camera.cpp:1213 configuring streams: (0) 1332x990-RGB888 (1) 1332x990-SBGGR10
[13:14:48.951211295] [49025]  INFO RPI vc4.cpp:549 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 1332x990-SBGGR10_1X10 - Selected unicam format: 1332x990-BG10
Video mode is now: 0
{'format': 'SRGGB10_CSI2P', 'size': (1332, 990)} 4168.969696969697
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1080)} 0.0
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1520)} 1740.7017543859647
{'format': 'SRGGB12_CSI2P', 'size': (4056, 3040)} 2627.7017543859647
[13:14:50.038766698] [49029]  INFO Camera camera.cpp:1213 configuring streams: (0) 2028x1080-RGB888 (1) 2028x1080-SBGGR12
[13:14:50.040098901] [49025]  INFO RPI vc4.cpp:549 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 2028x1080-SBGGR12_1X12 - Selected unicam format: 2028x1080-BG12
Video mode is now: 1
{'format': 'SRGGB10_CSI2P', 'size': (1332, 990)} 3456.2165071770337
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1080)} 1083.8377192982457
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1520)} 0.0
{'format': 'SRGGB12_CSI2P', 'size': (4056, 3040)} 887.0
[13:14:51.150796721] [49029]  INFO Camera camera.cpp:1213 configuring streams: (0) 2028x1520-RGB888 (1) 2028x1520-SBGGR12
[13:14:51.155711782] [49025]  INFO RPI vc4.cpp:549 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 2028x1520-SBGGR12_1X12 - Selected unicam format: 2028x1520-BG12
Video mode is now: 2
{'format': 'SRGGB10_CSI2P', 'size': (1332, 990)} 10552.216507177034
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1080)} 8179.837719298245
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1520)} 7096.0
{'format': 'SRGGB12_CSI2P', 'size': (4056, 3040)} 0.0
[13:14:52.287965560] [49029]  INFO Camera camera.cpp:1213 configuring streams: (0) 4056x3040-RGB888 (1) 4056x3040-SBGGR12
[13:14:52.294560245] [49025]  INFO RPI vc4.cpp:549 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 4056x3040-SBGGR12_1X12 - Selected unicam format: 4056x3040-BG12
Video mode is now: 3
{'format': 'SRGGB10_CSI2P', 'size': (1332, 990)} 10552.216507177034
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1080)} 8179.837719298245
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1520)} 7096.0
{'format': 'SRGGB12_CSI2P', 'size': (4056, 3040)} 0.0
[13:14:53.982813619] [49029]  INFO Camera camera.cpp:1213 configuring streams: (0) 4056x3040-RGB888 (1) 4056x3040-SBGGR12
[13:14:54.005717909] [49025]  INFO RPI vc4.cpp:549 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 4056x3040-SBGGR12_1X12 - Selected unicam format: 4056x3040-BG12
Video mode is now: 3
{'format': 'SRGGB10_CSI2P', 'size': (1332, 990)} 3456.2165071770337
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1080)} 1083.8377192982457
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1520)} 0.0
{'format': 'SRGGB12_CSI2P', 'size': (4056, 3040)} 887.0
[13:14:58.614531579] [49029]  INFO Camera camera.cpp:1213 configuring streams: (0) 2028x1520-RGB888 (1) 2028x1520-SBGGR12
[13:14:58.637439998] [49025]  INFO RPI vc4.cpp:549 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 2028x1520-SBGGR12_1X12 - Selected unicam format: 2028x1520-BG12
Video mode is now: 2
{'format': 'SRGGB10_CSI2P', 'size': (1332, 990)} 4168.969696969697
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1080)} 0.0
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1520)} 1740.7017543859647
{'format': 'SRGGB12_CSI2P', 'size': (4056, 3040)} 2627.7017543859647
[13:14:59.757508562] [49029]  INFO Camera camera.cpp:1213 configuring streams: (0) 2028x1080-RGB888 (1) 2028x1080-SBGGR12
[13:14:59.763868769] [49025]  INFO RPI vc4.cpp:549 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 2028x1080-SBGGR12_1X12 - Selected unicam format: 2028x1080-BG12
Video mode is now: 1
{'format': 'SRGGB10_CSI2P', 'size': (1332, 990)} 0.0
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1080)} 1396.121212121212
{'format': 'SRGGB12_CSI2P', 'size': (2028, 1520)} 1340.2320574162677
{'format': 'SRGGB12_CSI2P', 'size': (4056, 3040)} 2227.2320574162677
[13:15:00.900468898] [49029]  INFO Camera camera.cpp:1213 configuring streams: (0) 1332x990-RGB888 (1) 1332x990-SBGGR10
[13:15:00.905269776] [49025]  INFO RPI vc4.cpp:549 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 1332x990-SBGGR10_1X10 - Selected unicam format: 1332x990-BG10
Video mode is now: 0
Test completed!

1 Like

@d_fens,

Apparently, with your code everything works correctly, but it is not the same case.

With your code, every time you switch modes, you create a completely new configuration that obviously works.

In my code on camera startup I create a new setting that works correctly.
Later, to change the resolution, I just change the size parameter of the initially created configuration. The change of the size parameter is done correctly in the main stream, but it does not do so in the raw stream.
With the Bullseye version everything worked correctly.

If possible, do this test yourself and I would appreciate it if you would let us know the results.

Best regards

@d_fens/@Manuel_Angel - I can confirm that Manuel’s suspicion is correct:

EDIT 01: it seems that “doing it the old way (ie. modifying an existing config)” occationally freezes my RP (running headless via ssh and VNC) using the new “Bookworm”-distro, without any obvious error message. That is not so funny…

In addition, I see in the system log the following error-messages:

Oct 31 11:07:06 raspi-05 pipewire[915]: [0:00:26.969834259] [915]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+52-a858d20b
Oct 31 11:07:06 raspi-05 pipewire[915]: [0:00:27.071221290] [1036]  WARN RPiSdn sdn.cpp:39 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
Oct 31 11:07:06 raspi-05 pipewire[915]: [0:00:27.077926967] [1036]  INFO RPI vc4.cpp:387 Registered camera /base/soc/i2c0mux/i2c@1/imx477@1a to Unicam device /dev/media3 and ISP device >
Oct 31 11:07:06 raspi-05 pipewire[915]: spa.v4l2: '/dev/video14' VIDIOC_ENUM_FRAMEINTERVALS: Inappropriate ioctl for device
Oct 31 11:07:06 raspi-05 pipewire[915]: spa.v4l2: '/dev/video15' VIDIOC_ENUM_FRAMEINTERVALS: Inappropriate ioctl for device
Oct 31 11:07:06 raspi-05 pipewire[915]: spa.v4l2: '/dev/video21' VIDIOC_ENUM_FRAMEINTERVALS: Inappropriate ioctl for device
Oct 31 11:07:06 raspi-05 pipewire[915]: spa.v4l2: '/dev/video22' VIDIOC_ENUM_FRAMEINTERVALS: Inappropriate ioctl for device
Oct 31 11:07:06 raspi-05 pipewire[915]: spa.v4l2: '/dev/video0' VIDIOC_ENUM_FRAMEINTERVALS: Inappropriate ioctl for device
Oct 31 11:07:07 raspi-05 pipewire[915]: spa.v4l2: '/dev/video14' VIDIOC_ENUM_FRAMEINTERVALS: Inappropriate ioctl for device
Oct 31 11:07:07 raspi-05 pipewire[915]: spa.v4l2: '/dev/video15' VIDIOC_ENUM_FRAMEINTERVALS: Inappropriate ioctl for device
Oct 31 11:07:07 raspi-05 pipewire[915]: spa.v4l2: '/dev/video21' VIDIOC_ENUM_FRAMEINTERVALS: Inappropriate ioctl for device
Oct 31 11:07:07 raspi-05 pipewire[915]: spa.v4l2: '/dev/video22' VIDIOC_ENUM_FRAMEINTERVALS: Inappropriate ioctl for device
Oct 31 11:07:07 raspi-05 pipewire[915]: spa.v4l2: '/dev/video0' VIDIOC_ENUM_FRAMEINTERVALS: Inappropriate ioctl for device

plus, previously to this ,

Oct 31 11:03:38 raspi-05 wireplumber[927]: <WpPortalPermissionStorePlugin:0x55c0b9af10> Failed to call Lookup: GDBus.Error:org.freedesktop.portal.Error.NotFound: No entry for camera

so I think something is broken with the current libcamera-implementation.

EDIT 02: I think someone of us should raise this issue on either or both the RP camera forum or the picamera2 issues page. @Manuel_Angel - you already mentioned this in the discussion page of the picamera2-lib, but I think it is now more appropriate to put that on the “issues”-page. Also, I modified @d_fens’s program a little bit to work out the differences. If in the following code the useNewConfig global parameter is set to True, @d_fens’s test runs flawlessly; if set to False, something breaks.

import os
import picamera2 as pc2
import time

useNewConfig = True

class PicameraTest:
    def __init__(self):
        self.picamera2 = pc2.Picamera2()
        
        self.rawModes = [
            {"size":(1332,  990),"format":"SRGGB10"},
            {"size":(2028, 1080),"format":"SRGGB12"},
            {"size":(2028, 1520),"format":"SRGGB12"},
            {"size":(4056, 3040),"format":"SRGGB12"}
        ]        
        
        config = self.picamera2.create_still_configuration()
        
        self.mode = 3
        config['buffer_count'] = 4
        config['queue']        = True
        config['raw']          = self.rawModes[self.mode]
        config['main']         = {"size":self.rawModes[self.mode]['size'],'format':'RGB888'}

        self.picamera2.configure(config)        
        

    def setMode(self, para):
        # stop the camera
        self.picamera2.stop()       
        time.sleep(0.2)

        if useNewConfig:
            config = self.picamera2.create_still_configuration(raw={})
        else:
            config = self.picamera2.camera_configuration()
        
        config['raw']  = self.rawModes[int(para)]
        config['main'] = {"size":self.rawModes[int(para)]['size'], 'format':'RGB888'}

        self.picamera2.configure(config)
        
        self.picamera2.start()
        print('Video mode is now: %d' % int(para))
        request = self.picamera2.capture_request()
        request.save_dng(str(int(para)) + ".dng")
        request.release()
   
    def stop(self):
        self.picamera2.stop()
        
def main():
    # Print OS version
    os_version = os.popen('cat /etc/os-release').read()
    print(os_version)
    
    cam_test = PicameraTest()
    time.sleep(2)
    for i in range(len(cam_test.rawModes)):
        cam_test.setMode(i)
        time.sleep(0.1)  
    
     # Test modes in reverse order
    for i in reversed(range(len(cam_test.rawModes))):
        cam_test.setMode(i)
        time.sleep(0.1) 
        
    cam_test.stop()
    print("Test completed!")

if __name__ == "__main__":
    main()

(tested on a RP3 with “Bookworm” and 320 MB CMA-memory, headless access with either ssh or VNC. Original HQ sensor used as camera.)

@cpixip,

At Issues · raspberrypi/picamera2 · GitHub I just created a new issue based on the query I had previously opened.

With a little luck maybe they will investigate it and provide a solution.

Regards

2 Likes

just a short update - no response yet from the RP folks. The bug is still present in the current picamera2 version which was upgraded today (incl. a new kernel), that is, with version 0.3.14.

2 Likes

@cpixip,

Very good the contribution to the issue of Picamera2 in github.

The problem is perfectly explained.

Let’s see if they pay attention to us and provide any solution.

David Plowman responded to our issue and requested a simple, easy-to-analyze script to check the problem.

I just uploaded a script that is simplicity itself, but really demonstrates the problem of changing resolution.

3 Likes

The issue is updated with the latest comment from David Plowman.

Regards

2 Likes

This morning David Plowman announced that he has corrected the issue with changing raw resolution in picamera2.

Once the changes were incorporated into the picamera2 module of my RPi4 and the modifications indicated by David himself were made to my software, I carried out tests and everything worked correctly as expected.

He left the link to the solution.

3 Likes

For people following this thread: at this point in time (beginning of Nov 23) the bug is still there in the RP distribution. It will take a while until this is corrected in the distribution. Also, the picamera2 version will need to increase from 0.3.14 to some higher value.

Manuel (@Manuel_Angel) installed the required patches for testing by hand. :ok_hand:

2 Likes

Released python3-picamera2 ver. 0.3.16-1.

I just ran some tests and at first everything seems to work normally. At least the bug that is the subject of this thread is fixed.

3 Likes