Using an Android device as a webcam for Linux

This guide shows how to use any Android device as a webcam on a Linux system. It becomes very handy for when you are like “oh shit, i’m late for my video meeting”, or when you just dont want to bother with aquire additional hardware. There exists no updated software for dealing with this as the only solution i’ve come across is Droidcam. Droidcam only works for older Ubuntu versions sadly. But fear not, because the solution is quite simple.

As a quick note: This was tested on Ubuntu 17.10, but should be compatible with most Linux based systems.

Prerequisites:

  • GIT
  • ffmpeg
  • c compiler (build-essential)
  • Your Android device must be on the same network as your computer

1. Install dependencies

sudo apt-get install git build-essential

2. Install FFMPEG, (You may need to compile this for some distributions)

sudo apt-get install ffmpeg

3. Install v4l2 loopback driver

# Clone
cd /opt/ && git clone https://github.com/umlaeute/v4l2loopback

# Install
cd v4l2loopback && sudo make && sudo make install

# Load Kernel Module videodev
sudo modprobe videodev

# Just incase you have loaded v4l2 previously
sudo rmmod v4l2loopback

# Load v4l2 module
sudo insmod ./v4l2loopback.ko exclusive_caps=1


4. Find your newly created video device:

find /dev/ -name "video*"

# Output (Example, may be different, video0-9):
/dev/video1

 

We are now ready to set up your Android device!

5. Go to Google Play and Install IP Webcam (

6. Scroll down and press “Start Server”

Your device are now streaming your webcam via whatever protocol you set it to use. Note down the IP adress and the port of your webcam steam. Now back to your linux machine!

7. Download the existing (WOHO!) webcam hook:

cd ~/
wget https://raw.githubusercontent.com/bluezio/ipwebcam-gst/master/prepare-videochat.sh
chmod +x

8. Edit the file and find the line saying WIFI_IP. Fill in your Android device IP.

9. Run prepare-videochat.sh

./prepare-videochat.sh &

You should now be up and running with a brand new webcam for your Linux machine. You can verify that it is working at https://www.onlinemictest.com/webcam-test/

 

 

 

 

 

Move from block partition to lvm partition on Ubuntu 17.10

This tutorial shows how to move the Ubuntu filesystem from a regular block partition, to a LVM2 Partition. This may be necessary to do if you are silly like me and forget to select LVM when installing your Ubuntu system. This guide assume that you have a secondary hard-drive/partition with equal or more space than your old block partition. Lets get on with it!

First, log in as root. Ah, and i take no responsibility if you mess things up 🙂

1. Identify which hard-drive you will use for your LVM Partition. Create a partition. In my case i used /dev/sda and created a partition at /dev/sda2. I used the graphical interface that ships with Ubuntu Mate, but you can also use parted/gparted etc.

2. Create a new LVM parition

 pvcreate /dev/sda2

3. Create a new Logical Group. You can call it whatever. I call mine vg_root.

 vgcreate vg_root /dev/sda2

4. Create a new Logical Volume. The -L argument specifies the volume size. In my case i create a 60 GB volume. As mentioned, it should be larger than your old filesystem

 lvcreate -L 60G -n lv0 vg_root

5. Format the partition with ext4.

 mkfs.ext4 /dev/vg_root/lv0

6. Mount the newly created volume

mkdir /mnt/new_root
mount /dev/vg_root/lv0 /mnt/new_root/

7. Copy old filesystem to the mounted location

cp -ax / /mnt/new_root/
cp -ax /boot /mnt/new_root/

8. Edit /etc/fstab. Comment out the old / mount point and add

/dev/vg_root/lv0 / ext4 errors=remount-ro 0

9. Mount new filesystem

mount -o bind /dev /mnt/new_root/dev
mount -t proc none /mnt/new_root/proc
mount -t sysfs none /mnt/new_root/sys
cd /
chroot .
cd /mnt/new_root/
chroot .

10. Update Grub

 update-grub

 

11. Reboot

You should now be up and running on your newly create LVM partition

Oh, so you fucked up? If you managed to do the copy procedure correctly, you can still save this. Boot up ubuntu from live-cd

12. Install Boot-Repair

sudo add-apt-repository ppa:yannubuntu/boot-repair
sudo apt-get update
sudo apt-get install -y boot-repair && boot-repair

13. Follow instructions carefully

14. Reboot

Now you should be up and running!