Video Surveillance: Configuring the Client Machine

This is the first part of a tutorial series regarding video surveillance that will teach you how to set up a remote video surveillance system. In this particular article, you will learn how to configure the client machine (the one to which the camera is attached), to read the stream from your camera and make it accessible from a remote location via network or internet.

Note that there are many software solutions (both free and paid) that can read the camera stream and output it to an IP address, but in this tutorial, I will show you how to create a program in Java that does the same thing.

Required Java Libraries

There are many Java libraries that can be used to stream the video from the camera. The simplest one to use is vlcj, which can be downloaded from here. After downloading the zip file, you will have to include external libraries in your Eclipse or NetBeans project. To do that, right click on your project, select properties, then Java build path, and then the libraries tab. Click the Add external JARs button, browse to the folder where you saved the files, and select the all the JAR files extracted from the zip file.

Vlcj is actually a bridge between java and VLC media player. That means that you will have to install VLC media player and use its two files (libvlc.dll and libvlccore.dll). You could also use VLC media player’s interface to stream a video, but if you need some customizations, creating your own program is a good solution.

Creating a Video Streaming Program

Streaming a video is actually sending the output to an IP address and a port on it, so that someone can connect to that IP address and port and view the video. Thanks to vlcj library, the code for stream output is quite simple:

public class WebCam {    public static void main(String[] args) throws Exception {                // Add the path to libvlc.dll and libvlccore.dll, so Java can find them    	NativeLibrary.addSearchPath("libvlc", "C:/Program files/VideoLAN/VLC/");    		// Select a device to capture video from. See more info below.    	String media = "dshow://";        	// Stream options – in this example, the stream would be available                // on http://192.168.1.100:5555String options = formatStreamOptions("192.168.1.100", 5555);System.out.println("Streaming '" + media + "' to '" + options + "'");MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(args);HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();mediaPlayer.playMedia(media, options);Thread.currentThread().join();    }    private static String formatStreamOptions(String serverAddress, int serverPort) {    	StringBuilder sb = new StringBuilder(60);           	sb.append(":dshow-adev=none :dshow-vdev= my-camera-name :dshow-aspect-ratio=4\:3 :live-caching=200");           	sb.append(":sout=#duplicate{dst=std{access=http,mux=ts,");   	sb.append("dst=");  	sb.append(serverAddress);  	sb.append(':');   	sb.append(serverPort);  	sb.append("}}");    	return sb.toString();    }}

Let’s explain the code. First, Java sometimes cannot find the VLC files, so you need to add the path to them. After that, you have to select a device from which to capture video. However, device name is not used there, but a media resource locator (MRL). MRL is used to uniquely identify a media resource. Your device is usually a default device and can be accessed with “dshow://”, but in case that does not work, read more about using MRL here and here. The options string represents VLC commands that will be used.

The above example is using HTTP to stream the video. However, other protocols, such as RTSP (Real-time Streaming Protocol), can also be used. The program that uses RTSP to stream the video would look like this:

public class WebCam {    public static void main(String[] args) throws Exception {    	// Add the path to libvlc.dll and libvlccore.dll, so Java can find them    	NativeLibrary.addSearchPath("libvlc", "C:/Program files/VideoLAN/VLC/");	// Select a device to capture video from. See more info below.   	String media = "dshow://";	// Stream options – in this example, the stream would be available                // on rtsp://192.168.1.100:8435String options = formatStreamOptions("192.168.1.100", 8435, "demo");System.out.println("Streaming '" + media + "' to '" + options + "'");MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(args);HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();mediaPlayer.playMedia(media,            options,            ":no-sout-rtp-sap",            ":no-sout-standard-sap",            ":sout-all",            ":sout-keep"        );        Thread.currentThread().join();    }    private static String formatStreamOptions(String serverAddress, int serverPort, String id) {        StringBuilder sb = new StringBuilder(60);        sb.append(":sout=#rtp{sdp=rtsp://@");        sb.append(serverAddress);        sb.append(':');        sb.append(serverPort);        sb.append('/');        sb.append(id);        sb.append("}");        return sb.toString();    }}

To be continued…

In the next two parts of this tutorial, you will learn how to:

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

6 Tips for Setting Up a Decentralized Exchange

6 Tips for Setting Up a Decentralized Exchange

There’s no doubt that cryptocurrency is a complex and divisive topic in the modern financial landscape. There are those who are convinced that it’s nothing more than a bubble, but both who are well-informed are able to see the ways in which cryptocurrency can help them both build their fortune

user experience with someone on their phone

5 Ways to Improve Your Customers’ User Experience

They say you can’t judge a book by its cover, but just because they say that doesn’t mean it’s true. Consider how often you choose one sort of product over another just because it appeals to you. Then think about how often you’ve stopped using something because, simply put, it

How to Manage Your Finances after Buying a Home

How to Manage Your Finances after Buying a Home

Buying a home is a milestone in the journey of life – it’s one way to invest your money and create lasting memories. Now you know everything about a home purchase, home mortgage, and what is a conventional 97 loan but do you know what’s next after you sign the

Windows Logging is one of the vital aspects of any Windows system administration. However, it is mostly overlooked until the system develops a problem. This is because logs contain important information needed to troubleshoot and resolve system issues.

The Fundamentals of Windows Logging

Windows Logging is one of the vital aspects of any Windows system administration. However, it is mostly overlooked until the system develops a problem. This is because logs contain important information needed to troubleshoot and resolve system issues. Without it, tech experts might find it difficult to track a computer’s

Interstitial Ads: Best Practices for Successful Campaigns

Interstitial Ads: Best Practices for Successful Campaigns

Interstitial Ads: Best Practices for Successful Campaigns Interstitial ads are full-screen advertisements that appear to grasp the attention of on-site prospects, creating opportunities for brands seeking effective ways to communicate their proposition of value. With such an attention-grabbing format and high-impact visuals, it’s no wonder why interstitial advertising is proving