USB Cams and Motion on Debian


79 posts   Page 1 of 4   1, 2, 3, 4
by SteveDee » Sun Jun 10, 2012 6:18 pm
The end-game is to get RPi to work on Debian with Kenneth Larvsen's motion app, either using a USB camera or analogue camera + EzCap.

But for the moment I'm just trying to get my 2 USB cams working.

Initially there was no support, but I've now upgraded as discussed in this post:-
viewtopic.php?f=38&t=6942

With my old Creative Technologies cam:-
lsusb shows driver=usbhid

Running Cheese gives an unstable image, where horizontal breaks appear towards the lower part of the image, and this unstable section is a random part of the main image. Cheese also drives cpu to 100%, so is probably useless on RPi.

Running v4l2ucp with mplayer selected:-
tv:// -tv device=/dev/video0:driver=v4l2
...still produces this instability, but %cpu is nice & low.

When running "motion" I get errors including:-
VIDIOC_REQBUFS: device or resource busy.


The 2nd USB cam (Sonix Technology "Advent") lsusb shows: driver=uvcvideo.
I can't get any video out of this.

Both the usbhid & uvcvideo drivers were included in the upgrade.

So what am I looking for?
I don't have a clear idea how the various drivers fit into the video system (e.g. usbhid, z3cxx, v4l2 & so on). So it would be great if someone could explain.

If other RPi users have been able to get USB cams working with usbhid and uvcvideo drivers I may have to accept that there are compatibility issues with these drivers and my cams.

Any comments welcome.
User avatar
Posts: 147
Joined: Thu Dec 29, 2011 2:18 pm
by PaulBuxton » Mon Jun 11, 2012 11:05 am
Hi,

Firstly I have to mention I haven't gotten my webcams working yet either, although I was trying to build my own kernel with the required drivers in (the update that included the drivers hadn't happened when I started looking at this).

The top level component is the V4L2 layer, this provides a standard api through which your v4l2 drivers communicate with your applications. The uvcvideo driver is the basic usb video class v4l2 driver which most web-cams will use.

GUVCView is worth installing as a simple no-frills webcam interfacing program that might help you see some different output.

The image breakup you talk about makes me wonder about memory bandwidth maybe? Can you try reducing the resolution/framerate you are capturing at?

Have you tried using the vivi sample video capture driver?
To install it run
sudo modprobe vivi
This will then create a fake video capture device that will display a scrolling color bars, which should help eliminate any hardware related issues.

Hope this helps. I may play around with my webcams some more when I get home now that there has been an update to the debian image for them.

Hope this helps,
Paul.
Posts: 57
Joined: Tue Jan 10, 2012 11:38 am
by roytanck » Mon Jun 11, 2012 2:46 pm
I've set up Motion on the default Arch Linux image (my first experience with Arch, and so far it's been excellent). My UVC-compatible Microsoft webcam streams around 5 fps of 800*448 pixel video (MJPEG).

Couldn't get it to work on Debian at all, despite UVC apparently being universally supported on just about every Linux distro.
Posts: 4
Joined: Thu Oct 06, 2011 11:28 am
by ScoobyDoo » Mon Jun 11, 2012 3:50 pm
Motion is working great on Raspbian, a nice speed boast as motion uses hardfp.
Im using mine with a network CCTV camera though, all the recorded images are high quality.

I did see another user was having problems with corrupt images on a usb camera, he was using debian but when switched to raspbian the corruptions were less frequent.

I dont think the standard debian package for motion runs quick enough for usb cameras and this is why corruption is taking place.
User avatar
Posts: 71
Joined: Wed Apr 04, 2012 2:52 pm
Location: Staffordshire, UK
by cowpat » Mon Jun 11, 2012 5:37 pm
As Scoobydoo states I've enjoyed more success with raspbian.
I have been using the hexxeh rc3 image.

Here was my thread, with images of the horizontal break up I saw;
viewtopic.php?f=30&t=6973&p=90224#p90224

obviously when you use the webcam in motion, this break up will give you +10k changed pixels!

I'm using a logitech 270 now, which isn't an exciting camera, but I have found it more stable... Still only working up to 352x288 without issues though.

I think adding a swapfile helped, but I have since disabled it in the interests of SD card longevity. I'll be trying raspbian on a usb drive at some point, and will reinstate a swap partition then - but it's not something i really want for my application, as i'm running on batteries.

