Rasberry Pi - Raspbian - Motion - USB Camera - Black Image

6.3k views Asked by At

I recently purchased a Rasperry Pi, VersionB, and am trying to get an old USB webcam to work with motion so that I may access the stream via http. I am using Raspbian with update/upgrades already completed.

I am fairly certain that the camera will work, as I had played with the motion.conf file for quite some time, as well as unplugged/re-plugged the usb camera several times, and at some point recorded a 2 second motion video, however, i am unsure what I did that made it work temporarily.

Also, I am able to access the control port 8089, as well as the stream at 8081 (in firefox), however the stream is a black background with a counter on the bottom right.

The control port lists that the camera is connected and that motion detection is active, however, the video stream on port 8081 is black.

Finally, when I manually capture a screenshot via control port (8089), the screenshot is a black image, as if the camera is covered.

That said, I decided to turn to the stack wizards.

For reference:

lsusb output pertaining to camera:

Bus 001 Device 005: ID 0c45:6288 Microdia PC Camera with Microphone (SN9C202 + OV9655)

-EDIT:

dmesg output received after plugging in USB camera:

[  269.597235] usb 1-1.2: new high-speed USB device number 5 using dwc_otg
[  269.700498] usb 1-1.2: New USB device found, idVendor=0c45, idProduct=6288
[  269.700530] usb 1-1.2: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[  269.700546] usb 1-1.2: Product: USB20 Camera
[  269.784573] media: Linux media interface: v0.10
[  269.810131] Linux video capture interface: v2.00
[  269.819113] gspca_main: v2.14.0 registered
[  269.826148] gspca_main: gspca_sn9c20x-2.14.0 probing 0c45:6288
[  271.897401] gspca_sn9c20x: OV9655 sensor detected
[  271.905922] input: gspca_sn9c20x as /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/input/input0
[  271.910445] usbcore: registered new interface driver gspca_sn9c20x
[  272.078022] 5:2:1: cannot get freq at ep 0x84
[  272.091857] usbcore: registered new interface driver snd-usb-audio
[  278.190887] gspca_sn9c20x: Set 640x480
[  279.187333] gspca_sn9c20x: Set 640x480
[  280.158810] gspca_main: ISOC data error: [23] len=0, status=-63

OUTPUT FROM sudo motion -n

[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] httpd bind(): Address already in use
[1] Thread 1 started
[0] httpd thread exit
[1] cap.driver: "gspca_sn9c20x"
[1] cap.card: "USB20 Camera    "
[1] cap.bus_info: "usb-bcm2708_usb-1.3"
[1] cap.capabilities=0x85000001
[1] - VIDEO_CAPTURE
[1] - READWRITE
[1] - STREAMING
[1] Test palette JPEG (640x480)
[1] Using palette JPEG (640x480) bytesperlines 640 sizeimage 154190 colorspace 00000007
[1] found control 0x00980900, "Brightness", range 0,255
[1]     "Brightness", default 127, current 127
[1] found control 0x00980901, "Contrast", range 0,255
[1]     "Contrast", default 127, current 127
[1] found control 0x00980902, "Saturation", range 0,255
[1]     "Saturation", default 127, current 127
[1] found control 0x00980903, "Hue", range -180,180
[1]     "Hue", default 0, current 0
[1] found control 0x0098090e, "Red Balance", range 0,127
[1]     "Red Balance", default 40, current 40
[1] found control 0x0098090f, "Blue Balance", range 0,127
[1]     "Blue Balance", default 40, current 40
[1] found control 0x00980910, "Gamma", range 0,255
[1]     "Gamma", default 16, current 16
[1] found control 0x00980911, "Exposure", range 0,6016
[1]     "Exposure", default 51, current 5864
[1] found control 0x00980912, "Gain, Automatic", range 0,1
[1]     "Gain, Automatic", default 1, current 1
[1] found control 0x00980913, "Gain", range 0,28
[1]     "Gain", default 0, current 0
[1] Error requesting buffers 4 for memory map. VIDIOC_REQBUFS: Device or resource busy
[1] ioctl (VIDIOCGCAP): Inappropriate ioctl for device
[1] Could not fetch initial image from camera
[1] Motion continues using width and height from config file(s)
[1] Resizing pre_capture buffer to 1 items
[1] bind(): Address already in use
[1] Problem enabling stream server in port 8088: Address already in use
[1] Thread exiting
[0] Motion thread 1 restart
[1] Thread 1 started
""""
""""
""""
""""

