Official V4L2 driver


338 posts   Page 1 of 14   1, 2, 3, 4, 5 ... 14
by dom » Mon Dec 02, 2013 8:54 pm
rpi-update to get it. Consider this beta for now.

Some info is here (in linux tree):
https://github.com/raspberrypi/linux/bl ... 5-v4l2.txt

You need a version 1.0 or later of v4l2-ctl, available from:
git://git.linuxtv.org/v4l-utils.git

i.e
Code: Select all
sudo apt-get install autoconf gettext libtool libjpeg62-dev
cd v4l-utils
autoreconf -vfi
./configure
make
sudo make install

This takes about fifteen minutes.

You need to have camera enabled and sufficient gpu_mem configured (much like raspicam).
Some commands to get started:

# load the module
sudo modprobe bcm2835-v4l2

# viewfinder
v4l2-ctl --overlay=1 # enable viewfinder
v4l2-ctl --overlay=0 # disable viewfinder

# record video
v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.264

# capture jpeg
v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg

# set bitrate
v4l2-ctl --set-ctrl video_bitrate=10000000

# list supported formats
v4l2-ctl --list-formats

In theory (some) apps that use V4L should work. Report back what does work and what doesn't.
Thanks to Vincent Sanders at Collabora, and Luke Diamand and David Stevenson at Broadcom for working on this.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4059
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by jbeale » Mon Dec 02, 2013 9:02 pm
First thing I had to do was
Code: Select all
sudo apt-get install autoconf

to get the autoreconf command. EDIT: But maybe that wasn't enough, because it failed:
Code: Select all
pi@raspberrypi:~/v4l-utils$ autoreconf -vfi
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
configure.ac:173: warning: macro `AM_ICONV' not found in library
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --copy --force
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `build-aux'.
libtoolize: copying file `build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
configure.ac:173: warning: macro `AM_ICONV' not found in library
autoreconf: running: /usr/bin/autoconf --force
configure.ac:173: error: possibly undefined macro: AM_ICONV
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
Last edited by jbeale on Mon Dec 02, 2013 9:10 pm, edited 3 times in total.
User avatar
Posts: 2095
Joined: Tue Nov 22, 2011 11:51 pm
by dom » Mon Dec 02, 2013 9:03 pm
jbeale wrote:First thing I had to do was
Code: Select all
sudo apt-get install autoconf

to get the autoreconf command.

Thanks - added to instructions.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4059
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by jbeale » Mon Dec 02, 2013 9:06 pm
Do you get the same undefined macro: AM_ICONV error that I see? Is there another file I'm missing? The 'autoconf -vfi' step failed and ./configure will not proceed (configure: error: cannot find install-sh, install.sh or shtool in build-aux "."/build-aux )
Last edited by jbeale on Mon Dec 02, 2013 9:12 pm, edited 1 time in total.
User avatar
Posts: 2095
Joined: Tue Nov 22, 2011 11:51 pm
by dom » Mon Dec 02, 2013 9:12 pm
jbeale wrote:Do you get the same undefined macro: AM_ICONV error that I see? Is there another file I'm missing?

No it worked for me, but I've installed lots of things in the past.
Might be worth running:
Code: Select all
sudo apt-get install v4l-utils

first, to install the older v4l2 tools which may get some required dependencies. Then try building the newer code.

Some searching suggested:
Code: Select all
sudo apt-get install gettext
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4059
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by jbeale » Mon Dec 02, 2013 9:21 pm
dom wrote:Might be worth running:
Code: Select all
sudo apt-get install v4l-utils

first, to install the older v4l2 tools which may get some required dependencies. Then try building the newer code.

Some searching suggested:
Code: Select all
sudo apt-get install gettext

First I tried installing 'v4l-utils' but that was no help, I got exactly the same 'macro AM_ICONV not found in library' error as before. Then I installed 'gettext' and that fixed the problem. At least 'autoreconf -vfi' worked without error, and now I am able to proceed with ./configure
User avatar
Posts: 2095
Joined: Tue Nov 22, 2011 11:51 pm
by dom » Mon Dec 02, 2013 9:26 pm
jbeale wrote:Then I installed 'gettext' and that fixed the problem. At least 'autoreconf -vfi' worked without error, and now I am able to proceed with ./configure

