Testing Webcams With fswebcam, Pi Noir Picam and Remote View of Motion on the Pi

This App may get you started with what webcams work with the Pi, and get on with using the PiCam, which gets seen as /dev/video0 if it is the only camera.

From prior research, it may be a good idea to load the PiCam v4l2 driver module at boot by setting:

bcm2835-v4l2

in /etc/modules:

After a reboot, you can check it has loaded with:

root@PiBlanc:~# lsmod | grep v4l
bcm2835_v4l2 37225 0
videobuf2_vmalloc 3009 1 bcm2835_v4l2
videobuf2_core 33578 1 bcm2835_v4l2
v4l2_common 5077 2 bcm2835_v4l2,videobuf2_core
videodev 122487 3 bcm2835_v4l2,v4l2_common,videobuf2_core

This makes the PiCam v4l2 compatible, so install the v4l-utils

apt-get install fswebcam v4l-utils

man fswebcam

SYNOPSIS

fswebcam [<options>] <filename> [[<options>] <filename> ... ]

DESCRIPTION

fswebcam is a small and simple webcam app for *nix. It can capture images

from a number of different sources and perform simple manipulation on the

captured image. The image can be saved as one or more PNG or JPEG files.

The PNG or JPEG image can be sent to stdio using the filename "-". The outâ

put filename is formatted by strftime.

Capture Options

-d, --device [<prefix>:]<device name>

Set the source or device to use. The source module is selected auto

matically unless specified in the prefix.

Default is /dev/video0.

Available source modules, in order of preference:

V4L2 - Capture images from a V4L2 compatible video device.

V4L1 - Capture images from a V4L1 compatible video device.

FILE - Capture an image from a JPEG or PNG image file.

RAW - Reads images straight from a device or file.

TEST - Draws colour bars.

If you access  the Pi remotely as I do via PuTTY, create a /Share in samba accessible to Windows/Mint, then you view any video test files you create in Win/Mint A/V Apps also.

Check the camera works as normal first with a quick video:

raspivid -o /Share/vidtest.h264

View it back in VLC remotely or locally with omxplayer:

omxplayer /Share/vidtest.h264

You can check the camera works with fswebcam by taking a TEST in the format above:

fswebcam -d TEST:/dev/video0 /Share/TEST.jpg

You get the colour bar .jpg picture in Windows photo viewer:

TEST.jpg

 

 

 

 

 

 

 

 

 

 

fswebcam -d v4l2:/dev/video0 /Share/test2.jpg

These frames can be replayed by avplay, and appears to just play the single frame continuously like a video, on the HDMI TV until you CtrlC:

root@raspberrypi:/home/stevee# fswebcam -d v4l2:/dev/video0 /Share/testfs2.jpg

--- Opening v4l2:/dev/video0...

/dev/video0 opened.

No input was specified, using the first.

--- Capturing frame...

Captured frame in 0.00 seconds.

--- Processing captured image...

Writing JPEG image to '/testfs2.jpg'.

root@raspberrypi:/home/stevee# avplay /Share/test2.jpg

avplay version 9.14-6:9.14-1rpi1rpi1, Copyright (c) 2003-2014 the Libav developers

built on Jul 22 2014 15:08:12 with gcc 4.6 (Debian 4.6.3-14+rpi1)

Input #0, image2, from '/testfs2.jpg':

Duration: 00:00:00.04, start: 0.000000, bitrate: N/A

Stream #0.0: Video: mjpeg, yuvj420p, 384x288 [PAR 1:1 DAR 4:3], 25 tbn

^C 6.69 A-V: 0.000 s:0.0 aq= 0KB vq= 0KB sq= 0B f=0/0 0/0

root@raspberrypi:/home/stevee# fswebcam -d TEST /TEST.jpg

--- Opening TEST...

--- Capturing frame...

Captured frame in 0.00 seconds.

--- Processing captured image...

Writing JPEG image to '/testfs.jpg'.

root@raspberrypi:/home/stevee# avplay /test.jpg

avplay version 9.14-6:9.14-1rpi1rpi1, Copyright (c) 2003-2014 the Libav developers

built on Jul 22 2014 15:08:12 with gcc 4.6 (Debian 4.6.3-14+rpi1)

Input #0, image2, from '/test.jpg':

Duration: 00:00:00.04, start: 0.000000, bitrate: N/A

Stream #0.0: Video: mjpeg, yuvj420p, 384x288 [PAR 1:1 DAR 4:3], 25 tbn

