Tech Quickie: Convert your ipad/iphone into a good wireless webcam in Linux

in #technology6 years ago

Hi there,

I just wanted to show you how to take your Apple device and use it as a regular webcam in linux. The advantage being is that it works wirelessly with hd video. Audio won't work with this method, however that doesn't mean audio is impossible to get. This is just a quick hacky method that will work with a lot of devices with some tweaking.

Why?

The short story is that I am learning CV or computer vision with some machine learning. I didn't want to use static images or videos while I am learning , but I also didn't want to get a webcam when I already have a $400 iPad pro 4 and $900 Android phone that can do the same thing better. So... here we are.

To start, you will need an app called "IP camera - High end network camera" on your mobile device. This will let you use your iPad as a network camera via a local IP. But you can do a lot more with this app, try it out. Android phones will have similar apps, but the process will be different most likely. The command we'll be using relies on a webpage that has a single image being updated constantly.

IMG_0038.PNG

1). Install IP camera and start it. You will see an IP address for the iPad. you can view the live feed in any browse with this URL. In our case, we will be using a kernel module to create V4L2 loopback devices.

IMG_0047.PNG

2). Install v4l2loopback - a kernel module to create V4L2 loopback devices from here https://github.com/umlaeute/v4l2loopback

This kernel module can be built from source or you can use your distro's package manager. Follow the readme file from the git repo if you want to build it. v4l2loopaback is like x-split or OBS in that it can create fake video devices from other sources.

Arch Linux users: Run yaourt -S v4l2loopback-dkms-git to install the package.
Other distros may have a similar install command. Google it :)

3). Run sudo modprobe v4l2loopback devices=1 to make a blank device. We just need to give it some video input now!

4). Open a new terminal.

5). Run gst-launch-1.0 souphttpsrc location=http://192.168.1.125:80/live ! jpegdec ! videoconvert ! v4l2sink device=/dev/video0

This command takes the jpeg image and then passes it to some special filters. This will create a raw video stream to be used by our fake camera device called video0. The input can be anything too with some argument tweaks of gst-launch.

6). We are done now. If everything worked, you should be able the fake webcam in apps. However, you may need to run one of the following commands before running your app. The most common error is invalid color modes.

export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so
export LD_PRELOAD="/usr/lib/libv4l/v4l2convert.so"

Good luck and have fun! This is pretty niche use, but it works for what I need. Upvote if you like this post and want more like this.


Just a FYI. There are phone apps that use a custom desktop receiver app. This is great if you want a security camera to use, but not useful in this case. I could've made my life easier making my own app, but that requires a Mac computer to code apps for iOS in general. Which I don't have a Mac computer.

Sort:  

Thanks for your article.
Check out my tutorial if you wanna know How to: Use your Android mobile device as streaming camera with OBS, using IP Webcam.

Coin Marketplace

STEEM 0.30
TRX 0.11
JST 0.033
BTC 63968.82
ETH 3136.80
USDT 1.00
SBD 4.28