Author Topic: Usb web camera fails to capture images using Motion_Wrapper [SOLVED]  (Read 6971 times)

Avner

  • Veteran
  • ***
  • Posts: 76
    • View Profile
I have a camera connected through usb to my core. I followed the instructions in http://wiki.linuxmce.org/index.php/USB_Surveillance_Camera to install the usb camera.

The camera is operating in the OS. I can see the video using e.g. cheese, and invoke motion from the command line. When I invoke motion from the command line
Code: [Select]
sh-3.2# LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so motionthe images are stored to the directory /home/cameras/53 and the file /home/cameras/53/lastsnap.jpg is updated regularly.
I can then view the images correctly using the LinuxMCE web admin via: Security -> View cameras -> preview checked cameras

However, if I don't invoke motion manually from the command line I don't see any images.
The log file /var/log/pluto/52_Motion_Wrapper.log shows the following error messages:
Code: [Select]
sh-3.2# tail -f /var/log/pluto/52_Motion_Wrapper.log
...
========== NEW LOG SECTION ==========
1       06/13/13 10:06:16       52 (spawning-device)    Starting... 2
1       06/13/13 10:06:16       52 (spawning-device)    Found /usr/pluto/bin/Motion_Wrapper
05      06/13/13 10:06:16.941           Creating child 53 <0xb71ef6c0>
05      06/13/13 10:06:16.941           Note: Device manager has attached a device of type 66 that this has no custom event handler for.  It will not fire events. <0xb71ef6c0>
05      06/13/13 10:06:16.941           Note: Device manager has attached a device of type 66 that this has no custom handler for.  This is normal for IR. <0xb71ef6c0>
05      06/13/13 10:22:12.864           Could not take snapshot, fail sending SIGALRM signal... <0xb59ebb90>
05      06/13/13 10:22:18.072           Could not take snapshot, fail sending SIGALRM signal... <0xb59ebb90>
05      06/13/13 10:36:44.637           Could not take snapshot, fail sending SIGALRM signal... <0xb59ebb90>
...

