jstars
Posts: 6
Joined: Fri Feb 09, 2018 4:07 am

MMAL vs V4L2

Sat Feb 24, 2018 5:52 pm

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.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9870
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: MMAL vs V4L2

Mon Feb 26, 2018 10:22 am

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)
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

jstars
Posts: 6
Joined: Fri Feb 09, 2018 4:07 am

Re: MMAL vs V4L2

Fri Mar 02, 2018 5:33 am

Thanks. That's useful info - not only for me but other forum users.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9870
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: MMAL vs V4L2

Fri Mar 02, 2018 9:22 am

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.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

JGwinner
Posts: 6
Joined: Mon Jul 09, 2018 4:57 pm

Re: MMAL vs V4L2

Wed Nov 28, 2018 7:36 pm

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 ==

Return to “Camera board”