Live video streams
Nick Peers reveals how to add webcams to your PC, as well as putting them to various practical and fun uses.
Nick Peers reveals how to add webcams to your Ubuntu-based PC, plus put them to various practical (and fun) uses..
Video capture is easy nowadays, thanks to Linux’s wide range of video tools. Whether you want to record video messages, create animated movies, chat with far-flung friends and family or keep an eye on things while you’re away, there’s a multitude of apps to give you exactly what you need. Of course, you also need a camera to record yourself, and because of Linux’s universal UVC driver, you have access to a wide range of cheap – and some not so cheap – webcams.
UVC stands for USB Video Class, which doesn’t simply cover external webcams but also includes internal models found in laptops. It’s been a part of all Linux installations since kernel 2.6.26, and works in a similar way to mass-storage drivers in that it provides a generic driver for any Uvc-compliant webcam, which covers a wide range of models.
If you’ve already got a webcam, how can you determine if it’s Uvc-compliant? If you’re impatient, you could simply open Cheese (see later) – if it’s working, you’ll know it the moment the app opens.
If it doesn’t show up, perform a few tests by opening the Terminal and typing the following command to list all USB devices attached to your PC:
$ lsusb
You should be able to identify your webcam from here by its manufacturer and model name, or the telltale ‘webcam’ or ‘camera’ designation. Make a note of its ID and type the following, substituting 0c45:6341
with your device’s ID:
$ lsusb -d 0c45:6341 -v | grep “14 Video”
If you see several lines appear referring to bfunctionclass and binterfaceclass relating to 14 Video , your webcam is Uvc-compliant. If the magic ‘14 Video’ line shows up, try a different app – for example,
VLC users should go to Media > Open Capture Device. Click the ‘Video device name’ drop-down menu, where you should see /dev/video0 as an option (other connected webcams will also appear under /dev/ video1 and so on). Select this, then click Play. After a short pause the webcam camera should switch on to display what it can see.
Say Cheese
The simplest way to use your webcam is with Ubuntu’s built-in – and rather basic – Cheese application. It lets you take photos and record video from your webcam, plus gives you the option of applying one of 17 special overlay effects to your video stream before you hit the capture button.
Fire up the app; it automatically selects your default webcam and displays a real-time image of what it’s currently showing. You’ll see three buttons beneath the preview display: Photo and Video are self-explanatory, while Burst will take a group of photos in quick succession (by default, it’ll snap four photos spaced at one-second intervals).
Once you’ve chosen what you want to capture, click the camera button. If you’re taking a single photo or photo burst it’ll count down from three before taking the shot; if recording video, it’ll start the moment you click the button – click again to end the recording.
Photos or video are placed in the ‘photo stream’ at the bottom of the Cheese window. They’re saved in the Pictures/webcams and Videos/webcams folders respectively, but you can save them elsewhere by rightclicking and choosing ‘Save as’. Sadly you’re restricted to JPEG (for photos) and Webm (for video) formats. Double-click a photo or video to view it, or right-click to delete it from your hard drive, and the Cheese stream.
Click Effects to bring up a choice of 17 special overlay effects, split across two pages – click < and >
next to the Effects button to move between them. Select an option and the real-time preview immediately updates to show you how the effect will look – it’s then applied to any photos or video you subsequently take (you can’t apply these to existing recordings or snapshots, however). Effects range from simple colour casts such as Hulk, Mauve or Noir/b&w to more sophisticated effects like Historical and the weird and wacky Optical Illusion and Radioactive (more like
Doctor Who 1980s-style).
You can open the Cheese menu and choose Preferences to switch webcams if you have more than one connection, set a higher (or lower) photo and video resolution depending on what your webcam supports, plus tweak brightness, contrast, saturation and hue settings. You can also configure various image-capture settings: use the webcam’s flash (if it has one), forego the countdown, and change the burst-mode behaviour by selecting the number of photos to take and the delay between them. Sadly, you can’t snap faster than the default one second between photos.
Video capture alternatives
Cheese is a capable video capture tool, but it does lack advanced features. One alternative that offers a bit more control – if a slightly less user-friendly approach – is GTK+ UVC Viewer, which you can install with the following commands:
$ sudo add-apt-repository ppa:pj-assis/ppa
$ sudo apt-get update
$ sudo apt-get install guvcview
Once installed, launch it from Show Applications and you’ll see two windows: a preview of the currently selected webcam and the main Guvcview window with buttons for capturing images and video. There are also three tabs giving you more control over the image quality, with additional settings based on your webcam’s capabilities – for example, controlling sharpness, white balance and exposure.
The Video Controls tab enables you to set your desired frame rate in addition to altering the camera resolution. There’s a Camera Output option for switching to an uncompressed format if quality trumps file size, plus various video filters to try. Use the Audio Controls tab to choose a different audio device (such as a microphone) as well as tweaking sample rate, channels and latency – again, you’ll find a few effects such as echo, reverb and wahwah.
Capturing is a simple affair: click ‘Cap. Image’ and a JPEG photo is saved to your home folder. Click ‘Cap. Video’ and a MKV file is saved to the same directory. Unfortunately you can’t change the location. If you like what you see, but want more features and effects, check out the annotation of Webcamoid (see bottom-left).
Record stop-motion
One creative use for your webcam is as a tool to record stop-motion animations. Search for ‘Stopmotion’ in the
Software Centre; once it’s installed, open the program and follow the step-by-step guide (over the page) to create your first stop-motion movie. If your laptop camera is a bit restrictive, see the Quick Tip (upper
right) for an alternative involving a flexible arm. Make sure you regularly save your work. Once it’s complete you’ll need to export the individual frames in video form to share with others; before doing so, visit ‘Settings > Configure Stopmotion’ and switch to the Video Export tab. You’ll see that the default choice is ‘avconv’. Select ‘ffmpeg’ instead to create a MPEG4 video, or use one of the mencoder options to create a MPEG1 or MPEG2 video. If you go down this route you’ll need to install mencoder separately with sudo apt-get install mencoder . Once configured, choose File > Export > Video to save your video – make sure you include the file extension (.mp4 in most cases), or the conversion will fail.
Another practical use for a webcam is to provide a live video feed. You might want to demonstrate something to a public audience, or simply provide
yourself with a means of monitoring your home or pet while away. For one-off, time-limited live broadcasts, you could look at an online solution for hosting your feed, such as Youtube.
Sign into your account at www.youtube.com, then click the ‘Create a video or post’ webcam icon at the top. Choose ‘Go Live’, grant access to your webcam and/or microphone, then give the upcoming broadcast a title. Select your privacy settings: choose Private if you want to restrict it for your own personal use – you’ll then view it when signed into your own account under ‘Library > My videos’.
Click ‘More options’ if you’re publicly broadcasting and want to add additional features such as restricting chats or adding a description to help others find it. Once done, click Next, create a thumbnail and finally Click ‘Go Live’ to start your broadcast.
From here, the stream is managed from your browser so you’ll need to leave the tab open for the stream to continue. Click ‘End Stream’ when you’ve finished broadcasting.
Set up a surveillance system
That’s the easy way to broadcast live, but it’s not practical if you have a long-term streaming plan in mind (for example, as a security camera). Rather than tie up your main PC in this way, you can offload such a task to a suitable NAS such as one from QNAP or Synology, or press into service a dedicated device such as a Raspberry Pi. If going down the Pi route, consider a POE (Power over Ethernet) option so that you can site it without having to worry about a nearby power source.
One open-source surveillance tool that will work with multiple webcams is Zoneminder (www.zoneminder. com) – it even comes with mobile apps for checking your webcams on the go. It’s recommended that you run it on an Ubuntu Server install where you have selected the LAMP option during the installation process to install Apache, MYSQL and PHP. It’s a lengthy but not particularly complicated process to set up Zoneminder – head to http://bit.ly/lxf250zone and choose ‘Installation Guide’, followed by the Ubuntu section. Other distros are covered there too, including Debian and Red Hat; Pi users should follow the instructions outlined at https://wiki.zoneminder. com/debian.
If that’s all a bit too complicated and you simply want to use a camera or two to display or monitor something while your PC is up and running, check out a tool called ivideon (see box, lower left). Raspberry Pi users looking for a dedicated surveillance distro should check out Kerberos (www.kerberos.io) instead.
VOIP options
Last but by no means least are the tools for using your webcam to video-chat with friends, family or colleagues. The chat software you need depends, of course, on what your contacts are using. The market’s big players are Skype and Facebook Messenger; the former has its own dedicated Linux app, while you can access the latter in its own window via an open-source desktop app called Caprine. Both can be installed through the Software Centre.
Slack is another popular messaging tool in the workplace, and a beta desktop client of this can be downloaded from http://bit.ly/lxf250slack, with video and voice chat support built-in.
Those looking for a more secure, private chat tool to displace Skype should investigate one of three decentralised P2P video communication tools with endto-end encryption as standard. First up is Retroshare
(https://retroshare.cc), which combines messaging with forums, channels and mailboxes – audio and video calls are supported through the optional VOIP plug-in.
Tox (https://tox.chat) is more of an instantmessaging tool with added video chat, and Jami
(https://jami.net) offers video-conferencing features in addition to simple VOIP capabilities. It also lets you send pre-recorded video messages as file attachments.
All these apps work in a similar way – and rely on your contacts being persuaded to follow you to the platform in question. Retroshare is perhaps the fiddliest to set up, which may put off potential chat partners, but it will appeal to the ultra security-conscious.