How to use the command fswebcam (with examples)
fswebcam
is a small and simple webcam for *nix operating systems. It allows users to capture images from their webcams and save them as image files. The command provides several options to customize the image capture process, such as specifying the resolution, selecting the webcam device, and adding a timestamp to the image.
Use case 1: Take a picture
Code:
fswebcam filename
Motivation:
Taking a picture with fswebcam
is as easy as running the command followed by the desired filename. This use case is useful when you want to quickly capture an image without any customization.
Explanation:
filename
: Specifies the desired name for the image file to be created.
Example output:
The fswebcam
command successfully saves the captured image as image.jpg
in the current directory.
Use case 2: Take a picture with custom resolution
Code:
fswebcam -r widthxheight filename
Motivation:
Sometimes you may want to capture images with specific resolutions. By using the -r
option followed by the desired width and height separated by ‘x’, you can customize the resolution of the captured image.
Explanation:
-r widthxheight
: Sets the resolution for the captured image. Replacewidth
andheight
with the desired numeric values.
Example output:
Running fswebcam -r 800x600 image.jpg
captures an image with a resolution of 800x600 pixels and saves it as image.jpg
.
Use case 3: Take a picture from a selected device
Code:
fswebcam -d device filename
Motivation:
If your system has multiple webcam devices, you can use the -d
option to specify the desired device to capture the image from. By default, fswebcam
uses /dev/video0
.
Explanation:
-d device
: Specifies the device to be used for capturing the image. Replacedevice
with the desired webcam device identifier.
Example output:
Using fswebcam -d /dev/video1 image.jpg
captures an image from the device /dev/video1
and saves it as image.jpg
.
Use case 4: Take a picture with timestamp
Code:
fswebcam --timestamp timestamp filename
Motivation:
Adding a timestamp to the captured image can be helpful for record-keeping purposes or when you need to associate a specific time with the image. The --timestamp
option allows you to include a timestamp on the image file, formatted by strftime
.
Explanation:
--timestamp timestamp
: Specifies the timestamp to be added to the image. Replacetimestamp
with the desired format usingstrftime
formatting.
Example output:
Running fswebcam --timestamp "%Y-%m-%d %H:%M:%S" image.jpg
captures an image with the current date and time in the format “YYYY-MM-DD HH:MM:SS” appended to the image file name. For example, the image file may be saved as image_2022-01-01 12:34:56.jpg
.
Conclusion:
fswebcam
is a versatile command-line tool for capturing images with a webcam on *nix operating systems. By using the various options available, you can customize the resolution, device, and timestamp of the captured image. Whether you need a quick snapshot or a detailed image, fswebcam
provides the flexibility to meet your requirements.