raspberrypi / libcamera

Other
196 stars 74 forks source link

Enabling sensor HDR for Camera Module v3 #123

Closed otiv-jerome-colle closed 3 months ago

otiv-jerome-colle commented 3 months ago

Hi all,

I'm interested in trying out the sensor HDR mode on the Camera Module v3. I've tested it using rpicam-apps, and would like do ultimately expose it as a property of the libcamerasrc element to use it in a GStreamer application.

As far as I understand it, the rpicam-apps function directly enables the V4L2_CID_WIDE_DYNAMIC_RANGE control in all v4l2-subdevs, as done here. There, it's also specified that this is something that is not (yet) present in Libcamera.

I guess my question becomes: is this on the roadmap (not the GStreamer part), and if not, can I help?

Also, this can be considered as not being an issue, so please let me know if it's appropriate to post this here.

Thanks in advance!

naushir commented 3 months ago

Using the V4L2_CID_WIDE_DYNAMIC_RANGE is a bit of a hack that we have used to enable HDR on the IMX708. To cleanly implement HDR through V4L2, we need to define new HDR specific formats and add them to the upstream kernel. This is quite a long (and possibly controversial) process, so we have opted for the quick and dirty solution.

Because of this, unfortunately I don't think anyone will be willing to change GStreamer to allow this feature. However, there is a handy little command you can call to enable/disable HDR through the control:

v4l2-ctl -d /dev/v4l-subdevX --set-ctrl wide_dynamic_range=1

where the X in /dev/v4l-subdevX is the device node index of the sensor (usually 0/1/2). Your application can possible call this though a shell command before setting up the gst pipeline.

Eventually we will tackle the HDR formats in V4L2 - when time permits...

otiv-jerome-colle commented 3 months ago

Thanks for your answer! I'm currently setting the register from the registerCamera() method, so I'll keep it there and not spend too much time on it.

It seems that V4L2Device::listControls() reports Wide Dynamic Range (0x009a0915) as a control, and setting it using a ControlList works as well. At first glance it seemed like everything was there for writing the boilerplate to add it as a control. I'm relatively new to libcamera so there's a lot of things I don't fully understand yet, however. Anyway, looking forward to seeing it in action if in the future it gets added!