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

Re: Official V4L2 driver

Mon Dec 23, 2013 10:00 pm

jamesh wrote:Did you add the option to raspivid to select H264 or MJPEG? Cannot look at the moment! I can add it tomorrow if it's working OK.
No. I'm leaving RaspiVid to you, and only updating the V4L2 driver.

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

Re: Official V4L2 driver

Mon Dec 23, 2013 10:21 pm

Cool I'll sort raspivid tomorrow.
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."

olifre
Posts: 3
Joined: Mon Dec 23, 2013 11:49 pm

Re: Official V4L2 driver

Mon Dec 23, 2013 11:56 pm

Hi,
thanks for the great work!
Seeing the mjpeg and h264 formats supported by the v4l2 device, I hoped it could work with avconv / ffserver, but:

Code: Select all

avconv -f video4linux2 -list_formats all -i /dev/video0
avconv version 0.8.6-6:0.8.6-1+rpi1, Copyright (c) 2000-2013 the Libav developers
  built on Mar 31 2013 13:58:10 with gcc 4.6.3
[video4linux2 @ 0x11b8c00] R :   yuv420p :    4:2:0, packed YUV :
[video4linux2 @ 0x11b8c00] R :   yuyv422 :  4:2:2, packed, YUYV :
[video4linux2 @ 0x11b8c00] R :     bgr24 :           RGB24 (BE) :
[video4linux2 @ 0x11b8c00] R : Unsupported :                 JPEG :
[video4linux2 @ 0x11b8c00] R : Unsupported :                 H264 :
[video4linux2 @ 0x11b8c00] R : Unsupported :                MJPEG :
Is there something else to be done to allow ffserver to directly distribute the mjpeg / h264 stream? It appears to me that this might be the fastest streaming solution (or at least the one with the least overhead), and "according to the internet", other people with different cameras have a working setup in which ffserver can directly access MJPEG from the camera.

If somebody has another nice solution to stream the camera video using the new v4l2 device without any transcoding overhead, please point it out to me (would gstreamer work without overhead?).

Cheers,
Oliver

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

Re: Official V4L2 driver

Tue Dec 24, 2013 5:25 am

6by9 wrote:Good news for those after MJPEG - I have something working that is producing a nice stream of JPEGs. VLC doesn't like it (just displays the first frame, but does correctly get the clip duration as 10s long), but omxplayer is quite happy. v4l2-ctl claims to be getting 30fps at 1920x1080 from it too. [...]And you all thought Santa was due tomorrow night :D Happy Christmas!
Great work- the idea of MJPEG at 1080p30 is amazing, I did not think that was possible.

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1425
Joined: Sat Sep 10, 2011 11:43 am

Re: Official V4L2 driver

Tue Dec 24, 2013 7:00 am

It's easy to do it on the Pi GPU, because it has all the hardware goodness to do it (it has dedicated hardware for all of this pipeline!)

The problem will be taking that data and doing something with it! I guess it depends on the bitrate!

Gordon
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Official V4L2 driver

Tue Dec 24, 2013 7:15 am