For each error message: Could not take snapshot, fail sending SIGALRM signal... there is an error message in /var/log/pluto/DCERouter.log
Code: [Select]
h-3.2# tail -f /var/log/pluto/DCERouter.log
...
08      06/13/13 12:56:03.707           Received Message from 0 (unknown / ) to 53 (webcam2 / Entertainment Room1), type 1 id 84 Command:Get Video Frame, retry none, parameters: <0x7d2adb90>
08      06/13/13 12:56:03.707             Parameter 19(Data): 0 <0x7d2adb90>
08      06/13/13 12:56:03.707             Parameter 20(Format): jpg <0x7d2adb90>
08      06/13/13 12:56:03.707             Parameter 23(Disable Aspect Lock): 0 <0x7d2adb90>
08      06/13/13 12:56:03.707             Parameter 31(): 0 <0x7d2adb90>
08      06/13/13 12:56:03.707             Parameter 60(Width): 100 <0x7d2adb90>
08      06/13/13 12:56:03.707             Parameter 61(Height): 100 <0x7d2adb90>
05      06/13/13 12:56:03.868           Socket::ReceiveData 0x88329b8 failed, bytes left 0 start: 3460000 1: 0 1b: 0 2: 0 2b: 0 m_Socket: 135 Incoming_Conn Socket 135 127.0.0.1 <0x7d2adb90>
05      06/13/13 12:56:03.869           Socket::ReceiveString2 ReceiveData failed m_Socket: -1 Incoming_Conn Socket 135 127.0.0.1 <0x7d2adb90>
05      06/13/13 12:56:03.869           TCPIP: Closing connection to -1003 (Router Dev #0) 0x88329b8 m_Socket: -1 <0x7d2adb90>
05      06/13/13 12:56:03.869           Router::RemoveAndDeleteSocket 0x88329b8 -1003 <0x7d2adb90>
The attributes of the process Motion_Wrapper are:
Code: [Select]
sh-3.2# ps aux | grep -i motion
root     19268  0.1  0.0   3000   992 ?        Ss   00:16   1:04 /usr/bin/SCREEN -d -m -S Motion_Wrapper52 /usr/pluto/bin/Spawn_Device.sh 52 localhost Motion_Wrapper
root     19269  0.0  0.0   2872  1452 pts/16   Ss+  00:16   0:00 /bin/bash /usr/pluto/bin/Spawn_Device.sh 52 localhost Motion_Wrapper

I changed the values in /etc/motion/motion.conf via LinuxMCE web admin via Advanced -> Configuration -> Devices. In the Motion Device (Logitec webcam) in Device Data -> Motion Parameters and restarted the core.
Code: [Select]
sh-3.2# cat /etc/motion/motion.conf
...
minimum_motion_frames 2
snapshot_interval 2

This did not help. I suspect that the problem is in file permissions or in using a wrong device number

Permissions on the directory /home/cameras/53 are:
Code: [Select]
drwxr-xr-x 3 root root 4096 Jun 12 23:27 /home/cameras/53/
The device tree looks like this:
Code: [Select]
CORE
  (
   Device #1: CORE
   Using Device Template: Generic PC as Core #7
  )

  Logitec webcam
    (
     Device #52: Logitech webcam
     Using Device Template: Motion Wrapper #64
    )

    webcam2
      (
       Device #53: webcam2
       Using Device Template: Generic Analog Camera #66
      )


I am running that latest update of 8.10
Code: [Select]
sh-3.2# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 8.10
Release:        8.10
Codename:       intrepid

sh-3.2# uname -a
Linux dcerouter 2.6.27-17-generic #1 SMP Fri Mar 12 03:09:00 UTC 2010 i686 GNU/Linux

Thanks in advance for any help
Avner
« Last Edit: June 16, 2013, 12:57:27 am by Avner »
Asus P5GD2-X, Intel i915P/G, Pentium 4 3.2 GHz, 2.5GB, nvidia Geforce 8800, Hauppauge WinTV-HVR-1850

Avner

  • Veteran
  • ***
  • Posts: 76
    • View Profile
Re: Usb web camera fails to capture images using Motion_Wrapper
« Reply #1 on: June 16, 2013, 12:56:49 am »
I solved the problem by making 2 changes to the file: /etc/init.d/motion
1. Add the path to the dynamic library v4l1compat.so
2. Change the uid of the process from: motion to root

In /etc/init.d/motion I changed the following line from:
Code: [Select]
start-stop-daemon --start --exec $DAEMON -b --chuid motion || trueto:
Code: [Select]
LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so start-stop-daemon --start --exec $DAEMON -b --chuid root || true
After making the change, Motion_Wrapper automatically creates images without having to manually invoke the service motion. The following gets updated automatically as expected:
  • The last snapshot file in /home/cameras/53/lastsnap.jpg
  • The displayed image in LinuxMCE web admin: Security -> View cameras -> preview checked cameras
  • The displayed image via Orbiter (when selecting the camera)

I am not sure if this workaround is has side effects.
What are the consequences of running the service motion with uid root (instead of uid motion)?
« Last Edit: June 16, 2013, 01:03:29 am by Avner »
Asus P5GD2-X, Intel i915P/G, Pentium 4 3.2 GHz, 2.5GB, nvidia Geforce 8800, Hauppauge WinTV-HVR-1850

WhiteHatHacker

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Usb web camera fails to capture images using Motion_Wrapper [SOLVED]
« Reply #2 on: June 23, 2013, 10:48:39 pm »
I had the same problem and I went to try your solution, but the only place I could find that start-stop-daemon line is in an "if" statement. Is that where you implemented it?

Avner

  • Veteran
  • ***
  • Posts: 76
    • View Profile
Re: Usb web camera fails to capture images using Motion_Wrapper [SOLVED]
« Reply #3 on: June 25, 2013, 09:06:33 am »
WhiteHatHacker,
In lmce-08 (Intrepid) there is a single line with start-stop-daemon as stated above.

In lmce-1004, I changed the following line from:
Code: [Select]
if start-stop-daemon --start --oknodo --exec $DAEMON -b --chuid motion ; thento:
Code: [Select]
if LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so start-stop-daemon --start --oknodo --exec $DAEMON -b --chuid root ; then
Hope this helps
Avner
Asus P5GD2-X, Intel i915P/G, Pentium 4 3.2 GHz, 2.5GB, nvidia Geforce 8800, Hauppauge WinTV-HVR-1850

WhiteHatHacker

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Usb web camera fails to capture images using Motion_Wrapper [SOLVED]
« Reply #4 on: June 25, 2013, 06:55:11 pm »
I will try when I get home. Thank you for the reply.

WhiteHatHacker

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Usb web camera fails to capture images using Motion_Wrapper [SOLVED]
« Reply #5 on: June 26, 2013, 01:56:30 am »
Nothing for me yet, still says Unable to open video device

Avner

  • Veteran
  • ***
  • Posts: 76
    • View Profile
Re: Usb web camera fails to capture images using Motion_Wrapper [SOLVED]
« Reply #6 on: June 26, 2013, 08:14:44 am »
I suggest that you first verify that you can see the video with other means, e.g. via cheese
Asus P5GD2-X, Intel i915P/G, Pentium 4 3.2 GHz, 2.5GB, nvidia Geforce 8800, Hauppauge WinTV-HVR-1850

WhiteHatHacker

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Usb web camera fails to capture images using Motion_Wrapper [SOLVED]
« Reply #7 on: June 26, 2013, 08:26:16 pm »
I got it somewhat working with Kamoso. Very small image though. Still no luck through motion though.
« Last Edit: June 26, 2013, 09:05:17 pm by WhiteHatHacker »