72.80 A-V: 0.000 s:0.0 aq= 0KB vq= 0KB sq= 0B f=0/0 0/0

You can use fswebcam to test different webcams for compatibility in linux for V4l1, v4l2 or raw formats:

root@raspberrypi:/home/stevee# fswebcam -d v4l1:/dev/video1 /titan.jpg

--- Opening v4l1:/dev/video1...

/dev/video1 opened.

/dev/video1: Not a V4L device?

VIDIOCGCAP: Inappropriate ioctl for device

/dev/video1 closed.

root@raspberrypi:/home/stevee# fswebcam -d v4l2:/dev/video1 /titan.jpg

--- Opening v4l2:/dev/video1...

/dev/video1 opened.

No input was specified, using the first.

Unable to find a compatible palette format.

root@raspberrypi:/home/stevee# fswebcam -d raw:/dev/video1 /titan.jpg

--- Opening raw:/dev/video1...

No palette format specified.

 

What great little command line App after all the complexity and disappointment with ZM.

For RasPi useable webcams see here:

http://elinux.org/RPi_USB_Webcams

As expected, the Creative Optia cam is v4l2 compatible and creates a picture also:

The other that worked was a

Bus 001 Device 016: ID 0ac8:305b Z-Star Microelectronics Corp. ZC0305 Webcam

Note the auto change in dimensions between the different cameras.

http://www.slblabs.com/2012/09/26/rpi-webcam-stream/

One of the nice features of fswebcam is that it's possible to add a footer to the capture, where you can specify your text of choice.
For instance, this is the command I ran fswebcam with:

$ fswebcam -r 640x480 -S 15 --flip h --jpeg 95 --shadow --title "SLB Labs" --subtitle "Home" --info "Monitor: Active @ 1 fpm" --save home.jpg -q -l 60

http://www.home-automation-community.com/surveillance-with-raspberry-pi-noir-camera-howto/

Ok, that's a big help for future considerations and testing of cheap surveillance webcameras, and after ZM did not seem to run the Pi Noir, I'll try Motion as the surveillance App.

man motion

SYNOPSIS

motion [ -hns ] [ -c config file path ] [ -d level ] [ -p

process_id_file ]

DESCRIPTION

Motion uses a video4linux device to detect motion. If motion is

detected both normal and motion pictures will be taken. Motion can also

take actions to notify you if needed. Creation of automated snapshots

is also possible.

OPTIONS

-c Full path and filename of config file. E.g.

/home/kurt/motion.conf. Default is /usr/local/etc unless speciâ

fied differently when building Motion. Many RPMs and debian

packages will most likely use /etc or /etc/motion as default.

-h Show help screen.

-n Run in non-daemon mode.

-s Run in setup mode. Also forces non-daemon mode

-d level

Run in debug mode, level 1-9.

-p Full path and filename for process id file (pid file). E.g

/var/run/motion.pid. Default is not defined. Pid file is only

created when Motion is started in daemon mode.

CONFIG FILE OPTIONS

These are the options that can be used in the config file. They

are overridden by the commandline! All number values are inteâ

ger numbers (no decimals allowed). Boolean options can be on or

off (values "1", "yes" and "on" all means true and any other

value means false).

The link above

http://www.slblabs.com/2012/09/26/rpi-webcam-stream/

has done a brief overview of Motion so let me try some things with it.

First, backup the motion.conf file to somewhere, then recap the conf file settings overview in the Post I wrote when researching it first time:

cp -v /etc/motion/motion.conf /Share/motion.conf.bak

http://www.stevepedwards.com/DebianAdmin/usb-cam-intro-to-motion-and-zoneminder/

vi /etc/motion/motion.conf

Leaving it at defaults for now to see what happens, and check first output when motion is run:

root@raspberrypi:~# motion

