LinuxCommandLibrary

fswebcam

Capture images from a webcam

TLDR

Take a picture

$ fswebcam [filename]
copy

Take a picture with custom resolution
$ fswebcam [[-r|--resolution]] [width]x[height] [filename]
copy

Take a picture from selected device(Default is /dev/video0)
$ fswebcam [[-d|--device]] [device] [filename]
copy

Take a picture with timestamp(timestamp string is formatted by strftime)
$ fswebcam --timestamp [timestamp] [filename]
copy

SYNOPSIS

fswebcam [options] image_file

PARAMETERS

--device
    Specify the V4L2 device file (e.g., /dev/video0).

--resolution x
    Set the capture resolution (e.g., 640x480).

--input
    Select a specific input on the device (e.g., for multi-input cards).

--format
    Force a specific input format if the camera supports multiple.

--jpeg
    Set JPEG compression quality (0-100, 100 is best).

--png
    Set PNG compression level (0-9, 9 is best).

--bmp
    Output in BMP format.

--no-banner
    Disable the informational banner overlaid on the image.

--banner-colour <#RRGGBB>
    Set the banner background color using a hexadecimal RGB code.

--line-colour <#RRGGBB>
    Set the banner line color.

--text-colour <#RRGGBB>
    Set the banner text color.

--font
    Set the font for banner text (e.g., arial:10).

--title
    Set the main title text displayed on the banner.

--subtitle
    Set the subtitle text displayed on the banner.

--info
    Set additional info text on the banner.

--timestamp
    Display the current date and time on the banner.

--gmt
    Use Greenwich Mean Time for the timestamp.

--no-timestamp
    Disable the timestamp.

--top-banner
    Place the banner at the top of the image.

--bottom-banner
    Place the banner at the bottom of the image (default).

--no-overlay
    Disable all text and banner overlays.

--crop
    Crop the image before saving (e.g., 320x240,0,0).

--rotate
    Rotate the image by 90, 180, or 270 degrees clockwise.

--flip
    Flip the image horizontally (H) or vertically (V).

--greyscale
    Convert the captured image to greyscale.

--set =
    Set a V4L2 control (e.g., brightness=20). Use --list-controls to see available options.

--list-controls
    List available V4L2 controls and their current values for the device.

--list-formats
    List supported video formats for the device.

--skip
    Skip a specified number of initial frames (e.g., for camera warm-up).

--delay
    Wait for a specified duration before capturing the image.

--loop
    Continuously capture images at specified intervals (e.g., 60 for every minute).

--background
    Run in the background, typically used with --loop.

--help
    Display a help message and exit.

--version
    Display version information and exit.

DESCRIPTION

fswebcam is a small, simple webcam application for Linux. It captures images from a Video4Linux2 (V4L2) device, such as a USB webcam, and saves them to a local file. It supports various image formats like JPEG, PNG, and BMP. Beyond basic image capture, fswebcam offers features to customize the output, including adding text banners, timestamps, and adjusting image properties like brightness, contrast, and resolution.

It's often used in scripts for time-lapse photography, security monitoring, or simply taking a quick snapshot from a command line. Its straightforward syntax and lightweight nature make it a popular choice for embedded systems and server environments where a full GUI application is not practical or desired. It can also handle multiple cameras and offers options for controlling focus, exposure, and white balance if supported by the camera.

CAVEATS

fswebcam relies heavily on underlying V4L2 drivers; compatibility and available features (like specific --set controls) can vary significantly between different webcams and Linux distributions.

Error messages can sometimes be cryptic if the device or driver encounters issues. For consistent results, especially with time-lapse photography, it's often advisable to disable camera auto-settings (e.g., auto-exposure, auto-white-balance) using --set options or v4l2-ctl.

IMAGE FILE NAMING WITH DATE/TIME

The image_file argument can include strftime-like format specifiers to automatically name files based on the current date and time. This is particularly useful when using the --loop option for time-lapse captures.
For example: fswebcam --loop 60 /var/www/webcam/%Y-%m-%d_%H%M%S.jpg will save a new JPEG every minute with a unique timestamped filename.

DEVICE DISCOVERY

If the --device option is not specified, fswebcam will attempt to open /dev/video0 by default. If that fails, it will try other common device paths such as /dev/video1, /dev/video2, and so on, until a working V4L2 device is found.

HISTORY

fswebcam was developed by Philip Perry. It was initially released as webcam in 2004, then renamed to fswebcam (Free Software Webcam) in 2007. The project's goal was to provide a simple, lightweight, and efficient command-line tool for capturing images from webcams, particularly suited for environments without a graphical interface, such as servers or embedded Linux devices.

SEE ALSO

streamer(1), v4l2-ctl(1), ffmpeg(1), convert(1)

Copied to clipboard