I'm going to give a class 10 SD card a shot first.
User avatar
Posts: 90
Joined: Sat Apr 14, 2012 12:13 pm
Location: London
by cowpat » Mon Jun 11, 2012 9:47 pm
BTW - did you try the ezcap usb capture? I didn't have any luck with mine yet. (debian or raspbian - don't remember if i tried arch.) It was only a brief test - time is my enemy.
User avatar
Posts: 90
Joined: Sat Apr 14, 2012 12:13 pm
Location: London
by macpod » Tue Jun 12, 2012 11:50 pm
I just got an ezcap yesterday and hooked it up to a rpi. I was running debian sqeeze with a re-compiled kernel with the ezcap module enabled.

Unfortunately I can only get a green screen thus far.

This is how I start it:
mplayer tv:// -tv driver=v4l2:width=720:height=480:outfmt=uyvy:norm=NTSC_M:device=/dev/video1:input=1:fps=30:noaudio -vo sdl

Note:
For the rpi or any linux computer, you may find the video will work perfectly for a few seconds then just stop and show grey bars. Supposedly this is caused by the front end loosing sync.

You can get around this by loading the module with 'bars=0'
Posts: 2
Joined: Tue Jun 12, 2012 11:45 pm
Location: USA
by cowpat » Wed Jun 13, 2012 8:01 am
Can I ask a stupid question?

I'm looking for the em28xx module to enable it - but I can't find it!? I'm in;

Kernel configuration
Device Drivers ---> Multimedia Support ---> Video capture adapters

is that the right place?
User avatar
Posts: 90
Joined: Sat Apr 14, 2012 12:13 pm
Location: London
by SteveDee » Wed Jun 13, 2012 11:39 am
Thanks for your responses. My #1 enemy at the moment is "time", or the lack of it! So I'm not going to get much time to follow this up before the weekend.

Paul, yeah my view is that you only need one driver per camera (to do the low level stuff) with an API to access properties and execute methods. What's confusing me is driver z3cxx which is mentioned on the v4l2ucp interface.

I have GUVCView installed as well, and this gives a similar instability. I'm not sure how you change the frame rate in GUVCView but reducing the resolution from 352x288 to 176x144 doesn't yield any improvement.

I tried vivi but got some error saying it wasn't installed, so will look at this again when time permits.

roytanck, I really no nothing about Arch, but I think its a no-gui distro so is probably an excellent choice for a non-gui app like motion. I'll give it a try.

ScoobyDoo & cowpat, I did look at the Raspbian FAQ a while back and thought it too early in the dev phase to bother with. Cowpat's screen-shots show the same kind of instability that I get, so not sure if you finally resolved this. But may give this distro a try anyway...Hmmm, gonna need more SD cards.

EzCap: I've been using an EzCap (eb1a:2861 eMPIA Technology, Inc) on 'Buntu for some time, but I know the em28xx modules are not included in the current Debian image (I see macpod has used a specially compiled image for this reason). There are several versions of EasyCap/EzCap devices, and many are fake goods.

On my Lubuntu 10.10 "BirdBox" server, if I want to capture video+sound I have to:-
sudo rmmod em28xx
sudo modprobe em28xx card=2
...then...
mencoder tv:// -tv device=/dev/video0:input=1:norm=PAL-60:width=720:height=576:alsa:amode=1:forcechan=2:audiorate=24000:adevice=plughw.1,0:forceaudio:immediatemode=0 -oac copy -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:turbo:vbitrate=1200:keyint=15 -o /home/some.avi

As there is no sound with motion, I don't do any of the above for regular monitoring, it just works.
User avatar
Posts: 147
Joined: Thu Dec 29, 2011 2:18 pm
by macpod » Wed Jun 13, 2012 12:24 pm
Ah, you two seem to have different ezcap modules:
http://easycap.blogspot.com/p/devices.html

I have the 05e1:0408 (use lsusb to identify yours) which uses the easycap staging kernel module (CONFIG_EASYCAP)

I'm stepping away from this for the moment to figure out a more serious usb issue. USB just doesn't work right. With two different webcams I have I can see a picture, but every frame is corrupted. I have tried with/without a powered hub (trying to acquire another "known good" hub for more experiments now).

