jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23631
Joined: Sat Jul 30, 2011 7:41 pm

Re: Official V4L2 driver

Sun Jan 12, 2014 10:22 am

Not sure how it relates to ISO , but the max the camera can go to now in night mode is 0.97s exposure and 8x analog gain and 2x digital gain.

But I'm not sure the firmware with the fix in has been released yet. I pushed the code to the repo here at Brcm, but Dom then needs to release it to the public and I am not sure he has done that yet
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5331
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Official V4L2 driver

Sun Jan 12, 2014 11:31 am

jamesh wrote:Not sure how it relates to ISO , but the max the camera can go to now in night mode is 0.97s exposure and 8x analog gain and 2x digital gain.

But I'm not sure the firmware with the fix in has been released yet. I pushed the code to the repo here at Brcm, but Dom then needs to release it to the public and I am not sure he has done that yet
Yes, it's in: https://github.com/Hexxeh/rpi-firmware/ ... 42f00f0215
Follow https://twitter.com/RPF_Dev_Updates to see firmware commits.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23631
Joined: Sat Jul 30, 2011 7:41 pm

Re: Official V4L2 driver

Sun Jan 12, 2014 7:37 pm

dom wrote:
jamesh wrote:Not sure how it relates to ISO , but the max the camera can go to now in night mode is 0.97s exposure and 8x analog gain and 2x digital gain.

But I'm not sure the firmware with the fix in has been released yet. I pushed the code to the repo here at Brcm, but Dom then needs to release it to the public and I am not sure he has done that yet
Yes, it's in: https://github.com/Hexxeh/rpi-firmware/ ... 42f00f0215
Follow https://twitter.com/RPF_Dev_Updates to see firmware commits.
Cool. Thanks Dom.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

User avatar
jbeale
Posts: 3491
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Official V4L2 driver

Mon Jan 13, 2014 3:10 am

jamesh wrote:Not sure how it relates to ISO , but the max the camera can go to now in night mode is 0.97s exposure and 8x analog gain and 2x digital gain.
THis is a very nice improvement to functionality in "night", thank you! Although given the big difference in motion blur between 1/4 sec and 1 sec, I find myself wishing for an intermediate option between normal and night that works the way "night" used to. Maybe "evening" or "twilight" ?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23631
Joined: Sat Jul 30, 2011 7:41 pm

Re: Official V4L2 driver

Mon Jan 13, 2014 9:30 am

jbeale wrote:
jamesh wrote:Not sure how it relates to ISO , but the max the camera can go to now in night mode is 0.97s exposure and 8x analog gain and 2x digital gain.
THis is a very nice improvement to functionality in "night", thank you! Although given the big difference in motion blur between 1/4 sec and 1 sec, I find myself wishing for an intermediate option between normal and night that works the way "night" used to. Maybe "evening" or "twilight" ?
I did wonder whether that would cause problems elsewhere. There are a few modes, I wonder if I should tweak some others as well to compensate, and give back the initial night mode elsewhere.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

timrowledge
Posts: 1284
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Official V4L2 driver

Wed Jan 15, 2014 12:04 am

I've attempted to make sense of the thread but to no avail; I'm still none the wiser with regard to installing whatever is needed to help me connect Scratch to the camera module. Some might say I was none the wiser, full stop.

