Introduction
The article describes how you can use your Android phone as webcam or remote surveillance camera through Skype or VLC Media Player or any other applications that uses DirectShow API. The Android app used here can be found here and the source code is available here.
Background
If you happen to have more than 1 Android phone and you are thinking of how you can make use of the old Android phone besides selling it, then this article is for you.
Using the App and the Source Code
The Android app that I developed is capable of streaming MJPEG. It uses NanoHttpd and extends it to support motion JPEG.
Whenever a video frame is captured, it is streamed as a series of JPEG images as shown below.
private class VideoStreamingTask extends AsyncTask<datastream, void=""> {
@Override
protected Void doInBackground(DataStream... videoStreams) {
isStreamingVideo = true;
byte[] data = null;
while (true) {
if (!isStreamingVideo)
break;
DataStream videoStream = videoStreams[0];
try {
OutputStream os = videoStream.getOutputStream();
if (os != null) {
data = getSnapshot();
if (data == null)
continue;
os.write(("Content-type: image/jpeg\r\n" +
"Content-Length: " + data.length +
"\r\n\r\n").getBytes());
os.write(data);
os.write(("\r\n--" + NanoHttpd.MULTIPART_BOUNDARY + "\r\n").getBytes());
os.flush();
}
} catch (IOException e) {
Log.e(TAG, "[doInBackground] Error writing stream", e);
break;
} catch (Exception e) {
Log.e(TAG, "[doInBackground] General exception", e);
break;
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
}
}
</datastream,>
Look into the Java classes under com.mymobkit.net package you can find the various Java classes that use NanoHttpd to host a web server inside your Android app.
By using the Android app, once you start the control panel, you should be able to access the web interface through Chrome browser. Turn on the surveillance camera and you should be able to view your camera remotely. Click on the Media Information button and you can see the URL for the MJPEG stream.
Image showing URL of web control panel
Image showing the MJPEG URL
In order for Skype to use MJPEG, download and install either IP Camera Adapter or IP Camera [JPEG/MJPEG] DirectShow Filter. Below is a screenshot of what you should see in Skype. You should see MJPEG Camera for IP Camera Adapter, or IP Camera [MJPEG/JPEG] for IP Camera [JPEG/MJPEG] DirectShow Filter.
Now with the MJPEG url and also make sure the camera is turned on through the web control panel, open up your Skype.
Perform the following steps
- click Tools > Options
- Under Video settings, choose "MPJEG Camera" (I am using IP Camera Adapter)
- click WebCam settings
- Paste the MJPEG url into the Camera feed URL text box
- click Autodetect to make sure the URL is working (make sure the camera is turned on).
- click OK if everything is fine.
Change the following configurations to allow Skype to answer video call automatically.
- click Tools > Options
- Under Calls, click Call settings
- Click Show advanced options
- Tick Answer incoming calls automatically.
- Tick Start my video automatically when I am in a call
With all the configurations in place, now is time for you to test. Create another Skype id and login using that id from another machine. In my case, I installed Skype in my tablet, and add the Skype id I used with the Android phone.
Here is what you should see if you make a video call now.
Using VLC Media Player
VLC Media Player also supports network streaming using MJPEG. You can open a network stream and view the video remotely.