Added to first post.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4059
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by jbeale » Mon Dec 02, 2013 9:40 pm
Ok, well ./configure worked OK and 'make' worked away industriously for maybe 10 minutes, and then reported this error:
Code: Select all
Making all in rds
make[3]: Entering directory `/home/pi/v4l-utils/utils/rds'
  CC     rds-saa6588.o
In file included from rds-saa6588.c:16:0:
/usr/include/linux/i2c-dev.h:38:8: error: redefinition of âstruct i2c_msgâ
/usr/include/linux/i2c.h:67:8: note: originally defined here
/usr/include/linux/i2c-dev.h:90:7: error: redefinition of âunion i2c_smbus_dataâ
/usr/include/linux/i2c.h:125:7: note: originally defined here
make[3]: *** [rds-saa6588.o] Error 1
make[3]: Leaving directory `/home/pi/v4l-utils/utils/rds'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/pi/v4l-utils/utils'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/pi/v4l-utils'
make: *** [all] Error 2

This same error was reported by 'subnet' back on 14 Jul 2013 when attempting to compile i2c-arduino in this post. Unfortunately no one has since replied to that post.

EDIT: There may be some naming conflict if you have previously done 'sudo apt-get install libi2c-dev' which I think is where /usr/include/linux/i2c-dev.h came from? investigating... confirmed. I was able to fix that error by executing 'sudo apt-get remove libi2c-dev'. I suppose you would not have the error if you had not previously installed libi2c-dev.
Last edited by jbeale on Mon Dec 02, 2013 10:55 pm, edited 2 times in total.
User avatar
Posts: 2095
Joined: Tue Nov 22, 2011 11:51 pm
by dom » Mon Dec 02, 2013 9:48 pm
jbeale wrote:Ok, well ./configure worked OK and 'make' worked away industriously for maybe 10 minutes, and then reported this error:


From http://ubuntuforums.org/archive/index.p ... 33646.html
Code: Select all
sudo apt-get remove libi2c-dev


You could try my v4l2-ctl, but I don't know if there are other requirements aparts from the linked libs:
https://dl.dropboxusercontent.com/u/366 ... p/v4l2-ctl
https://dl.dropboxusercontent.com/u/366 ... nvert.so.0
https://dl.dropboxusercontent.com/u/366 ... bv4l2.so.0
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4059
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by jbeale » Mon Dec 02, 2013 11:10 pm
Got it working. After 'sudo modprobe bcm2835-v4l2' and 'v4l2-ctl --overlay=1' I see the live camera view in the background of the console. My particular conflict with the struct i2c_msg definition was fixed by 'sudo apt-get remove libi2c-dev' and probably most people will not see it because they hadn't installed that header file.

Now the standard 'motion' package works, and is able to save JPEG files at roughly 30 fps at a resolution of 352x288 (with CPU nearly 100%). That was never possible with the RPi-specific motion-mmal program which I found was limited to a much lower frame rate even at very low resolutions. It can also run at 1280x720 at 5 fps but it can only save JPEGs at about 1 fps at that resolution, as it is doing the JPEG encoding on the ARM. I get a detection latency of about 140 msec at 64x32 pixels 30 fps with about 2% CPU (not saving any files, just pulsing a GPIO output from the on_event_start line).
Code: Select all
sudo apt-get install motion

