# Raspberry Pi B+ / webcamd / ffmpeg problem



## DeadLoco (Dec 13, 2014)

I have a Raspberry Pi B+ with FreeBSD 10.1-R on it. I have installed cuse4bsd-kmod / libv4l / v4l_compat / v4l2-ctl / webcamd / ffmpeg.

Now I can attach my Vimicro Venus USB2 webcam and have /dev/video0 appeared.

Also I can talk to camera:

```
> v4l2-ctl --all
Driver Info (not using libv4l2):
  Driver name  : uvcvideo
  Card type  : Venus USB2.0 Camera
  Bus info  : usb-/dev/usb-/dev/usb
  Driver version: 2.6.38
  Capabilities  : 0x84000001
  Video Capture
  Streaming
Format Video Capture:
  Width/Height  : 640/480
  Pixel Format  : 'YUYV'
  Field  : None
  Bytes per Line: 1280
  Size Image  : 614400
  Colorspace  : Unknown (00000000)
Crop Capability Video Capture:
  Bounds  : Left 0, Top 0, Width 640, Height 480
  Default  : Left 0, Top 0, Width 640, Height 480
  Pixel Aspect: 1/1
Video input : 0 (Camera 1: ok)
Streaming Parameters Video Capture:
  Capabilities  : timeperframe
  Frames per second: 30.000 (30/1)
  Read buffers  : 0
Priority: 2
```
ffmpeg can see it too:

```
> ffmpeg -f v4l2 -list_formats all -i /dev/video0
ffmpeg version 2.3.5 Copyright (c) 2000-2014 the FFmpeg developers
built on Dec 13 2014 12:57:49 with FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
configuration: --disable-libaacplus --disable-indev=alsa --disable-outdev=alsa
--disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libass
--disable-libcdio --disable-libcelt --enable-libfaac --disable-libfdk-aac
--enable-ffserver --disable-fontconfig --disable-libfreetype --disable-frei0r
--disable-gnutls --disable-libgsm --disable-iconv --disable-indev=jack
--enable-libmp3lame --disable-libbluray --enable-libv4l2 --disable-libmodplug
--disable-openal --disable-indev=openal --disable-libopencv --disable-libopenjpeg
--disable-openssl --disable-libopus --disable-libpulse --disable-indev=pulse
--disable-outdev=pulse --disable-librtmp --disable-libschroedinger
--disable-libspeex --disable-libtheora --disable-vaapi --disable-vdpau
--disable-libvorbis --disable-libvo-aacenc --disable-libvo-amrwbenc --disable-libvpx
--enable-libx264 --disable-libx265 --enable-libxvid --prefix=/usr/local
--mandir=/usr/local/man --datadir=/usr/local/share/ffmpeg --enable-shared
--enable-gpl --enable-postproc --enable-avfilter --enable-avresample
--enable-pthreads --enable-memalign-hack --disable-libstagefright-h264
--disable-libutvideo --disable-libsoxr --cc=cc --extra-cflags=' -I/usr/local/include'
--extra-ldflags='-L/usr/local/lib ' --extra-libs=-pthread --disable-debug
--disable-sse --disable-mmx --disable-ffplay --disable-outdev=sdl --enable-nonfree
  libavutil  52. 92.100 / 52. 92.100
  libavcodec  55. 69.100 / 55. 69.100
  libavformat  55. 48.100 / 55. 48.100
  libavdevice  55. 13.102 / 55. 13.102
  libavfilter  4. 11.100 /  4. 11.100
  libavresample  1.  3.  0 /  1.  3.  0
  libswscale  2.  6.100 /  2.  6.100
  libswresample  0. 19.100 /  0. 19.100
  libpostproc  52.  3.100 / 52.  3.100
[video4linux2,v4l2 @ 0x21c2c410] Raw  :  yuyv422 :  YUV 4:2:2 (YUYV) : 640x480 320x240 176x144 160x120 800x600 1280x960 1280x1024 1600x1200
/dev/video0: Immediate exit requested
```
But when I want to capture video I get the error:

```
> ffmpeg -f v4l2 -framerate 30 -video_size 640x480 -i /dev/video0 output.mkv
. . . . .
[video4linux2,v4l2 @ 0x21c32410] ioctl(VIDIOC_STREAMON): Device not configured
/dev/video0: Device not configured
```