[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

[1] Thread 1 started

[1] cap.driver: "bm2835 mmal"

[1] cap.card: "mmal service 16.1"

[0] motion-httpd/3.2.12 running, accepting connections

[1] cap.bus_info: "platform:bcm2835-v4l2"

[0] motion-httpd: waiting for data on port TCP 8080

[1] cap.capabilities=0x85200005

[1] - VIDEO_CAPTURE

[1] - VIDEO_OVERLAY

[1] - READWRITE

[1] - STREAMING

[1] Test palette YU12 (320x240)

[1] Using palette YU12 (320x240) bytesperlines 480 sizeimage 115200 colorspace 00000001

[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] found control 0x0098090e, "Red Balance", range 1,7999

[1] "Red Balance", default 1000, current 1000

[1] found control 0x0098090f, "Blue Balance", range 1,7999

[1] "Blue Balance", default 1000, current 1000

[1] mmap information:

[1] frames=4

[1] 0 length=115200

[1] 1 length=115200

[1] 2 length=115200

[1] 3 length=115200

[1] Using V4L2

[1] Resizing pre_capture buffer to 1 items

[1] Started stream webcam server in port 8081

Let's see what's in a browser as the Noir LED is lit, after changing remote access:

# Restrict webcam connections to localhost only (default: on)

webcam_localhost off

# Restrict control connections to localhost only (default: on)

control_localhost off


Setup mode is working on ports 8080 so now stop and turn off in the conf file.

# Start in Setup-Mode, daemon disabled. (default: off)

setup_mode off

Restart and try 8081

[1] Using V4L2

[1] Resizing pre_capture buffer to 1 items

[1] Started stream webcam server in port 8081

KMeleon Browser:


http://www.instructables.com/id/Raspberry-Pi-remote-webcam/

Lots of Q+As link - Chrome and IE viewer problems! No good for Motion's stream mjpeg

IE thinks the stream is a file download!

Now to test for max screen values starting at 640 x 480:

# Image width (pixels). Valid range: Camera dependent, default: 352

#width 320

width 640

# Image height (pixels). Valid range: Camera dependent, default: 288

#height 240

height 480

[1] Test palette YU12 (640x480)

[1] Using palette YU12 (640x480) bytesperlines 960 sizeimage 460800 colorspace 00000001

OK!


3 times bigger? 960 x 720? Yep!


4 X? 1280 x 960?

[1] Test palette YU12 (1280x960)

[1] Using palette YU12 (1280x960)


5X = 1600 x 1200. Try it...yep!

[1] Test palette YU12 (1600x1200)

[1] Using palette YU12 (1600x1200)

 

I can see detail on the wallpaper and curtains now!

Try 6X? 1920 X 1440? Yep!

[1] Test palette YU12 (1920x1440)

[1] Using palette YU12 (1920x1440)

And finally! A cool command to find what formats the Pi Noir camera is capable of:

root@raspberrypi:/# v4l2-ctl -d /dev/video0 --list-formats

ioctl: VIDIOC_ENUM_FMT

Index : 0

Type : Video Capture

Pixel Format: 'YU12'

Name : 4:2:0, packed YUV

 

Index : 1

Type : Video Capture

Pixel Format: 'YUYV'

Name : 4:2:2, packed, YUYV

 

Index : 2

Type : Video Capture

Pixel Format: 'RGB3'

Name : RGB24 (LE)

 

Index : 3

Type : Video Capture

Pixel Format: 'JPEG' (compressed)

Name : JPEG

 

Index : 4

Type : Video Capture

Pixel Format: 'H264' (compressed)

Name : H264

 

Index : 5

Type : Video Capture

Pixel Format: 'MJPG' (compressed)

Name : MJPEG

 

Index : 6

Type : Video Capture

Pixel Format: 'YVYU'

Name : 4:2:2, packed, YVYU

 

Index : 7

Type : Video Capture

Pixel Format: 'VYUY'

Name : 4:2:2, packed, VYUY

 

Index : 8

Type : Video Capture

Pixel Format: 'UYVY'

Name : 4:2:2, packed, UYVY

 

Index : 9

Type : Video Capture

Pixel Format: 'NV12'

Name : 4:2:0, packed, NV12

 

Index : 10

Type : Video Capture

Pixel Format: 'BGR3'

Name : RGB24 (BE)

 

Index : 11

Type : Video Capture

Pixel Format: 'YV12'

Name : 4:2:0, packed YVU

 

Index : 12

Type : Video Capture

Pixel Format: 'NV21'

Name : 4:2:0, packed, NV21

 

Index : 13

Type : Video Capture

Pixel Format: 'BGR4'

Name : RGB32 (BE)

root@raspberrypi:/# v4l2-ctl -d /dev/video0 --list-framesizes=YUYV

ioctl: VIDIOC_ENUM_FRAMESIZES

Size: Stepwise 16x16 - 2592x1944 with step 2/2

If you want to understand the details of 4:2:0 or 4:2:2 watch guru Monty Montgomery explain it all:

http://xiph.org/video/vid1.shtml


Comments are closed.

Post Navigation