Page 1 of 1

MMAL vs V4L2

Posted: Sat Feb 24, 2018 5:52 pm
by jstars
I am experimenting with a Raspberry Pi camera model V2. I am using motion with the v4l2 driver (I installed motion from the standard repositories, not from Github). I notice that the camera has a lot of problems with low light and bright (outdoors) conditions. I have tried enabling auto brightness in motion, but it doesn't make it better. Is this the result of the driver or the camera? Would using MMAL improve this? Frankly I don't know the difference between the two.

Re: MMAL vs V4L2

Posted: Mon Feb 26, 2018 10:22 am
by 6by9
MMAL and V4L2 are two APIs for multimedia.
MMAL is Broadcom specific, but exposes all the features of the hardware.
V4L2 is defined by a group of Linux kernel developers, is common to almost all Linux devices, but in being generic means that not all the features can be exposed.

Motion's autobrightness algorithm by default appears to adjust the brightness control of the V4L2 device. That is typically applied solely as digital gain, so you don't gain any extra detail. To improve the scene detail you need to be adjusting exposure time or analog gain. Typically those are controlled automatically, but within ranges defined by the exposure mode, which in turn can be controlled by the V4L2 scene mode.
The V4L2 driver does support a "night" scene mode, which allows significantly longer exposure times, and higher gain than normal mode. You MUST reduce the frame rate requested in order to achieve longer exposure times - there's no way to produce 30fps with exposure times greater than 33ms as physics won't allow it.

You can try the commands:

Code: Select all

v4l2-ctl --set-ctrl=scene_mode=8
v4l2-ctl -p 5
to request night mode and 5fps, although that does assume that motion doesn't override any of those settings (there is a "framerate" parameter according to https://rawgit.com/Motion-Project/motio ... nfig_Files).

I do note that https://github.com/Motion-Project/motion has merged in support for using MMAL on the Pi, but it does state that that has not been merged to the main repos as yet (it only got added in Sep 2016, and Debian moves slowly)

Re: MMAL vs V4L2

Posted: Fri Mar 02, 2018 5:33 am
by jstars
Thanks. That's useful info - not only for me but other forum users.

Re: MMAL vs V4L2

Posted: Fri Mar 02, 2018 9:22 am
by 6by9
I should add that V4L2 is built on top of MMAL, as the feature set is a subset of that which MMAL can offer. There are a couple of bits that don't fit brilliantly (eg the distinction between video and stills doesn't exist in V4L2), but otherwise it works reasonably.

Re: MMAL vs V4L2

Posted: Wed Nov 28, 2018 7:36 pm
by JGwinner
Really good info!

Understood on the vl42 being built 'on top' of mmal; I still have a basic question though.

Does mmal for Motion give higher framerates, all else being equal?

It sounds like the main difference is one of capabilities.

== John ==