The Scratch code is built on the assumption that a v4linux dynamic library will be available and will do the correct thing when referred to in code like this -
hLibv4l2 = dlopen("libv4l2.so.0", RTLD_LAZY);
if (hLibv4l2) {
vd_open = dlsym(hLibv4l2, "v4l2_open");
vd_close = dlsym(hLibv4l2, "v4l2_close");
vd_dup = dlsym(hLibv4l2, "v4l2_dup");
...
I did the apt-get of v4l-utils and an update/upgrade but to no apparent success. I spotted a mention of using

Code: Select all

sudo modprobe bcm2835-v4l2
but that gave me an error

Code: Select all

'could not open moddep file lib/modules/3.10.24+/modules.dep.bin'
so I guess there is more to do.

I'm hoping there is an extremely simple process to do to make this work. Advice welcomed...
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

User avatar
jbeale
Posts: 3491
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Official V4L2 driver

Wed Jan 15, 2014 12:16 am

I'm not the expert but I think if the modprobe bcm2835-v4l2 step fails then you will have no /dev/video0 and will never get v4l2 working, so we need to fix that before going farther. I'm presuming you've done these five steps in this order:

Code: Select all

sudo apt-get update
sudo apt-get dist-upgrade
sudo rpi-update
sudo reboot
sudo modprobe bcm2835-v4l2
Note that "apt-get dist-upgrade" will fix some things that "apt-get upgrade" does not.
Using upgrade keeps to the rule: under no circumstances are currently installed packages removed, or packages not already installed retrieved and installed. If that's important to you, use apt-get upgrade. If you want things to "just work", you probably want apt-get dist-upgrade to ensure dependencies are resolved. - from http://askubuntu.com/questions/194651/w ... st-upgrade
If that is what you have done, and it still doesn't work, then presuming you have a spare SD card, I'd suggest trying it using a completely fresh install. Theory being that something is broken in your current system that the updates did not fix.

Having just done the above five steps on my system, I see v4l2 is working:

Code: Select all

$ ls -al /dev/video0
crw-rw---T 1 root video 81, 0 Jan 14 16:32 /dev/video0

$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=test1.jpg
$ ls -al test1.jpg
-rw-r--r-- 1 pi pi 1875800 Jan 14 16:36 test1.jpg

timrowledge
Posts: 1284
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Official V4L2 driver

Wed Jan 15, 2014 1:28 am

Thanks jbeale!

I sort-of 'solved' the problem by accident of looking at another issue (I want to mount a folder on my iMac on my Pi so I can use it as a nice safe backed up directory; used to work until Mavericks broke it) and trying mod probe cifs - which failed the same way. Eventually the lead me to reboot and now the v4l works ; well, up to a point. The colour map seems a bit weird under Scratch, all smurf blue, something I imagine that is configurable somewhere.

The bit that bothers me and is probably best discussed in some other thread is that rpi-update is 'command not found'. That doesn't seem quite right, somehow.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

pondruska
Posts: 1
Joined: Wed Jan 15, 2014 6:11 am

Re: Official V4L2 driver

Wed Jan 15, 2014 6:25 am

When I try to load the camera in OpenCV I get an error:
HIGHGUI ERROR: V4L/V4L2: VIDIOC_CROPCAP
The image is eventually fetched but in 'BGR3' format and is cropped (compared to raspistill output). Moreover when I try to change resolution I get the same error and the resolution stays at 640x480 all the time.

Anyone encountered this?

Code: Select all

#!/usr/bin/env python2.7
import cv2

camera = cv2.VideoCapture(0)
success, image = camera.read()
cv2.imwrite("image.jpg", image)
camera.release()

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

Re: Official V4L2 driver

Wed Jan 15, 2014 12:20 pm

timrowledge wrote:The colour map seems a bit weird under Scratch, all smurf blue, something I imagine that is configurable somewhere.
Which colour format are you/Scratch asking for? The driver supports YU12, YUYV, and BGR24 as raw image formats, and JPEG, H264, and MJPEG as compressed formats.
If you run the command

Code: Select all

v4l2-ctl -V
once you've run your app then it should report which mode was selected. Something like

Code: Select all

pi@raspberrypi ~ $ v4l2-ctl -V
Format Video Capture:
        Width/Height  : 1024/768
        Pixel Format  : 'JPEG'
        Field         : None
        Bytes per Line: 1024
        Size Image    : 786432
        Colorspace    : SRGB
which shows that I last had JPEG selected.

There is suspected to be a bug that we're producing RGB24 instead of BGR24, which would result in blue and red being swapped. Other than that I believe we produce frames as requested.
Knowing which format is believed to be at fault would help us track down any actual issue.
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.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5331
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Official V4L2 driver

Wed Jan 15, 2014 12:26 pm

timrowledge wrote:The bit that bothers me and is probably best discussed in some other thread is that rpi-update is 'command not found'. That doesn't seem quite right, somehow.

Code: Select all

sudo apt-get install rpi-update
It's been installed as a default for some time but an old sdcard may not have it.

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

Re: Official V4L2 driver

Wed Jan 15, 2014 12:28 pm

pondruska wrote:When I try to load the camera in OpenCV I get an error:
HIGHGUI ERROR: V4L/V4L2: VIDIOC_CROPCAP
The image is eventually fetched but in 'BGR3' format and is cropped (compared to raspistill output). Moreover when I try to change resolution I get the same error and the resolution stays at 640x480 all the time.
The driver doesn't currently support cropping of the image, which is what VIDIOC_CROPCAP is trying to do. I would expect the app (ie OpenCV) to cope with that as it is not mandatory to implement all ioctls.

The format is chosen by the app, and it has obviously decided BGR3 is the format it would like (we default to JPEG, so it isn't just the default). Resolution too is set by the app.

The image cropping compared to raspistill will be down to the issue of preview reading a 16:9 image off the sensor, whilst stills capture reads the full 4:3. raspistill will be asking for a still image capture at your chosen resolution, whilst V4L2 is asking for video frames in order to achieve a higher framerate.
Both Jamesh and I have had a look at the sensor driver to try and add a full frame video mode, but neither of us have had the time to get it actually working as yet - sorry.
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.

flok
Posts: 19
Joined: Thu Dec 13, 2012 9:46 am
Location: Gouda
Contact: ICQ Website

Re: Official V4L2 driver

Mon Jan 27, 2014 12:06 pm

Hi,

Fwiw: "koudevoeten" (yes, that is the name of the software) also works fine with the video4linux driver of the raspberry pi camera.
http://www.vanheusden.com/koudevoeten/

Tested it with kernel 3.10.27+.

clippax
Posts: 1
Joined: Wed Jan 15, 2014 5:00 pm

Re: Official V4L2 driver

Tue Jan 28, 2014 3:57 am

So, is anyone working on getting the "motion" (application) to work correctly with the official v4l2 driver?

I am using raspbian (2014-01-07) with custom compiled "motion" but I don't seem to get more than 2 fps.

Is anyone getting rates better than 2fps at 640x480 with motion?

Also, is there a way to tell motion to use the H264 stream from the camera to offload the CPU?

bsdz
Posts: 19
Joined: Mon Dec 30, 2013 5:00 pm

Re: Official V4L2 driver

Wed Feb 05, 2014 10:20 am

When trying to capture from camera in opencv one receives a "VIDIOC_QUERYMENU: Invalid argument" error. This is because opencv uses xioctl to check each control menu item and for some reason the camera controls doesn't set the correct maximum and minimum index on some menu items.

One can see this using v4l2-ctl --list-ctrls-menus

Code: Select all

      auto_exposure (menu)   : min=0 max=3 default=0 value=0
                0: Auto Mode
                1: Manual Mode

      white_balance_auto_preset (menu)   : min=0 max=9 default=1 value=1
                1: Auto
                2: Incandescent
                3: Fluorescent
                4: Fluorescent H
                5: Horizon
                6: Daylight
                7: Flash
                8: Cloudy
                9: Shade
The maximum for auto exposure is set to 3 but there are only 2 sub items. Likewise for white_balance_auto_preset the minimum is set to 0 but the first sub item starts at 1.

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

Re: Official V4L2 driver

Wed Feb 05, 2014 12:54 pm

bsdz wrote:When trying to capture from camera in opencv one receives a "VIDIOC_QUERYMENU: Invalid argument" error. This is because opencv uses xioctl to check each control menu item and for some reason the camera controls doesn't set the correct maximum and minimum index on some menu items.

One can see this using v4l2-ctl --list-ctrls-menus
<snip>

The maximum for auto exposure is set to 3 but there are only 2 sub items. Likewise for white_balance_auto_preset the minimum is set to 0 but the first sub item starts at 1.
Please don't cross post - you're unlikely to get two different answers, at least from us.
Reply made on http://www.raspberrypi.org/forum/viewto ... 43&t=65026. Suffice to say it appears to be bad handling within OpenCV of controls with the type of V4L2_CTRL_TYPE_MENU.
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.

robswain
Posts: 1
Joined: Thu Feb 06, 2014 5:03 pm

Re: Official V4L2 driver

Thu Feb 06, 2014 5:06 pm

Could the H264 Profile and Level configuration be exposed through V4L2 API? (V4L2_CID_MPEG_VIDEO_H264_PROFILE and V4L2_CID_MPEG_VIDEO_H264_LEVEL controls I think.)

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

Re: Official V4L2 driver

Thu Feb 06, 2014 6:36 pm

robswain wrote:Could the H264 Profile and Level configuration be exposed through V4L2 API? (V4L2_CID_MPEG_VIDEO_H264_PROFILE and V4L2_CID_MPEG_VIDEO_H264_LEVEL controls I think.)
That should be a trivial one to do.
I'm in the middle of something else at the moment, but will hopefully have a couple of updates pushed by the end of next week.
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.

towolf
Posts: 421
Joined: Fri Jan 18, 2013 2:11 pm

Re: Official V4L2 driver

Fri Feb 07, 2014 2:03 pm

Personally, I’m wondering how much of an impact intra-refresh would have on h264 encoding latencies. That is in the MMAL headers too.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23631
Joined: Sat Jul 30, 2011 7:41 pm

Re: Official V4L2 driver

Fri Feb 07, 2014 3:38 pm

towolf wrote:Personally, I’m wondering how much of an impact intra-refresh would have on h264 encoding latencies. That is in the MMAL headers too.
You can set intra-refresh in raspivid, so you can try it yourself already. Think it's -g IIRC. Unless I am thinking of something else.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

towolf
Posts: 421
Joined: Fri Jan 18, 2013 2:11 pm

Re: Official V4L2 driver

Fri Feb 07, 2014 7:27 pm

I don’t mean intra period or GOP length. I mean intra refresh, that column thing that can start to be decoded earlier.

I think you mentioned that the h264 block supports this?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23631
Joined: Sat Jul 30, 2011 7:41 pm

Re: Official V4L2 driver

Sat Feb 08, 2014 9:41 am

Sorry, misread your post.

I do have a recollection that intrarefresh is supported in the HW, but whether its possible to actually use it I don't know. You are correct that using it does mean you can reduce latency. I've seen it down to 15ms or less (after wireless transmission from one device to another) on similar HW but with lots of custom SW.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

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

Re: Official V4L2 driver

Mon Feb 10, 2014 12:20 pm

jamesh wrote:Sorry, misread your post.

I do have a recollection that intrarefresh is supported in the HW, but whether its possible to actually use it I don't know. You are correct that using it does mean you can reduce latency. I've seen it down to 15ms or less (after wireless transmission from one device to another) on similar HW but with lots of custom SW.
Stripe based encoding for low latency is NOT supported from the camera. As James says it requires a bundle of support software which becomes more hassle than it is worth.
I know the hardware supports (horizontal) slice mode to increase robustness, and that could reduce latency on the decode side (no gain on encode if we can't feed the data in in stripes). I'm not familiar with exactly what is needed to enable it though.

I don't believe the hardware supports encoding using a Periodic Intra Refresh to replace full keyframes with columns of intra macroblocks spread over several frames. It should decode it quite happily though.
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.

towolf
Posts: 421
Joined: Fri Jan 18, 2013 2:11 pm

Re: Official V4L2 driver

Tue Feb 11, 2014 4:47 pm

I see. Interesting, thanks.

airsports
Posts: 3
Joined: Wed Feb 12, 2014 8:14 am

Re: Official V4L2 driver

Wed Feb 12, 2014 8:20 am

How do I enable 'night' exposure mode?
As far as I can see, through v4l2-ctl I can only set auto_exposure to either 0 (auto) or 1 (manual). Am I missing something?

Return to “Camera board”