Example Script to Capture Webcam Images on Linux

October 3, 2015

This is a simple example script that will capture images from a webcam on a Linux computer at the specific interval and save them off.

First, you may need to install some dependencies.

sudo apt-get install streamer netpbm

Save off the following script and make it executable.

#!/bin/sh
 
interval=5
 
while true
do
  	streamer -q -o capture.ppm
 
	# now convert to jpeg
	now=$(date +"%b-%d-%y-%S")
	pnmtojpeg capture.ppm > capture-${now}.jpg
 
    	# streamer can take captures using its own interval/delay
	# but we'll use sleep anyway
  	sleep $interval
done

You can simply press Ctrl-C to quit.

Related Posts