Does not seem to work with motion:
$ motion
[0] Processing thread 0 - config file motion.conf
[0] Motion 3.2.12 Started
[0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478785
[0] Thread 1 is from 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 MJPG (640x480)
[1] Using palette MJPG (640x480) bytesperlines 640 sizeimage 307200 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=307200
[1] 1 length=307200
[1] 2 length=307200
[1] 3 length=307200
[1] Using V4L2
[1] Resizing pre_capture buffer to 1 items
Segmentation fault


If I first use working palette YU12 (motion 8), I get different error:
$ motion
[0] Processing thread 0 - config file motion.conf
[0] Motion 3.2.12 Started
[0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478785
[0] Thread 1 is from 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 MJPG (640x480)
[1] Error setting pixel format VIDIOC_S_FMT: Timer expired
[1] Config palette index 2 (MJPG) doesn't work.
[1] Supported palettes:
[1] 0: YU12 (4:2:0, packed YUV)
[1] 1: YUYV (4:2:2, packed, YUYV)
[1] 2: BGR3 (RGB24 (BE))
[1] 3: JPEG (JPEG)
[1] 4: H264 (H264)
[1] 5: MJPG (MJPEG)
[1] Selected palette YU12

But it does not work and I soon get the same timer expired.

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

Re: Official V4L2 driver

Tue Dec 24, 2013 9:13 am

jbeale wrote:
6by9 wrote:Good news for those after MJPEG - I have something working that is producing a nice stream of JPEGs. VLC doesn't like it (just displays the first frame, but does correctly get the clip duration as 10s long), but omxplayer is quite happy. v4l2-ctl claims to be getting 30fps at 1920x1080 from it too. [...]And you all thought Santa was due tomorrow night :D Happy Christmas!
Great work- the idea of MJPEG at 1080p30 is amazing, I did not think that was possible.
You might be pushing it to get 1080p30 - not sure the jpg encoder is that fast, but I saw it tested yesterday at 720p30 which was OK. As Gordon said,you might start seeing bandwidth problems as MJPG takes up much more of it than H264.
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."

tauceti
Posts: 3
Joined: Tue Dec 10, 2013 12:01 am

Re: Official V4L2 driver

Tue Dec 24, 2013 11:28 am

Hi,

after installing the utils I get:
pi@raspberrypi ~ $ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.264
VIDIOC_STREAMON: failed: Invalid argument

Does anyone know what is wrong?
I loaded the module before:
pi@raspberrypi ~ $ ls -l /dev/video0
crw-rw---T 1 root video 81, 0 Dez 24 12:15 /dev/video0

syslog says:
Dec 24 12:32:14 raspberrypi kernel: [ 2428.225740] bcm2835_v4l2: error 0 waiting for sync completion
Dec 24 12:32:15 raspberrypi kernel: [ 2429.255800] bcm2835_v4l2: error 0 waiting for sync completion
Dec 24 12:32:15 raspberrypi kernel: [ 2429.255839] bcm2835-v4l2: Failed enabling camera, ret -62
Dec 24 12:32:15 raspberrypi kernel: [ 2429.255852] bcm2835-v4l2: Failed to enable camera


Does anyone know what is wrong?

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

Re: Official V4L2 driver

Tue Dec 24, 2013 1:09 pm

jamesh wrote:
jbeale wrote:Great work- the idea of MJPEG at 1080p30 is amazing, I did not think that was possible.
You might be pushing it to get 1080p30 - not sure the jpg encoder is that fast, but I saw it tested yesterday at 720p30 which was OK. As Gordon said,you might start seeing bandwidth problems as MJPG takes up much more of it than H264.
1080p30 works, at least over 200 frames according to v4l2-ctl. Whether it keeps up over a longer period I can't say.
IIRC the JPEG block was supposedly rated somewhere around 80-100MPix/s, so that would mean 1080p30 was within reach, so I can believe the numbers :-)
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.

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

Re: Official V4L2 driver

Tue Dec 24, 2013 1:13 pm

Since you are here..

Been trying to get raspivid working with mjpg. Am getting output of about the right size, but omxplayer doesnt like it, and vlc just shows the first frame. Have tried MJPG, MJPA, MJPB, all similar results (although VLC did show differently for B, just one frame).

Interestingly, fbi will load the video as as single frame jpg, so there data is definitely in there..

I'm sure you said omxplayer would play the stream back...

James
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: 7149
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Official V4L2 driver

Tue Dec 24, 2013 1:40 pm

olifre wrote:Hi,
thanks for the great work!
Seeing the mjpeg and h264 formats supported by the v4l2 device, I hoped it could work with avconv / ffserver, but:
<snip>
Is there something else to be done to allow ffserver to directly distribute the mjpeg / h264 stream? It appears to me that this might be the fastest streaming solution (or at least the one with the least overhead), and "according to the internet", other people with different cameras have a working setup in which ffserver can directly access MJPEG from the camera.

If somebody has another nice solution to stream the camera video using the new v4l2 device without any transcoding overhead, please point it out to me (would gstreamer work without overhead?).

Cheers,
Oliver
I'm no expert on avconv (or V4L2 for that matter), but looking at the source of avconv via http://libav.org/doxygen/release/0.8/v4 ... tml#l00293 it appears to be doing different things based on "vfd.flags & V4L2_FMT_FLAG_COMPRESSED" and the value of "type" being passed in.
The driver is not setting the flag value with V4L2_FMT_FLAG_COMPRESSED for JPEG, MJPEG, or H264 at present, which may well be causing this issue.

If you fancied trying it yourself (I haven't got my setup running at the moment), then /drivers/media/platform/bcm2835/bcm2835-camera.c function vidioc_enum_fmt_vid_cap is the one you're after. Let us know the results, or I may have a play if I have the time over the break.
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.

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

Re: Official V4L2 driver

Tue Dec 24, 2013 1:58 pm

shuckle wrote:Does not seem to work with motion:
$ motion
[...]
[1] frames=4
[1] 0 length=307200
[1] 1 length=307200
[1] 2 length=307200
[1] 3 length=307200
[1] Using V4L2
[1] Resizing pre_capture buffer to 1 items
Segmentation fault


If I first use working palette YU12 (motion 8), I get different error:
$ motion
[0] Processing thread 0 - config file motion.conf
[0] Motion 3.2.12 Started
[0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478785
[...]
[1] Test palette MJPG (640x480)
[1] Error setting pixel format VIDIOC_S_FMT: Timer expired
[1] Config palette index 2 (MJPG) doesn't work.
[1] Supported palettes:
[1] 0: YU12 (4:2:0, packed YUV)
[...]
[1] 5: MJPG (MJPEG)
[1] Selected palette YU12

But it does not work and I soon get the same timer expired.
When trying to get motion to work with JPEG I was also seeing seg faults. If you run it via gdb, I was seeing it somewhere in a JPEG DCT function, which sort of implies that something is wrong with the JPEG decode. When selecting JPEG though, I was also getting very small buffers being passed out, but I hadn't had a chance to work out why. Trying to rebuild Motion to debug further was how I screwed up ffmpeg on my Pi :(

Any chance you could run it via gdb to see where it is blowing up please? ("gdb motion", "r<return>", and then probably "c<return>" a couple of times until it hits the seg fault). Whilst we'll do our best supporting this, it is still a spare-time project, so the more info you can feed us the better.

Second time through appears to be selecting MJPEG first, and then YU12 - that's a bit strange if you are sure you've set your config correctly to request YU12. I know for certain that Motion with YU12 was working, and the code to support that hasn't changed recently.
The driver isn't as polished as it could be, and if we get things too wrong then it can get the GPU into a weird state that the error handling code can't recover from. Can you try YU12 from a clean boot? It's possible that the selection of MJPEG and got us into a weird state. Thanks.

BTW Motion itself seems to have been updated since the version that is available via apt-get. YU12 is now format 17, not 8! The niggle is that you need to have all the relevant source files around for ffmpeg and the like to be able to rebuild it.
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.

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

Re: Official V4L2 driver

Tue Dec 24, 2013 2:05 pm

jamesh wrote:Since you are here..

Been trying to get raspivid working with mjpg. Am getting output of about the right size, but omxplayer doesnt like it, and vlc just shows the first frame. Have tried MJPG, MJPA, MJPB, all similar results (although VLC did show differently for B, just one frame).

Interestingly, fbi will load the video as as single frame jpg, so there data is definitely in there..

I'm sure you said omxplayer would play the stream back...

James
Odd. Are you just saving the data, no container or anything?
Just try out the V4L2 capture to confirm that it is working first:

Code: Select all

v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=5
v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.mjpg
omxplayer somefile.mjpg
I don't know what omxplayer is using to determine the codec/container type, and of course you have no headers so file extension is probably the key. I think I used .mjpg, and not .mjpeg - not got the work laptop powered up to check, but you've got the email, and my other files are on cam-a-b4 in a place you should be able to find quite easily.
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.

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

Re: Official V4L2 driver

Tue Dec 24, 2013 2:39 pm

6by9 wrote:
jamesh wrote:Since you are here..

Been trying to get raspivid working with mjpg. Am getting output of about the right size, but omxplayer doesnt like it, and vlc just shows the first frame. Have tried MJPG, MJPA, MJPB, all similar results (although VLC did show differently for B, just one frame).

Interestingly, fbi will load the video as as single frame jpg, so there data is definitely in there..

I'm sure you said omxplayer would play the stream back...

James
Odd. Are you just saving the data, no container or anything?
Just try out the V4L2 capture to confirm that it is working first:

Code: Select all

v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=5
v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.mjpg
omxplayer somefile.mjpg
I don't know what omxplayer is using to determine the codec/container type, and of course you have no headers so file extension is probably the key. I think I used .mjpg, and not .mjpeg - not got the work laptop powered up to check, but you've got the email, and my other files are on cam-a-b4 in a place you should be able to find quite easily.
Same output code as the H264 encode. So no containers etc. I'm using mjpg as the extension. However, have now run out of time, bearing in mind its now 5.30 (well, time go anyway). I'm back on 2nd, will try it then.
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."

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Official V4L2 driver

Tue Dec 24, 2013 2:42 pm

6by9 wrote:
When trying to get motion to work with JPEG I was also seeing seg faults. If you run it via gdb, I was seeing it somewhere in a JPEG DCT function, which sort of implies that something is wrong with the JPEG decode. When selecting JPEG though, I was also getting very small buffers being passed out, but I hadn't had a chance to work out why. Trying to rebuild Motion to debug further was how I screwed up ffmpeg on my Pi :(

Any chance you could run it via gdb to see where it is blowing up please? ("gdb motion", "r<return>", and then probably "c<return>" a couple of times until it hits the seg fault). Whilst we'll do our best supporting this, it is still a spare-time project, so the more info you can feed us the better.

Second time through appears to be selecting MJPEG first, and then YU12 - that's a bit strange if you are sure you've set your config correctly to request YU12. I know for certain that Motion with YU12 was working, and the code to support that hasn't changed recently.
The driver isn't as polished as it could be, and if we get things too wrong then it can get the GPU into a weird state that the error handling code can't recover from. Can you try YU12 from a clean boot? It's possible that the selection of MJPEG and got us into a weird state. Thanks.

BTW Motion itself seems to have been updated since the version that is available via apt-get. YU12 is now format 17, not 8! The niggle is that you need to have all the relevant source files around for ffmpeg and the like to be able to rebuild it.
Yes, I will try to debug it, but can't do it today.

The YU12 still works fine. Motin just guves the different error after I first use the working YU12. It does not core dump for mjpeg but gives the timeout, so the fallback isnot working. It would be interesting to test with the new motion....
Thanks for your help on this.

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

Re: Official V4L2 driver

Tue Dec 24, 2013 2:42 pm

6by9 wrote:I don't know what omxplayer is using to determine the codec/container type
It's using ffmpeg. If you run "omxplayer -i" on a file it will print the details much like ffprobe.
I'm not sure how important file extension is, or if it always analyses header bytes to determine file format.

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

Re: Official V4L2 driver

Tue Dec 24, 2013 4:40 pm

6by9 wrote: Just try out the V4L2 capture to confirm that it is working first:

Code: Select all

v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=5
v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.mjpg
omxplayer somefile.mjpg
This presents the appearance of capturing MJPEG to a file, at least I get something:

Code: Select all

pi@rp2 ~ $ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=5
pi@rp2 ~ $ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.mjpg
<<<<<<<<<<<<<<<<<<<<<<<<<<< 25 fps
<<<<<<<<<<<<<<<<<<<<<<<<<< 25 fps
<<<<<<<<<<<<<<<<<<<<<<<<<< 25 fps
<<<<<<<<<<<<<<<<<<<<<
pi@rp2 ~ $ ls -al somefile.mjpg
-rw-r--r-- 1 pi pi 9959775 Dec 24 08:32 somefile.mjpg
but 'omxplayer somefile.mjpg' just immediately wishes me a good day without presenting anything on the screen. I also tried a lower resolution, 640x480 with exactly the same result. Do I have the latest version?

Code: Select all

omxplayer - Commandline multimedia player for the Raspberry Pi
        Build date: Mon, 16 Dec 2013 22:06:42 +0100
        Version   : b34143c [master]
        Repository: https://github.com/popcornmix/omxplayer.git
Imagemagick believes the output is a single 1920x1088 pixel, 10 MB JPEG image.

Code: Select all

pi@rp2 ~ $ identify -verbose somefile.mjpg
Image: somefile.mjpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Class: DirectClass
  Geometry: 1920x1088+0+0
  Resolution: 72x72
  Print size: 26.6667x15.1111
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 52.5326 (0.20601)
      standard deviation: 25.4187 (0.0996813)
      kurtosis: 1.94339
      skewness: 0.772891
    Green:
      min: 0 (0)
      max: 219 (0.858824)
      mean: 20.4532 (0.0802086)
      standard deviation: 19.2094 (0.075331)
      kurtosis: 10.2291
      skewness: 2.83908
    Blue:
      min: 0 (0)
      max: 180 (0.705882)
      mean: 10.6911 (0.0419259)
      standard deviation: 9.04591 (0.0354741)
      kurtosis: 12.4504
      skewness: 2.22513
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 27.8923 (0.109382)
      standard deviation: 19.1219 (0.0749879)
      kurtosis: 15.9185
      skewness: 3.77711
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Interlace: None
  Background color: white
  Border color: srgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Compose: Over
  Page geometry: 1920x1088+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 49
  Orientation: Undefined
  Properties:
    date:create: 2013-12-24T08:32:46-08:00
    date:modify: 2013-12-24T08:32:46-08:00
    jpeg:colorspace: 2
    jpeg:sampling-factor: 2x2,1x1,1x1
    signature: fe4abbac86594c7843a77dcc5fdba7f8fc5e7710d66306a7686731bfd2f05b9a
  Artifacts:
    filename: somefile.mjpg
    verbose: true
  Tainted: False
  Filesize: 9.96MB
  Number pixels: 2.089M
  Pixels per second: 2.374MB
  User time: 0.690u
  Elapsed time: 0:01.880
  Version: ImageMagick 6.7.7-10 2013-09-03 Q16 http://www.imagemagick.org
Last edited by jbeale on Tue Dec 24, 2013 5:52 pm, edited 1 time in total.

uski
Posts: 13
Joined: Sat Oct 27, 2012 12:41 pm

Re: Official V4L2 driver

Tue Dec 24, 2013 5:45 pm

Hi there,

Just a quick thank you to those working on the V4L2 driver and on MJPEG/JPEG support.
It's a feature I have been anticipating a lot and that has been really missing. Please keep working on it, it's much appreciated ! :)

Please don't focus only on video capturing to a file, it was the major issue with raspistill and raspivid.
Some people like to use motion detection tools which need direct access to the data, while others want to directly stream a compressed stream to the network.

Also, I've read a few posts about supporting different resolutions at once, it would be very interesting (like full HD H264 on /dev/video0 and 320x240 YUV or RGB preview on /dev/video1), but that's a lower priority of interest to me.

Or, better, /dev/video0 MJPEG/H264 and /dev/video1 RGB/YUV (same resolution - probably easier to implement).

Thanks ! :)
uski

uski
Posts: 13
Joined: Sat Oct 27, 2012 12:41 pm

Re: Official V4L2 driver

Tue Dec 24, 2013 6:49 pm

And by the way, here's a bug report :

# modprobe bcm2835-v4l2
$ sudo v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=5
VIDIOC_S_FMT: failed: Timer expired

$ dmesg
[ 37.887758] media: Linux media interface: v0.10
[ 37.906678] Linux video capture interface: v2.00
[ 37.976903] bcm2835-v4l2: V4L2 device registered as video0
[ 37.982208] bcm2835-v4l2: Broadcom 2835 MMAL video capture ver 0.0.2 loaded.
[ 40.180565] bcm2835_v4l2: port_parameter_get:result:0 component:0x40 port:2 parameter:13
[ 47.979565] bcm2835_v4l2: error 0 waiting for sync completion
[ 47.979605] bcm2835-v4l2: vidioc_s_fmt_vid_cap: failed to setup mmal components: -62

And from here, all commands return the VIDIOC_S_FMT error.

$ sudo rmmod bcm2835-v4l2
[ 213.319706] bcm2835-v4l2: unregistering video0
[ 214.329567] bcm2835_v4l2: error 0 waiting for sync completion
[ 215.329570] bcm2835_v4l2: error 0 waiting for sync completion
[ 216.329567] bcm2835_v4l2: error 0 waiting for sync completion
[ 217.329572] bcm2835_v4l2: error 0 waiting for sync completion

$ raspistill -w 1920 -h 1080
^Cmmal: Aborting program
(I hit CTRL+C because it was stuck, and the camera red led didn't light up)

$ sudo reboot

After the reboot :

$ raspistill -w 1920 -h 1080
...and I get a picture !

So it looks like the V4L2 driver has an issue and it locks up the core.
I did a rpi-update right before doing the tests above.

Any clue ?

Thanks !
uski

olifre
Posts: 3
Joined: Mon Dec 23, 2013 11:49 pm

Re: Official V4L2 driver

Tue Dec 24, 2013 9:59 pm

6by9 wrote:If you fancied trying it yourself (I haven't got my setup running at the moment), then /drivers/media/platform/bcm2835/bcm2835-camera.c function vidioc_enum_fmt_vid_cap is the one you're after. Let us know the results, or I may have a play if I have the time over the break.
Because I am neither an expert of V4L2 nor have any real kernel experience (nor any toolchain for the raspberry floating around) I'd rather wait and support some more userspace open source projects, but thanks a lot for your quick reply!
If this works, it would allow streaming of compressed MJPEG data / H264 data with avserver over the network without any further special touching of the data, which would probably be helpful to many users.

So I am crossing my fingers and wish you good luck (and some nice days off also, of course!).

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

Re: Official V4L2 driver

Thu Dec 26, 2013 6:50 pm

uski wrote:Just a quick thank you to those working on the V4L2 driver and on MJPEG/JPEG support.
It's a feature I have been anticipating a lot and that has been really missing. Please keep working on it, it's much appreciated ! :)

Please don't focus only on video capturing to a file, it was the major issue with raspistill and raspivid.
Some people like to use motion detection tools which need direct access to the data, while others want to directly stream a compressed stream to the network.

Also, I've read a few posts about supporting different resolutions at once, it would be very interesting (like full HD H264 on /dev/video0 and 320x240 YUV or RGB preview on /dev/video1), but that's a lower priority of interest to me.

Or, better, /dev/video0 MJPEG/H264 and /dev/video1 RGB/YUV (same resolution - probably easier to implement).

Thanks ! :)
uski
Sorry, what do you mean by a major issue with raspistill /vid?

There are limitations when having multiple channels of information being output - you start to exceed the bandwidth of the GPU->ARM, esp. with YUV or MJPEG which require quite a high bandwidth compared with H264. There nothing stopping you doing this already though - a modification of raspivid for example - some people have already been doing this.
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."

kyrill
Posts: 2
Joined: Thu Dec 26, 2013 6:55 pm

Re: Official V4L2 driver

Thu Dec 26, 2013 6:57 pm

I downloaded the new NOOBS v1.3.3 image, checked the SHA1 checksum, installed Raspbian and started with “sudo modprobe bcm2835-v4l2″. But everything I get is “operation not permitted”. Even “modprobe … -vvv doesn’t” give me some hints… I'm not sure if it is a problem of bcm2835-v4l2 or the new image. Any ideas?

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

Re: Official V4L2 driver

Fri Dec 27, 2013 11:47 am

kyrill wrote:I downloaded the new NOOBS v1.3.3 image, checked the SHA1 checksum, installed Raspbian and started with “sudo modprobe bcm2835-v4l2″. But everything I get is “operation not permitted”. Even “modprobe … -vvv doesn’t” give me some hints… I'm not sure if it is a problem of bcm2835-v4l2 or the new image. Any ideas?
Have you enabled the camera with "sudo raspi-config" as per the instructions on http://www.raspberrypi.org/camera? The V4L2 driver will no load if it can't find the camera on the GPU, and that requires it to be connected and the correct firmware selected.
Do raspistill or raspivid work? Or the output from dmesg wouold be of some use.
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.

kyrill
Posts: 2
Joined: Thu Dec 26, 2013 6:55 pm

Re: Official V4L2 driver

Fri Dec 27, 2013 4:38 pm

Have you enabled the camera with "sudo raspi-config" as per the instructions on http://www.raspberrypi.org/camera? The V4L2 driver will no load if it can't find the camera on the GPU, and that requires it to be connected and the correct firmware selected.
Do raspistill or raspivid work? Or the output from dmesg wouold be of some use.
The camera was enabled with raspi-config. But you pointed me in the right direction... raspivid throws ENOMEM. Actually it turned out that the micro-connector from the camera module to the camera board PCB has been loose. Now everything is working as expected. Maybe the module in future should also show such an error message.

Thank you!

uski
Posts: 13
Joined: Sat Oct 27, 2012 12:41 pm

Re: Official V4L2 driver

Sat Dec 28, 2013 4:10 pm

Hi james !
jamesh wrote:Sorry, what do you mean by a major issue with raspistill /vid?
First, no offence, raspi[still|vid] are useful for their purpose : capture to a file.
But the limitation (what I call the "issue") is that you can't use them with standard Linux tools that use V4L(2) as an interface.

So the issue is that the Raspberry Pi _was_ very limited in what you could do with standard tools (motion, mjpg_streamer, ...), because the "camera driver" was actually a proprietary userland interface. But now, that's sorted out with the V4L2 driver, and I'm very grateful for that.
jamesh wrote:There are limitations when having multiple channels of information being output - you start to exceed the bandwidth of the GPU->ARM, esp. with YUV or MJPEG which require quite a high bandwidth compared with H264. There nothing stopping you doing this already though - a modification of raspivid for example - some people have already been doing this.
Yup.

By the way, can you reproduce the bug I have reported ?

For now I'm mostly interested in streaming MJPEG data straight from the GPU to the network with mjpg_streamer, and getting YUV or RGB data to motion for motion detection and alarm reporting (not simultaneously - these are two different uses).
I believe the V4L2 driver allows for this, but I am stuck with the bug I reported for now.

uski

Return to “Camera board”