I'll probe more over the week, but I don't expect this is a power issue. I'm more suspect of software, or hardware issues (an issue with my board, or the design). The behavior reminds me of a device with mismatched impedances (low speed devices are ok, full speed usuaully work, and high-speed seem to lockup everything even when just enumerating).
Posts: 2
Joined: Tue Jun 12, 2012 11:45 pm
Location: USA
by cowpat » Wed Jun 13, 2012 12:39 pm
I have ezcap working on a debian desktop machine (without having to do anything hard). I'm fairly sure it isn't a knock off... http://ezcap.tv/ it's em28xx anyway. I believe the dodgy ones are Syntek?

I'm beginning to agree with you SteveDee regarding Raspbian. It does work... but I don't think i have the experience to be that close to the 'bleeding edge' on development. I'm going to put that card (I already have a little pile of them) to one side for a short while and concentrate on the official debian. Although I will probably try the raspbian installer when I have a little HDD to play with.

As I see it, the hard float calculations should improve performance of motion (i think they do - but i haven't done any real tests) but the problem is lack of cpu effort... it's either ram, or (i speculate) maybe because the ethernet and the camera are both on the usb bus - and i'm viewing over a network?

Time's up - son is waking up...
User avatar
Posts: 90
Joined: Sat Apr 14, 2012 12:13 pm
Location: London
by SteveDee » Fri Jun 15, 2012 3:38 pm
Well, managed to burn a few hours today trying to make sense of Arch Linux.

First problem was getting the display to work, as the config.txt settings that work for Debian don't work for Arch (seems to need: hdmi_mode=4).

Then I tried to use pacman to update and install packages like motion, but ran into the conflict problem between systemd-tools & udev.

So going to return to Debian...
User avatar
Posts: 147
Joined: Thu Dec 29, 2011 2:18 pm
by cowpat » Fri Jun 15, 2012 6:43 pm
i removed the config settings and that came good.
There is a fix for the conflict... a bit of searchig will confirm this, but it's something along the lines of NOT upgrading pacman first.
User avatar
Posts: 90
Joined: Sat Apr 14, 2012 12:13 pm
Location: London
by SteveDee » Sat Jun 16, 2012 10:53 am
Help needed!

I abandoned Arch in favour of spending my time compiling my own kernel for my Debian RPi.

I'm trying to compile a new RPi kernel on my Lubuntu laptop which I then hope to install on RPi.

So on my laptop I've installed the tools required to compile an RPi kernel, and run this:-
git clone https://github.com/raspberrypi/linux.git

I've also created an em28driver directory and done this:-
git clone git://linuxtv.org/media_build.git
cd media_build
./build {and needed to install a couple of other packages as requested}

...and I now have a nice shiny new em28xx.ko which I hope will solve my EzCap problem.

So what I need to do now is compile the kernel on my laptop for RPi and to include this newly created em28xx.ko file.

I don't understand the example Make commands that I've looked at, so can anyone help/explain?
User avatar
Posts: 147
Joined: Thu Dec 29, 2011 2:18 pm
by cowpat » Sat Jun 16, 2012 12:44 pm
i haven't managed to get;
Code: Select all
git clone git://linuxtv.org/media_build.git
cd media_build
./build

I presume you built it in a cross compiler? I have yet to build this successfully on the pi itself yet.
I have the required packages.
I think i've got the headers in the right place.
I haven't got the error message to hand - but i didn't have much luck googling it.

I would like to try and get cx231xx and em28xx, would I be able to install your .ko files?
User avatar
Posts: 90
Joined: Sat Apr 14, 2012 12:13 pm
Location: London
by cowpat » Sat Jun 16, 2012 1:32 pm
too late to edit my last post, but here is where it seems to fall apart for me;

Code: Select all
make[2]: Entering directory `/lib/modules/3.1.9+/build'
  CC [M]  /home/pi/media_build/v4l/cpia2_v4l.o
In file included from <command-line>:0:0:
/home/pi/media_build/v4l/compat.h: In function 'i2c_smbus_read_word_swapped':
/home/pi/media_build/v4l/compat.h:44:2: error: implicit declaration of function 'i2c_smbus_read_word_data' [-Werror=implicit-function-declaration]
/home/pi/media_build/v4l/compat.h: In function 'i2c_smbus_write_word_swapped':
/home/pi/media_build/v4l/compat.h:53:2: error: implicit declaration of function 'i2c_smbus_write_word_data' [-Werror=implicit-function-declaration]
cc1: some warnings being treated as errors
User avatar
Posts: 90
Joined: Sat Apr 14, 2012 12:13 pm
Location: London
by SteveDee » Sat Jun 16, 2012 2:50 pm
OK, I'm an idiot (...and new to kernel compilation).

Wading through websites and docs it looks like I've just built em28xx.ko for my laptop, not for ARM.

Here is an example Make command from a another forum thread:-
make KSRC=/home/steve/RaspberryPi/linux/ ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k

I think I've worked out that this needs to be run in the directory containing the driver source (e.g. /home/steve/em28driver/media_build) rather than doing:-
cd media_build
./build
....from my previous post!

Not sure whether to delete my em28xxdriver directory & start again...
User avatar
Posts: 147
Joined: Thu Dec 29, 2011 2:18 pm
by cowpat » Sat Jun 16, 2012 8:26 pm
Well you are doubtless not alone, on both counts;

I have found a more meaningful error message, for want of scrolling up...

Code: Select all
 WARNING: Symbol version dump /lib/modules/3.1.9+/build/Module.symvers
           is missing; modules will have no dependencies and modversions.


Although it doesn't make it any clearer to me - but the internet says;


NOTE: "modules_prepare" will not build Module.symvers even if
CONFIG_MODVERSIONS is set; therefore, a full kernel build needs to be
executed to make module versioning work.


so i guess a have 6hrs to kill
User avatar
Posts: 90
Joined: Sat Apr 14, 2012 12:13 pm
Location: London
by SteveDee » Wed Jun 20, 2012 12:45 pm
Now switched from Squeeze to Wheezy, and my Advent Sonix USB cam now works great (no instability).

I can view and control motion remotely via Firefox, and with simple file sharing enabled I can remotely access my motion video, copy & delete files. Its all looking good!
User avatar
Posts: 147
Joined: Thu Dec 29, 2011 2:18 pm
by cowpat » Wed Jun 20, 2012 1:00 pm
That's good news - I've just written the new wheezy beta to SD card.

Regarding em28xx - I can see now that it was there in the https://github.com/raspberrypi/linux.git source all along! In 'make menuconfig' I couldn't see it initially, but requires I2C to be set to 'Y' before it's visible. However, before I could get too excited, i seem to have killed that SD image in all my mucking about... so I will try again.
User avatar
Posts: 90
Joined: Sat Apr 14, 2012 12:13 pm
Location: London
by cowpat » Thu Jun 21, 2012 1:30 pm
my kernel with it's new driver looks encouraging - lsusb below confirms different device.


Code: Select all
lsusb
Bus 001 Device 006: ID eb1a:2861 eMPIA Technology, Inc.

dmesg
[    8.953890] em28xx #0: chip ID is em2860
[    9.169704] em28xx #0: board has no eeprom
[    9.345597] em28xx #0: found i2c device @ 0x4a [saa7113h]
[    9.462853] em28xx #0: Your board has no unique USB ID.
[    9.494434] em28xx #0: A hint were successfully done, based on i2c devicelist hash.
[    9.609985] em28xx #0: This method is not 100% failproof.
[    9.617972] em28xx #0: If the board were missdetected, please email this log to:
[    9.940237] em28xx #0:    V4L Mailing List  <linux-media@vger.kernel.org>
[   10.108901] em28xx #0: Board detected as EM2860/SAA711X Reference Design
[   10.468909] em28xx #0: Identified as EM2860/SAA711X Reference Design (card=19)
[   10.580113] em28xx #0: Registering snapshot button...
[   10.588279] input: em28xx snapshot button as /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.3/input/input2
[   10.824968] em28xx #0: Config register raw data: 0x10
[   10.929124] em28xx #0: AC97 vendor ID = 0x83847652
[   10.989135] em28xx #0: AC97 features = 0x6a90
[   10.996094] em28xx #0: Sigmatel audio processor detected(stac 9752)
[   11.748736] em28xx #0: v4l2 driver version 0.1.3
[   13.290930] em28xx #0: V4L2 video device registered as video0
[   13.299452] em28xx #0: V4L2 VBI device registered as vbi0
[   13.307861] em28xx audio device (eb1a:2861): interface 1, class 1
[   13.330587] em28xx audio device (eb1a:2861): interface 2, class 1
[   13.358893] usbcore: registered new interface driver em28xx
[   13.366915] em28xx driver loaded


everything seems ok


Code: Select all
[0] Processing thread 0 - config file /etc/motion/motion.conf
[0] Motion 3.2.12 Started
[0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478784
[0] Thread 1 is from /etc/motion/motion.conf
[0] motion-httpd/3.2.12 running, accepting connections
[1] Thread 1 started
[0] motion-httpd: waiting for data on port TCP 8080
[1] cap.driver: "em28xx"
[1] cap.card: "EM2860/SAA711X Reference Design"
[1] cap.bus_info: "usb-bcm2708_usb-1.3.3"
[1] cap.capabilities=0x05020051
[1] - VIDEO_CAPTURE
[1] - VBI_CAPTURE
[1] - AUDIO
[1] - READWRITE
[1] - STREAMING
[1] Test palette BA81 (720x576)
[1] Using palette BA81 (720x576) bytesperlines 720 sizeimage 414720 colorspace 00000001
[1] mmap information:
[1] frames=4
[1] 0 length=414720
[1] 1 length=414720
[1] 2 length=414720
[1] 3 length=414720
[1] Using V4L2
[1] Resizing pre_capture buffer to 1 items


then it hangs for a bit, and comes back with a watchdog timeout

Code: Select all
[0] Thread 1 - Watchdog timeout, trying to do a graceful restart
[0] httpd - Finishing
[0] httpd Closing
[0] httpd thread exit


To be honest - given that it got this far, and /dev/video0 is there - i wonder if it's something i've done, or not done, in motion.conf
User avatar
Posts: 90
Joined: Sat Apr 14, 2012 12:13 pm
Location: London
by SteveDee » Thu Jun 21, 2012 6:17 pm
Here is a rough guide to motion.conf.

You should copy /etc/motion/motion.conf to /home/cowpat/.motion/motion.conf
...and make it read/write so you can edit it. Motion will find this file.

Video & picture files need to be saved somewhere convenient, so in motion.conf;
Set target_dir /home/cowpat/motion

Other motion.conf settings:-

v4l2_palette 8

For EzCap:-
input 1
...or for a USB cam:-
input 8

ffmpeg_video_codec msmpeg4

webcam_port 8081

webcam_localhost off

control_port 8080

control_localhost off

You won't be able to monitor video on RPi with Midori, you need Firefox which you can run remotely:-
{RPi IP Address}:8081

...and you can remotely change motion.conf settings via Firefox with:-
{RPi IP Address}:8080

I hope this helps.
User avatar
Posts: 147
Joined: Thu Dec 29, 2011 2:18 pm
by cowpat » Thu Jun 21, 2012 6:41 pm
Thanks Steve, but I've tried all that. I found it didn't like palette 8 - but it picked one it did like anyway. I am sure I have seen this before on the desktop machine, and think it may have been something like an unsupported resolution.. but I've looked at the .conf I used on the desktop machine and I've definitely seen it working with 720x576 (i think that's right - that's from memory)

Out of boredom, because I can't face trying yet another distro SD image, I've compiled ffmpeg from source and installed that... I'm now compiling media_build.git (which seems to be working now; a) i have enabled i2c too - b) some other reason).

What I haven't done yet, stupidly, is check this current installation is working for a webcam.

Can i just check with you - are you running the wheezy-beta image or the alpha from earlier?
Feel like I'm taking steps backwards at the moment....
User avatar
Posts: 90
Joined: Sat Apr 14, 2012 12:13 pm
Location: London
by cowpat » Thu Jun 21, 2012 8:45 pm
I've compiled ffmpeg and media_build.git from source... both installed ok... now I've reached macpod's green screen!
User avatar
Posts: 90
Joined: Sat Apr 14, 2012 12:13 pm
Location: London
by SteveDee » Fri Jun 22, 2012 9:38 am
cowpat wrote:Can i just check with you - are you running the wheezy-beta image or the alpha from earlier?
Feel like I'm taking steps backwards at the moment....


I'm using 2012-06-18-wheezy-beta.

The native resolution for PAL is 720x576, or 720x480 for NTSC (http://easycap.blogspot.co.uk/p/driver.html)

Yeah, checking motion with a known working (on RPi) USB webcam would be a good next step.
User avatar
Posts: 147
Joined: Thu Dec 29, 2011 2:18 pm