This article is part of the Webcam Cool Project. You should check the project homepage first!
For anyone wanting to set up a simple command line webcam capture program in Ubuntu, I recommend using Synaptic to install camE from the repos.
camE is a command line utility that takes a snap from a Video4Linux (V4L) device at dev/video0 (your webcam) and either saves it as a file locally or uploads it to a server via FTP or SCP.
I used camE with a Logitech Sphere webcam and it worked faultlessly. Unfortunately I later changed it to a Logitech QuickCam 5000 which camE didn't like ('unsupported palette' error) so I had to switch to using fswebcam, but I like camE as it's highly configurable and rock solid so it's worth a look.
By default there will be no config file installed with camE so you'll need to create one in your home directory with the command:
nano ~/.camErc
... and paste the following into it....
# --------------------------------------------------------------------
# camE example configuration
#
[ftp]
#host = host name or IP address
#user = usernamehere
#pass = userpswdhere
dir = /tech-tips/public/webcam
# where should the file end up? Also, this extension determines the file
# type the image is saved as. Try image.png for a png.
file = webcamimg.jpg
# camE uploads to a temp file, and moves it across when done
# this way people don't view half-uploaded images
tmp = uploading.jpg
# keep the connection open (1) or reopen it for each shot (0)
keepalive = 1
# do passive ftp?
passive = 0
#an interface to use for non-passive ftp. use "-" to let libcurl choose, or
#use a real interface name. (libcurl often chooses incorrectly)
interface = -
# ftp debugging? (noisy)
# Set to '1' while testing so messages are displayed in terminal
debug = 1
#
# Actually do the upload? If do = 0, just take and archive pics.
do = 0
# Some servers require us to explicitly delete the previous image
# In that case, enable this option
delete_first = 1
# Determines how many shots are taken before an image is uploaded.
# (1 == every picture is uploaded, 10 would be every 10th image)
# (Defaults to 1 if not present)
upload_every = 1
# you can set ftp->do to 0 above and use scp instead - you still need
# the dir, file and tmp settings in the ftp section for this to work.
# scp also honors the upload_every setting from the ftp section, and
# will also default to a value of 1 if not present.
[scp]
# target = user@host
# ---------------------------------------------------------------
[grab]
# use
device = /dev/video0
# store temp image on local machine
temp_file = ~/Pictures/viewcam.jpg
# lag reduction, takes 5 shots, discards the first 4, thus clearing mmap
# buffers
lag_reduce = 0
#lag_reduce = 5
# This goes at the bottom left, with the message from "infofile" appended.
# It is run through strftime, so date vars are expanded.
text = %d/%m/%Y %H:%M:%S %Z
width = 320
height = 240
# delay (seconds) between uploading one shot and starting the next
delay = 60
# do we want to correct the delay for a slow connect?
# (keeps the perpetually updating clients in sync)
correct = 1
# scale image resolution dynamically based on bandwidth?
# percentage of the delay to spend uploading the image,
# 100 disables, useful values are < 40
percent = 100
################################################## ######
# PWC specific features (only for Phillips cams right now)
# framerate of cam capture, lower fps -> less grainy image, more chance or
# blurred motion
#framerate = 5
framerate = 10
# image settings (0-100)
colour = 50
brightness = 50
contrast = 50
hue = 50
whiteness = 50
# White balance mode
# can be "auto", "indoor", "outdoor", "fluorescent" or "manual"
pwc_wb_mode = auto
# if _mode is set to manual, these two controls affect the balance
# (0-100)
pwc_wb_red = 50
pwc_wb_blue = 50
# Backlight compensation mode
# switched off, when set to 0
pwc_backlight_mode = 1
################################################## ######
# where to log activity. comment out this line to disable logging
# logfile = /var/log/camlog
# gets the message text from here. one line allowed only. means you can do
# stuff like echo "sleeping and stuff" > ~/.caminfo
infofile = /tech-tips/itsme/.caminfo
# directory to archive pics in. They are datestamped and saved in here.
archive = /opt/images/webcam
# archive pics in datestamped subdirs
# (1 == with subdirs, 0 == without subdirs)
archive_subdirs = 0
# extension (determines type) of archived images.
archive_ext = jpg
# determines how many shots are taken before a pic is archived
# (1 == every pic, 0 == don't archive)
archive_shot_every = 0
#archive_shot_every = 1
# create archive thumbnails enable/disable flag and give width/height
archive_thumbnails_dir = /opt/images/webcam/thumbnails
archive_thumbnails_create = 0
archive_thumbnails_width = 120
archive_thumbnails_height = 90
# jpeg quality (you can save as png etc too, but then quality does squat)
quality = 100
input = 0
# 0 for PAL, 1 for NTSC
norm = 0
# Goes in the top right. strftime() is run on this too, so put date stuff in
# if you like
title_text = ImageTitle
# color/transparency of title text
title_r = 255
title_g = 255
title_b = 0
title_a = 255
# font for title text. fontname/size
title_font = Arial/10
# fancy font styles
# title_style = /path/to/title.style
# color/transparency of message text
text_r = 255
text_g = 255
text_b = 0
text_a = 255
# font for message text. fontname/size
text_font = Arial/8
# fancy font styles
# text_style = /path/to/text.style
# color/transparency of rectangle behind text
# make it 0,0,0,0 to disable.
bg_a = 0
bg_b = 0
bg_g = 0
bg_a = 75
#bg_a = 100
# directory to look for ttf fonts in
ttf_dir = /usr/share/fonts/truetype/msttcorefonts
#ttf_dir = /usr/X11R6/lib/X11/fonts/TrueType
# ************************************************** *************************
# file to check for before shooting. while this file exists, no shots will
# be taken.
# ************************************************** *************************
blockfile = /tech-tips/root/BLOCKCAM
# ************************************************** *************************
# image to upload when blockfile is first put in place
offline_image = /tech-tips/root/.block.jpg
# ************************************************** *************************
# File to check before shotting, while this file exists, shots will be taken.
# but not uploaded. blockimage will not be uploaded if you set this.
uploadblockfile = /tech-tips/root/BLOCKUPLOAD
# ************************************************** *************************
# Shots will only be taken/uploaded if the specified interface is active.
#watch_interface = ppp0
watch_interface = eth0
# image to overlay
overlay_image = /tech-tips/itsme/.lb.png
overlay_x = 5
overlay_y = 5
# do things. like play sounds or whatever. Each is a shell command.
#action_pre_shot
#action_post_shot
#action_post_upload
# image processing
# crop = 1
# crop_width = 320
# crop_height = 240
# crop_x = 20
# crop_y = 20
#
# scaling is applied after cropping, so you can###
# remove borders then stretch up the result
# scale = 1
# scale_width = 640
# scale_height = 480
#
# Flip the image horizontally or vertically.
# Horizontal flipping is useful for some Philips cams
# which give a mirrored image when used with the pwc module.
# flip_horizontal = 1
# flip_vertical = 1
#
# Change the orientation of the image.
# Useful if your camera is on its side (for whatever reason).
# 1 rotates clockwise by 90 degrees, 2, rotates clockwise by 180 degrees,
# 3 rotates clockwise by 270 degrees.
# orientation = 1;
A few points to note about this example config file...
Uncomment the lines you need by removing the hash (#). Similarly, comment out the lines you don't want by preceeding them with a hash.
Enter the valid FTP or SCP parameters to copy a captured image to a server. Be aware that there is no method for entering a password with SCP so for that method to work you will need to set up certificate based authentication with the public certificate installed on the client camE machine. If you're using SCP you will also need certain parameters from the FTP section, namely the Dir, File and Tmp settings so don't comment them out. For FTP or SCP to work set do=1.
With debug=1 set in the FTP section, status messages will appear in the console window in which camE was started. This will allow you to keep an eye on what is going on. Once it's all running properly, set debug=0.
This config file assumes your webcam is at dev/video0.You can check to see if this is valid on your installation by running the command find /dev/video0 which will return with 'dev/video0' if successful or an error if not.
The date, time and a title will be displayed within the image. Comment out the text and title_text lines if this is not desired. Amend these lines to change the format of the date or to set the title.
An offline image can be set so that, if present, it will prevent the webcam image being displayed.
Ensure the correct network interface is set if using FTP/SCP. Run an ifconfig command to find your live interface name if required. By default eth0 is set.
To start camE using the config file in ~/.camErc use: usr/bin/camE
To start camE with an alternative config file use: usr/bin/camE -c /PathToAltConfig/altconfig
To start camE as a daemon (background) use: usr/bin/camE -d
To stop camE use: pkill camE
Be sure to stop each instance of camE with the pkill command before starting it again or you'll get an error stating the default video device is busy.
If you get any font errors when you start camE such as can't load font FreeSans/8 (or arial/8 as specified in the above example config), then your image won't be displayed with the title or title_text parameters. To fix this, install the msttcorefonts package. You can get this from Synaptic or with sudo apt-get install msttcorefonts
If you have problems getting camE to work, try fswebcam (see link below for details).
Related articles on this site:
Webcam Project homepage
Using a Video4Linux2 (V4L2) compliant webcam with fswebcam
Refreshing a webcam image with Java and using a webcam with Joomla 1.5
Making a weatherproof webcam for outdoors
The view from my corner of Leamington Spa via my TV aerial mounted webcam!
The electro-mechanical USB reset circuit
One year on...
External Links:
camE