Using Android Camera as Webcam on Linux

After recently acquiring a new android smartphone, I’ve become interesting in testing the capabilities of its camera. One concept I’ve been curious to experiment with is live-streaming footage of my 3DS without the usage of a modded console, as I’ve seen this done fairly well. The first step to doing this though requires some setup, which is what I will explain in this guide.To stream footage from an android device to linux, I start with an app called IP Webcam. This allows the camera data to be sent over a network. There are two ways the data can be transferred: Wireless and USB tether. I opt for the USB method, since it should in theory reduce latency and data loss. This also prevents flooding my router with the data transfer. Note though, to accomplish this the USB tether option must be available on the android device. As far as I know this comes standard with recent Android versions (I have Android 5.1 Lollipop).

Once the stream is started, it can be access via the following local address:

http://192.168.42.129:8080/videofeed

Using an application such as VLC player’s network stream option to test this is often effective. Note that the IP address portion is set for a USB tether. If the device is connected via WiFi, the device’s network address will be used in its place.

To capture the stream, it needs to be directed to a video device. Packages for v4l2 (video 4 Linux), and gstreamer are required:

sudo pacmatic -S v4l2loopback-dkms gstreamer0.10-good-plugins

With this, a video loopback device must be loaded into the kernel:

sudo modprobe v4l2loopback

Finally, gstreamer is used to direct the video stream to the loopback device:

gst-launch-0.10 -vt souphttpsrc location='http://192.168.42.129:8080/videofeed' is-live=true ! multipartdemux ! decodebin2 ! v4l2sink device=/dev/videoX

Note that the X in <videoX> should be replaced with the number of the loopback device. In my case, since my laptop already has a webcam set to video0, the device is found in video1.

With this, the device can be used as a normal video device, such as a webcam for Skype, as an example. I plan on using this for streaming, likely by using Open Broadcast Studio for an easier setup, and live video mixing.

5 thoughts on “Using Android Camera as Webcam on Linux

  1. Tried this solution, it “works” by creating a device, but not a single software seems to work with it. guvcview is the only software that recognized the loopback as a “dummy video source”, but refuses to use it.
    Not to mention that using gstreamer can be a little nightmarish (really, how to kill it if I want to fix something or just shut down the loopback for any reason?)
    I’d be curious to know how to fix it.

    Like

    • While I honestly haven’t tried using this in years, the only functional way I’d be using this would be with VLC + OBS. I also don’t know if it’d work better with the newer gstreamer packages available. I may re-visit this some day, but it’s not currently something I’m trying to use. Thanks for the feedback none the less.

      Like

Leave a comment