OUTPUT FROM lsmod

Module                  Size  Used by
snd_bcm2835            16165  0
snd_usb_audio         116191  0
snd_usbmidi_lib        18267  1 snd_usb_audio
snd_hwdep               5968  1 snd_usb_audio
snd_seq_midi            4682  0
snd_seq_midi_event      6551  1 snd_seq_midi
snd_rawmidi            21357  2 snd_usbmidi_lib,snd_seq_midi
snd_pcm                81593  2 snd_bcm2835,snd_usb_audio
snd_page_alloc          5156  1 snd_pcm
snd_seq                53769  2 snd_seq_midi_event,snd_seq_midi
snd_seq_device          6473  3 snd_seq,snd_rawmidi,snd_seq_midi
snd_timer              20133  2 snd_pcm,snd_seq
snd                    58895  9 snd_bcm2835,snd_usb_audio,snd_hwdep,snd_timer,snd_pcm,snd_seq,snd_rawmidi,snd_usbmidi_lib,snd_seq_device
evdev                   9325  1
arc4                    1683  2
rt2800usb              16720  0
rt2800lib              67499  1 rt2800usb
rt2x00usb              11492  1 rt2800usb
rt2x00lib              44180  3 rt2x00usb,rt2800lib,rt2800usb
gspca_sn9c20x          25601  1
gspca_main             23579  2 gspca_sn9c20x
mac80211              315610  3 rt2x00lib,rt2x00usb,rt2800lib
videodev              111230  3 gspca_sn9c20x,gspca_main
cfg80211              209273  2 mac80211,rt2x00lib
media                  13467  1 videodev
crc_ccitt               1529  1 rt2800lib
leds_gpio               2059  0
rfkill                 19138  2 cfg80211
led_class               3688  2 leds_gpio,rt2x00lib

If it matters, I have set motion to run as daemon.

Anything else I should check/change to get things working properly?

P.S. I am a linux/debian noob, obviously, so take it easy on me.

1

There are 1 answers

0
Kelton Temby On

Had exactly the same problem on a low end laptop. The total USB bandwidth available on pi is limited, and you'll already be using some for your network connection.

I would recommend you reduce the image resolution and framerate that motion is processing.

Now first i'm assuming you have installed the latest version of motion

sudo apt-get update
sudo apt-get install motion

Then we confirm the USB Camera has been recognized as a v4l2 device

lsusb
ls /dev/video*
v4l2-ctl --list-devices

Make sure you see the camera you expect in each of the outputs. Make a note of the camera name, I'll assume /dev/video0.

Now we'll edit the motion configuration

sudo nano /etc/motion/motion.conf

Under "Capture Device Options" heading you should have the camera that matches what you have. e.g. videodevice /dev/video0

Next make sure the framerate and resolution is nice and low. You can increase these later until motion breaks again, just start with what works.

width 320
height 240
framerate 2

For debugging, its best to turn on the live webcam server, and make it so you can view from your laptop. Just look through the /etc/motion/motion.conf file till you find the section.

webcam_motion on
webcam_localhost off

Now we need to enable the motion daemon by opening a different file.

sudo nano /etc/default/motion

Change the value to start_motion_daemon=yes

Now we can run motion!!

sudo service motion start

We're going to look at the feed from the camera in Firefox. First find the IP address of your pi using ifconfig, and look for wlan0 if you're wifi etc.

ifconfig

I'll assume the pi IP address is 192.168.1.123.

Now, from the laptop open firefox and in the address bar put 192.168.1.123:8081. You will see a preview of your motion feed!! If you don't, put the resolution even lower, and make sure your laptop has a good connection, and is on the same network as your pi.