I'm sure I've missed something but I've never dealt with webcams/media on FreeBSD before.


----------



## acheron (Dec 15, 2014)

This is a bit off topic but how do you manage to get ffmpeg built with x264, I have lots of errors because of missing *_neon symbols inside libx264.


----------



## DeadLoco (Dec 15, 2014)

acheron said:


> This is a bit off topic but how do you manage to get ffmpeg built with x264, I have lots of errors because of missing *_neon symbols inside libx264.


I've got the same headache till realize that all troubles are because of "extra compiler optimizations" aka OPTIMIZED_CFLAGS. Just unset that option in the port configuration.


----------



## acheron (Dec 15, 2014)

Ok, this is what I've done, just wanted to be sure I didn't miss something. Thanks!


----------



## acheron (Dec 16, 2014)

I've tried on current and I have an other error: 
	
	



```
[mjpeg @ 0x22c74810] ignoring invalid SAR: 0/0
[mjpeg @ 0x22c74810] overread 8
[mjpeg @ 0x22c74810] No JPEG data found in image
Error while decoding stream #0:0: Invalid data found when processing input
```
There are only artefacts in output.mkv.
I've tried multimedia/pwcview and it works but the image is ugly, surely because I have an USB key + a webcam + ethernet plugged into the RPI.


----------



## DeadLoco (Dec 16, 2014)

Now I'll try to get an image on the virtual machine instead of RPi. Seems like problem is in the kernel/soft configuration, not RPi itself.


----------



## acheron (Dec 16, 2014)

DeadLoco said:


> I've got the same headache till realize that all troubles are because of "extra compiler optimizations" aka OPTIMIZED_CFLAGS. Just unset that option in the port configuration.


I've submitted a PR for this problem: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=196033


----------



## hselasky@ (Dec 19, 2014)

Hi,

The USB host controller driver on the RPI, does currently in software not support isochronous packets above 512 bytes.

For reliable webcam reception ensure:

1) webcam is high-speed (USB 2.0)
2) wMaxPacketSize (See lsusb -vvv) of the desired isochronous setting is not above 0x200

Try setting lower resolution for example.

`usbdump` and `usbconfig` and `lsusb` might give you more clues about what is going on!

--HPS


----------



## DeadLoco (Dec 21, 2014)

Now I've reinstall 10.1-stable.
I'm not familiar with USB internals so I'll just dump this here:


```
FreeBSD rpi.lan 10.1-STABLE FreeBSD 10.1-STABLE #0 r275566
```


```
> usbconfig -d 0.5 dump_all_config_desc
ugen0.5: <Venus USB2.0 Camera Vimicro Corp.> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (128mA)
. . . . .
  Interface 1 Alt 1
  bLength = 0x0009
  bDescriptorType = 0x0004
  bInterfaceNumber = 0x0001
  bAlternateSetting = 0x0001
  bNumEndpoints = 0x0001
  bInterfaceClass = 0x000e  <Video device>
  bInterfaceSubClass = 0x0002
  bInterfaceProtocol = 0x0000
  iInterface = 0x0000  <no string>

  Endpoint 0
  bLength = 0x0007
  bDescriptorType = 0x0005
  bEndpointAddress = 0x0082  <IN>
  bmAttributes = 0x0005  <ASYNC-ISOCHRONOUS>
  wMaxPacketSize = 0x0080
  bInterval = 0x0001
  bRefresh = 0x0000
  bSynchAddress = 0x0000

  Interface 1 Alt 2
. . . . .
```
Here I see Interface 1 Alt 1-7 described as <Video device> <ASYNC-ISOCHRONOUS> 
with 
wMaxPacketSize = 0x0080, 0x0200, 0x0400, 0x0b00, 0x0c00, 0x1380, 0x1400

As far as I understand that is different resolutions/bitrates/packetsizes supported by camera in range 176x144 - 1600x1200. 
Look like camera have 640x480 (0x0b00) by default, but how can I change this setting?


----------



## hselasky@ (Dec 21, 2014)

Hi,

Can you install:

sysutils/usbutils

When running `lsusb -vvv` you should see the resolution listed next to wMaxPacketSize = 0x0200

When using `pwcview` there is an -s option to change the resolution.

--HPS


----------