Code: Select all
pi@raspberrypi:/run/shm$ motion
[0] could not open configfile /etc/motion/motion.conf: No such file or directory
[0] Not config file to process using default values
[0] Motion 3.2.12 Started
[0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478785
[1] Thread 1 started
[1] cap.driver: "bm2835 mmal"
[1] cap.card: "mmal service 15.1"
[1] cap.bus_info: "platform:bcm2835-v4l2"
[1] cap.capabilities=0x85000005
[1] - VIDEO_CAPTURE
[1] - VIDEO_OVERLAY
[1] - READWRITE
[1] - STREAMING
[1] Test palette YU12 (352x288)
[1] Using palette YU12 (352x288) bytesperlines 528 sizeimage 152064 colorspace 00000008
[1] found control 0x00980900, "Brightness", range 0,100
[1]     "Brightness", default 50, current 50
[1] found control 0x00980901, "Contrast", range -100,100
[1]     "Contrast", default 0, current 0
[1] found control 0x00980902, "Saturation", range -100,100
[1]     "Saturation", default 0, current 0
[1] mmap information:
[1] frames=4
[1] 0 length=152064
[1] 1 length=152064
[1] 2 length=152064
[1] 3 length=152064
[1] Using V4L2
[1] Resizing pre_capture buffer to 1 items
[1] File of type 1 saved to: ./01-20131202154257-27.jpg
[1] File of type 1 saved to: ./01-20131202154257-28.jpg
[1] File of type 1 saved to: ./01-20131202154258-00.jpg
[1] File of type 1 saved to: ./01-20131202154258-01.jpg
[1] File of type 1 saved to: ./01-20131202154258-02.jpg
[1] File of type 1 saved to: ./01-20131202154258-03.jpg
[1] File of type 1 saved to: ./01-20131202154258-04.jpg
[1] File of type 1 saved to: ./01-20131202154258-05.jpg
[1] File of type 1 saved to: ./01-20131202154258-06.jpg
[1] File of type 1 saved to: ./01-20131202154258-07.jpg
[1] File of type 1 saved to: ./01-20131202154258-08.jpg
[1] File of type 1 saved to: ./01-20131202154258-09.jpg
[1] File of type 1 saved to: ./01-20131202154258-10.jpg
[1] File of type 1 saved to: ./01-20131202154258-11.jpg
[1] File of type 1 saved to: ./01-20131202154258-12.jpg
[1] File of type 1 saved to: ./01-20131202154258-13.jpg
[1] File of type 1 saved to: ./01-20131202154258-14.jpg
[1] File of type 1 saved to: ./01-20131202154258-15.jpg
[1] File of type 1 saved to: ./01-20131202154258-17.jpg
[1] File of type 1 saved to: ./01-20131202154258-18.jpg
[1] File of type 1 saved to: ./01-20131202154258-19.jpg
[1] File of type 1 saved to: ./01-20131202154258-20.jpg
[1] File of type 1 saved to: ./01-20131202154258-21.jpg
[1] File of type 1 saved to: ./01-20131202154258-22.jpg
[1] File of type 1 saved to: ./01-20131202154258-23.jpg
[1] File of type 1 saved to: ./01-20131202154258-24.jpg
[1] File of type 1 saved to: ./01-20131202154258-25.jpg
[1] File of type 1 saved to: ./01-20131202154258-26.jpg
[1] File of type 1 saved to: ./01-20131202154258-27.jpg
[1] File of type 1 saved to: ./01-20131202154258-28.jpg
[1] File of type 1 saved to: ./01-20131202154258-29.jpg
[1] File of type 1 saved to: ./01-20131202154259-00.jpg
[1] File of type 1 saved to: ./01-20131202154259-01.jpg
[1] File of type 1 saved to: ./01-20131202154259-02.jpg

Code: Select all
pi@raspberrypi:/run/shm$ v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
        Index       : 0
        Type        : Video Capture
        Pixel Format: 'YU12'
        Name        : 4:2:0, packed YUV

        Index       : 1
        Type        : Video Capture
        Pixel Format: 'YUYV'
        Name        : 4:2:2, packed, YUYV

        Index       : 2
        Type        : Video Capture
        Pixel Format: 'BGR3'
        Name        : RGB24 (BE)

        Index       : 3
        Type        : Video Capture
        Pixel Format: 'JPEG'
        Name        : JPEG

        Index       : 4
        Type        : Video Capture
        Pixel Format: 'H264'
        Name        : H264
Last edited by jbeale on Tue Dec 03, 2013 1:41 am, edited 2 times in total.
User avatar
Posts: 2095
Joined: Tue Nov 22, 2011 11:51 pm
by jbeale » Tue Dec 03, 2013 12:07 am
Motion works using the YU12 format output. It does not work if you select the JPEG format output instead of YU12 in the motion.config setup file.
Code: Select all
pi@raspberrypi:/etc/motion$ motion
[0] Processing thread 0 - config file /etc/motion/motion.conf
[0] Motion 3.2.12 Started
[0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478785
[0] Thread 1 is from /etc/motion/motion.conf
[0] motion-httpd/3.2.12 running, accepting connections
[0] motion-httpd: waiting for data on port TCP 8080
[1] Thread 1 started
[1] cap.driver: "bm2835 mmal"
[1] cap.card: "mmal service 15.1"
[1] cap.bus_info: "platform:bcm2835-v4l2"
[1] cap.capabilities=0x85000005
[1] - VIDEO_CAPTURE
[1] - VIDEO_OVERLAY
[1] - READWRITE
[1] - STREAMING
[1] Test palette JPEG (1280x720)
[1] Using palette JPEG (1280x720) bytesperlines 1280 sizeimage 921600 colorspace 00000008
[1] found control 0x00980900, "Brightness", range 0,100
[1]     "Brightness", default 50, current 50
[1] found control 0x00980901, "Contrast", range -100,100
[1]     "Contrast", default 0, current 0
[1] found control 0x00980902, "Saturation", range -100,100
[1]     "Saturation", default 0, current 0
[1] mmap information:
[1] frames=4
[1] 0 length=921600
[1] 1 length=921600
[1] 2 length=921600
[1] 3 length=921600
[1] Error starting stream VIDIOC_STREAMON: Operation not permitted
[1] ioctl (VIDIOCGCAP): Inappropriate ioctl for device
[1] Could not fetch initial image from camera


If I try it with 'sudo motion' then I get a crash.
Code: Select all
pi@raspberrypi:/etc/motion$ sudo motion
[0] Processing thread 0 - config file /etc/motion/motion.conf
[0] Motion 3.2.12 Started
[0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478785
[0] Thread 1 is from /etc/motion/motion.conf
[0] motion-httpd/3.2.12 running, accepting connections
[0] motion-httpd: waiting for data on port TCP 8080
[1] Thread 1 started
[1] cap.driver: "bm2835 mmal"
[1] cap.card: "mmal service 15.1"
[1] cap.bus_info: "platform:bcm2835-v4l2"
[1] cap.capabilities=0x85000005
[1] - VIDEO_CAPTURE
[1] - VIDEO_OVERLAY
[1] - READWRITE
[1] - STREAMING
[1] Test palette JPEG (1280x720)
[1] Using palette JPEG (1280x720) bytesperlines 1280 sizeimage 921600 colorspace 00000008
[1] found control 0x00980900, "Brightness", range 0,100
[1]     "Brightness", default 50, current 50
[1] found control 0x00980901, "Contrast", range -100,100
[1]     "Contrast", default 0, current 0
[1] found control 0x00980902, "Saturation", range -100,100
[1]     "Saturation", default 0, current 0
[1] mmap information:
[1] frames=4
[1] 0 length=921600
[1] 1 length=921600
[1] 2 length=921600
[1] 3 length=921600
[1] Using V4L2
[1] Resizing pre_capture buffer to 1 items
[ 3880.191236] Unable to handle kernel paging request at virtual address 00100104
[ 3880.198472] pgd = c0004000
[ 3880.201175] [00100104] *pgd=00000000
[ 3880.204758] Internal error: Oops: 817 [#1] PREEMPT ARM

Entering kdb (current=0xc691d5c0, pid 30) Oops: (null)
due to oops @ 0xbf16dfd0

dCPU: 0 PID: 30 Comm: VCHIQ-0 Not tainted 3.10.21+ #604
dtask: c691d5c0 ti: c6986000 task.ti: c6986000
PC is at service_callback+0x1c4/0x530 [bcm2835_v4l2]
LR is at 0x200200
pc : [<bf16dfd0>]    lr : [<00200200>]    psr: 20000093
sp : c6987ea8  ip : 00100100  fp : 00009e96
r10: c2cbc010  r9 : c2c90580  r8 : c6987eb8
r7 : c7017900  r6 : c2cbc000  r5 : 00000002  r4 : 00100100
r3 : c6986000  r2 : c46746a0  r1 : 00200200  r0 : 60000013
Flags: nzCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment kernel
Control: 00c5387d  Table: 05290008  DAC: 00000017
dCPU: 0 PID: 30 Comm: VCHIQ-0 Not tainted 3.10.21+ #604
[<c00139f8>] (unwind_backtrace+0x0/0xf0) from [<c0010d5c>] (show_stack+0x10/0x14)
[<c0010d5c>] (show_stack+0x10/0x14) from [<c00765f8>] (kdb_dumpregs+0x28/0x50)
[<c00765f8>] (kdb_dumpregs+0x28/0x50) from [<c0078868>] (kdb_main_loop+0x3c0/0x6c0)
[<c0078868>] (kdb_main_loop+0x3c0/0x6c0) from [<c007af68>] (kdb_stub+0x154/0x380)
[<c007af68>] (kdb_stub+0x154/0x380) from [<c0072150>] (kgdb_handle_exception+0x32c/0x6c0)
[<c0072150>] (kgdb_handle_exception+0x32c/0x6c0) from [<c0013178>] (kgdb_notify+0x24/0x40)
[<c0013178>] (kgdb_notify+0x24/0x40) from [<c03fb688>] (notifier_call_chain+0x44/0x84)
[<c03fb688>] (notifier_call_chain+0x44/0x84) from [<c03fb700>] (__atomic_notifier_call_chain+0x38/0x4c)
[<c03fb700>] (__atomic_notifier_call_chain+0x38/0x4c) from [<c03fb72c>] (atomic_notifier_call_chain+0x18/0x20)
[<c03fb72c>] (atomic_notifier_call_chain+0x18/0x20) from [<c03fb76c>] (notify_die+0x38/0x44)
[<c03fb76c>] (notify_die+0x38/0x44) from [<c0010e24>] (die+0xc4/0x3a8)
[<c0010e24>] (die+0xc4/0x3a8) from [<c03f372c>] (__do_kernel_fault.part.9+0x54/0x74)
[<c03f372c>] (__do_kernel_fault.part.9+0x54/0x74) from [<c03fb3b4>] (do_page_fault+0x1dc/0x3c4)
[<c03fb3b4>] (do_page_fault+0x1dc/0x3c4) from [<c000834c>] (do_DataAbort+0x34/0x98)
[<c000834c>] (do_DataAbort+0x34/0x98) from [<c03f9bf8>] (__dabt_svc+0x38/0x60)
Exception stack(0xc6987e60 to 0xc6987ea8)
7e60: 60000013 00200200 c46746a0 c6986000 00100100 00000002 c2cbc000 c7017900
7e80: c6987eb8 c2c90580 c2cbc010 00009e96 00100100 c6987ea8 00200200 bf16dfd0
7ea0: 20000093 ffffffff
[<c03f9bf8>] (__dabt_svc+0x38/0x60) from [<bf16dfd0>] (service_callback+0x1c4/0x530 [bcm2835_v4l2])
[<bf16dfd0>] (service_callback+0x1c4/0x530 [bcm2835_v4l2]) from [<c028c47c>] (shim_callback+0xbc/0x10c)
[<c028c47c>] (shim_callback+0xbc/0x10c) from [<c02866a4>] (slot_handler_func+0xde4/0x1708)
[<c02866a4>] (slot_handler_func+0xde4/0x1708) from [<c003c750>] (kthread+0xa4/0xb0)
[<c003c750>] (kthread+0xa4/0xb0) from [<c000db58>] (ret_from_fork+0x14/0x3c)

Also, as far as I can tell 'xawtv' does not work. Looks like there is some problem with using /usr/bin/v4l-conf? Is the program supposed to be using /usr/local/bin/v4l2-ctl instead? I'm not familiar with the v4l2 world so I don't know if those two programs are supposed to do the same tasks (?)
User avatar
Posts: 2095
Joined: Tue Nov 22, 2011 11:51 pm
by fernandovg » Tue Dec 03, 2013 12:54 am
I got this error trying to build v4l-utils
Raspbmc:
https://www.dropbox.com/sc/yqxbvgmaxhc526m/3Q39QItwSj
Posts: 13
Joined: Wed Sep 26, 2012 6:59 pm
by jbeale » Tue Dec 03, 2013 5:50 am
if you get error: possibly undefined macro: AC_PROG_LIBTOOL (as I just did, building on a second R-Pi board) the solution is to install libtool. And you also need jpeglib.h which is not in raspbian by default. So the whole sequence should be:
Code: Select all
sudo apt-get install autoconf gettext libtool libjpeg62-dev
git clone git://git.linuxtv.org/v4l-utils.git
cd v4l-utils
autoreconf -vfi
./configure
make
sudo make install
User avatar
Posts: 2095
Joined: Tue Nov 22, 2011 11:51 pm
by tommybobbins » Tue Dec 03, 2013 9:36 am
jbeale wrote:if you get error: possibly undefined macro: AC_PROG_LIBTOOL (as I just did, building on a second R-Pi board) the solution is to install libtool. And you also need jpeglib.h which is not in raspbian by default. So the whole sequence should be:
Code: Select all
sudo apt-get install autoconf gettext libtool libjpeg62-dev
git clone git://git.linuxtv.org/v4l-utils.git
cd v4l-utils
autoreconf -vfi
./configure
make
sudo make install


Hello,

Did you have to run
Code: Select all
libtoolize --force


to reconfigure the configure.ac for the m4 macro error above?
Posts: 3
Joined: Tue Oct 22, 2013 8:31 am
by towolf » Tue Dec 03, 2013 4:14 pm
Sweet! I've been waiting for this. Gonna test soon.

Why does it say "Authored 10 months ago" on GitHub?
Posts: 388
Joined: Fri Jan 18, 2013 2:11 pm
by poing » Tue Dec 03, 2013 4:30 pm
Noob question: Why do I want this? What does it do?

Thanks!
Posts: 1097
Joined: Thu Mar 08, 2012 3:32 pm
by towolf » Tue Dec 03, 2013 4:34 pm
It's a kernel driver that is written according to the standard video2linux specification.

Most software on Linux requires video4linux drivers.

The cludge with piping video to other software is unnecessary now. Provided it works properly.

And proper timestamps allowing VFR, and easy muxing, e.g., with gstreamer.

I wonder if they sorted out full-frame video.
Posts: 388
Joined: Fri Jan 18, 2013 2:11 pm
by fernandovg » Tue Dec 03, 2013 4:45 pm
How to check it was installed ok?

I got this:
Code: Select all
checking for gawk... no
checking for QT... no
checking for QTGL... no
checking for ALSA... no
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether we are cross compiling... no
checking for dlltool... no
checking for sysroot... no
checking if mt is a manifest tool... no
checking if gcc -std=gnu99 supports -fno-rtti -fno-exceptions... no
checking whether -lc should be explicitly linked in... no
checking for X11... no


in /usr/local/bin I have some new files with "v4l2" and "dvbv5" in the name

Also If I run this I get:

Code: Select all
pi@raspbmc: sudo dpkg-query -l '*v4l*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Nome                       Versăo             Arquitectura       Descriçăo
+++-==========================-==================-==================-==========================================================
ii  libv4l-0:armhf             0.8.8-3            armhf              Collection of video4linux support libraries
ii  libv4lconvert0:armhf       0.8.8-3            armhf              Video4linux frame format conversion library
ii  v4l-conf                   3.102-3            armhf              tool to configure video4linux drivers
Posts: 13
Joined: Wed Sep 26, 2012 6:59 pm
by jamesh » Tue Dec 03, 2013 4:53 pm
towolf wrote:I wonder if they sorted out full-frame video.


No, that's a GPU side issue, nothing to do with the Arm side code.
Volunteer at the Raspberry Pi Foundation, helper at Picademy September and October 2014.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 12113
Joined: Sat Jul 30, 2011 7:41 pm
by jbeale » Tue Dec 03, 2013 4:59 pm
fernandovg wrote:How to check it was installed ok?

Try to take a picture and see if it works:
Code: Select all
sudo modprobe bcm2835-v4l2
v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=test1.jpg

If you don't see any error messages and find a valid JPEG file "test1.jpg" in your current directory, then the driver is installed and working.
User avatar
Posts: 2095
Joined: Tue Nov 22, 2011 11:51 pm
by jbeale » Tue Dec 03, 2013 5:29 pm
So far I have the new V4L2 driver installed and working on two different R-Pis, so that is good. The apt-get version of motion ( Version 3.2.12, Copyright 2000-2005 ) works, at least in the default 'YU12' mode, although not in 'JPEG' mode so far. I notice that many jpeg images saved by motion appear somewhat overexposed, for some reason.

The raspicam and raspistill applications have a lot of control over camera parameters like ISO, shutter speed, etc. Is that level of control possible through v4l2-ctl or other interface? If so, an example of the command would be great.
User avatar
Posts: 2095
Joined: Tue Nov 22, 2011 11:51 pm
by towolf » Tue Dec 03, 2013 5:36 pm
Normally you can enumerate the controls a v4l driver exposes. Does this v4l tool have a command line option like "list controls"?
Posts: 388
Joined: Fri Jan 18, 2013 2:11 pm
by jbeale » Tue Dec 03, 2013 5:41 pm
Ok, looks like this is what we have:
Code: Select all
pi@raspberrypi:~/test$ v4l2-ctl --list-ctrls

User Controls

                     brightness (int)    : min=0 max=100 step=1 default=50 value=50 flags=slider
                       contrast (int)    : min=-100 max=100 step=1 default=0 value=0 flags=slider
                     saturation (int)    : min=-100 max=100 step=1 default=0 value=0 flags=slider
                horizontal_flip (bool)   : default=0 value=0
                  vertical_flip (bool)   : default=0 value=0
                      sharpness (int)    : min=-100 max=100 step=1 default=0 value=0 flags=slider
                  color_effects (menu)   : min=0 max=15 default=0 value=0
                         rotate (int)    : min=0 max=360 step=90 default=0 value=0
             color_effects_cbcr (int)    : min=0 max=65535 step=1 default=32896 value=32896

MPEG Encoder Controls

             video_bitrate_mode (menu)   : min=0 max=1 default=0 value=0 flags=update
                  video_bitrate (int)    : min=25000 max=25000000 step=25000 default=10000000 value=10000000

Camera Controls

                  auto_exposure (menu)   : min=0 max=3 default=0 value=0
             auto_exposure_bias (intmenu): min=0 max=16 default=8 value=8
      white_balance_auto_preset (menu)   : min=0 max=9 default=1 value=1
            image_stabilization (bool)   : default=0 value=0
                iso_sensitivity (intmenu): min=0 max=4 default=0 value=0
         exposure_metering_mode (menu)   : min=0 max=2 default=0 value=0

JPEG Compression Controls

            compression_quality (int)    : min=0 max=100 step=1 default=30 value=30

and it does seem to work, see the file size change:
Code: Select all
v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
v4l2-ctl --set-ctrl compression_quality=1
v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=test01.jpg
v4l2-ctl --set-ctrl compression_quality=100
v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=test100.jpg

-rw-r--r-- 1 pi pi  106507 Dec  3 09:45 test01.jpg
-rw-r--r-- 1 pi pi 2405248 Dec  3 09:46 test100.jpg

By the way the minimum value of "compression_quality" is actually 1 despite what the controls list shows. Setting 0 gives an error:
Code: Select all
pi@raspberrypi:~/test$ v4l2-ctl --set-ctrl compression_quality=1
pi@raspberrypi:~/test$ v4l2-ctl --set-ctrl compression_quality=0
VIDIOC_S_EXT_CTRLS: failed: No such process
compression_quality: No such process
Last edited by jbeale on Tue Dec 03, 2013 5:54 pm, edited 2 times in total.
User avatar
Posts: 2095
Joined: Tue Nov 22, 2011 11:51 pm
by towolf » Tue Dec 03, 2013 5:52 pm
I don't know if guvcview is available on raspbian. It's a GTK GUI program that allows you to control the stuff with sliders.

guvcview -o just shows the controls with no preview.

My Apple LCD at work has these:

Code: Select all
                     brightness (int)    : min=-127 max=127 step=1 default=0 value=0
                       contrast (int)    : min=0 max=64 step=1 default=32 value=32
                     saturation (int)    : min=0 max=128 step=1 default=64 value=64
                            hue (int)    : min=-4500 max=4500 step=100 default=0 value=0
 white_balance_temperature_auto (bool)   : default=1 value=1
                          gamma (int)    : min=100 max=220 step=120 default=220 value=220
           power_line_frequency (menu)   : min=0 max=2 default=3 value=3
      white_balance_temperature (int)    : min=2800 max=6500 step=1 default=6500 value=6500 flags=inactive
                      sharpness (int)    : min=0 max=16 step=1 default=8 value=8
         backlight_compensation (int)    : min=0 max=1 step=1 default=1 value=1
                  exposure_auto (menu)   : min=0 max=3 default=0 value=0
              exposure_absolute (int)    : min=100 max=10000 step=1 default=300 value=300 flags=inactive


exposure_auto and exposure_absolute would be interesting. And white_balance_temperature.

And we need to document the settings the numeric values correspond to.
Posts: 388
Joined: Fri Jan 18, 2013 2:11 pm
by jbeale » Tue Dec 03, 2013 6:10 pm
Yes, it works, at least somewhat.
Code: Select all
sudo apt-get install guvcview

Image
I notice when guvcview is running, the CPU is pegged at 100% (75% guvcview and 21% Xorg), I guess rendering the live update window at 480x480 25 fps takes all the CPU. There is a two-option setting for "Auto Exposure" which is either auto or manual. However in "manual" mode there are no actual manual controls to set. Setting manual exposure does lock the exposure to the current settings, so subsequent darker or brighter scenes can go to full black or full white. There is a long list of "Color Effects" like Emboss, Solarization etc. which do work. The "Cap. Image" button does capture to "Image.jpg" in the current directory.
If you scroll down in the controls window (hidden in screen cap above) there is an item marked "JPEG Compression Controls:" but it is blank, there are no actual controls shown.
If you select the "Video and Files" tab there is a "Resolution:" pulldown menu but 480x480 is the only item available. Likewise, there is a "Frame Rate:" menu but 25 fps is the only option. There is a "Camera Output:" menu set to YU12. It offers the options YU12, YUYV, BGR3, JPEG, RGB3, YV12. The BGR3 and RGB3 modes work. If you select YUYV or JPEG it crashes with Segmentation fault. You also get a segfault just by quitting normally ("Quit" button).

The full text output (program startup, and then quit) is here:
Code: Select all
pi@raspberrypi ~ $ guvcview
guvcview 1.5.3
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
video device: /dev/video0
Unable to find parent usb device.Init. mmal service 15.1 (location: platform:bcm2835-v4l2)
{ pixelformat = 'YU12', description = '4:2:0, packed YUV' }
{ ?GSPCA? : width = 480, height = 480 }
fmtind:1 fsizeind: 1
{ pixelformat = 'YUYV', description = '4:2:2, packed, YUYV' }
VIDIOC_ENUM_FRAMESIZES - Error enumerating frame sizes: Inappropriate ioctl for device
  Unable to enumerate frame sizes.
: Inappropriate ioctl for device
{ pixelformat = 'BGR3', description = 'RGB24 (BE)' }
{ ?GSPCA? : width = 480, height = 480 }
fmtind:3 fsizeind: 1
{ pixelformat = 'JPEG', description = 'JPEG' }
VIDIOC_ENUM_FRAMESIZES - Error enumerating frame sizes: Inappropriate ioctl for device
  Unable to enumerate frame sizes.
: Inappropriate ioctl for device
{ pixelformat = 'H264', description = 'H264' }
   { not supported - request format(875967048) support at http://guvcview.sourceforge.net }
{ pixelformat = 'RGB3', description = 'RGB3' }
{ ?GSPCA? : width = 480, height = 480 }
fmtind:5 fsizeind: 1
{ pixelformat = 'YV12', description = 'YV12' }
{ ?GSPCA? : width = 480, height = 480 }
fmtind:6 fsizeind: 1
vid:6469762f
pid:6c346f65
driver:bm2835 mmal
checking format: 842093913
Unable to set 1/25 fps
VIDIOC_S_PARM error: Inappropriate ioctl for device
VIDIOC_G_PARM - Unable to get timeperframe: Inappropriate ioctl for device
fps is set to 1/25
drawing controls

control type: 0x00000006 not supported
control type: 0x00000006 not supported
control type: 0x00000006 not supported
control type: 0x00000009 not supported
control type: 0x00000009 not supported
control type: 0x00000006 not supported
fps is set to 1/25
Checking video mode 480x480@32bpp : OK
write /home/pi/.guvcviewrc OK
Segmentation fault
User avatar
Posts: 2095
Joined: Tue Nov 22, 2011 11:51 pm