Hi everybody, droidcam is a small utility which converts an Android phone into a webcam for linux (connected by USB or Wifi). Since there is a webcam shortage right now and many people have Android phones, I thought I post my notes here for everybody who needs a webcam on a Debian 10 system. It worked for me with a Moto G4 plus with ArrowOS and a Google Pixel with the latest Android release for this device.
Technically droidcam implements a v4l2 kernel module which make the droidcam look like a local webcam. In addition, a newer version of libjpeg62-turbo is needed. This I compiled from source to /opt, since I was not sure if I break something if I recompile the experimental package for buster and replace the buster package. I built and installed the software in /opt as local install user, except the kernel module which needs to go at the regular place. This probalby could be done better, since there is a pull request which implements dkms usage. To run the phone as webcam, the droidcam app needs to be installed on the Android phone and the droidcam-cli command needs to run on the Debian machine. That is all what is needed. I hope this is useful for somebody. Droidcam: ========= # apt-get build-dep libjpeg62-turbo # apt-get install libswscale-dev gtk+-2.0 libavutil-dev # mkdir /opt/libjpeg62-turbo-2.0.4/ => I have a local user just to install software into /opt or /usr/local/ # chown install /opt/libjpeg62-turbo-2.0.4/ # cd /opt # ln -s libjpeg62-turbo-2.0.4 libjpeg-turbo As install user new libjepg62-turbo: # su - install install@gigabyte:~$ wget http://deb.debian.org/debian/pool/main/libj/libjpeg-turbo/libjpeg-turbo_2.0.4.orig.tar.gz install@gigabyte:~$ tar xfz libjpeg-turbo_2.0.4.orig.tar.gz install@gigabyte:~$ mkdir build install@gigabyte:~$ cd build/ install@gigabyte:~/build$ cmake -G"Unix Makefiles" cmake - DCMAKE_INSTALL_PREFIX=/opt/libjpeg62-turbo-2.0.4/ ../libjpeg-turbo-2.0.4 -- The C compiler identification is GNU 8.3.0 [...] [...] -- Build files have been written to: /home/install/build install@gigabyte:~/build$ make Scanning dependencies of target simd [ 0%] Building ASM_NASM object simd/CMakeFiles/simd.dir/x86_64/jsimdcpu.asm.o [ 0%] Building ASM_NASM object simd/CMakeFiles/simd.dir/x86_64/jfdctflt- sse.asm.o [ 1%] Building ASM_NASM object simd/CMakeFiles/simd.dir/x86_64/jccolor- sse2.asm.o [...] [ 97%] Built target djpeg [ 98%] Built target jpegtran [ 99%] Built target jcstest [100%] Built target md5cmp Install the project... -- Install configuration: "Release" [...] -- Installing: /opt/libjpeg62-turbo-2.0.4/bin/jpegtran -- Set runtime path of "/opt/libjpeg62-turbo-2.0.4/bin/jpegtran" to "/opt/ libjpeg62-turbo-2.0.4/lib" install@gigabyte:~/build$ cd /opt/libjpeg62-turbo-2.0.4/ install@gigabyte:/opt/libjpeg62-turbo-2.0.4$ make test [...] install@gigabyte:~/build$ make install [ 8%] Built target simd [...] Install droidcam cli and v4l2 kernel module: -------------------------------------------- install@gigabyte:~/git$ git clone https://github.com/aramg/droidcam.git Cloning into 'droidcam'... remote: Enumerating objects: 66, done. remote: Counting objects: 100% (66/66), done. remote: Compressing objects: 100% (34/34), done. remote: Total 293 (delta 25), reused 45 (delta 19), pack-reused 227 Receiving objects: 100% (293/293), 1.19 MiB | 2.65 MiB/s, done. Resolving deltas: 100% (117/117), done. install@gigabyte:~/git$ Adapt install paths: install@gigabyte:~$ cd git/droidcam/ install@gigabyte:~/git/droidcam$ git diff diff --git a/linux/Makefile b/linux/Makefile index 134f723..541b06a 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -9,7 +9,8 @@ CC = -no-pie GTK = `pkg-config --libs --cflags gtk+-2.0` LIBS = `pkg-config --libs libswscale libavutil` -JPEG = -I/opt/libjpeg-turbo/include /opt/libjpeg-turbo/lib`getconf LONG_BIT`/libturbojpeg.a +#JPEG = -I/opt/libjpeg-turbo/include /opt/libjpeg-turbo/lib`getconf LONG_BIT`/libturbojpeg.a +JPEG = -I/opt/libjpeg-turbo/include /opt/libjpeg-turbo/lib/libturbojpeg.a SRC = src/connection.c src/decoder.c NO_WARN = -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast diff --git a/linux/install b/linux/install index 6189db5..a68db85 100755 --- a/linux/install +++ b/linux/install @@ -68,8 +68,8 @@ fi set -x cp "$V4L2_LOOPBACK_DIR/$V4L2_LOOPBACK_KO" $DRIVER_LOCATION -cp droidcam /usr/bin/ -cp droidcam-cli /usr/bin/ +cp droidcam /usr/local/bin/ +cp droidcam-cli /usr/local/bin/ set +x echo "Registering webcam device" diff --git a/linux/uninstall b/linux/uninstall index 9acc7b5..39c9344 100755 --- a/linux/uninstall +++ b/linux/uninstall @@ -4,7 +4,7 @@ echo "Un-loading driver module" sudo rmmod v4l2loopback_dc echo "Removing files" -sudo rm -f /usr/bin/droidcam* +sudo rm -f /usr/local/bin/droidcam* sudo rm -f /lib/modules/`uname -r`/kernel/drivers/media/video/v4l2loopback- dc.ko etc_modules() { install@gigabyte:~/git/droidcam$ install@gigabyte:~/git/droidcam$ cd linux/ install@gigabyte:~/git/droidcam/linux$ make gcc -Wall -no-pie -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast src/ droidcam.c src/connection.c src/decoder.c `pkg-config --libs --cflags gtk+-2.0` -I/opt/libjpeg-turbo/include /opt/libjpeg-turbo/lib/libturbojpeg.a `pkg-config --libs libswscale libavutil` -lm -o droidcam src/droidcam.c: In function ‘main’: src/droidcam.c:418:2: warning: ‘gdk_pixbuf_new_from_inline’ is deprecated [- Wdeprecated-declarations] gtk_window_set_icon(GTK_WINDOW(window), gdk_pixbuf_new_from_inline(-1, icon_inline, FALSE, NULL)); ^~~~~~~~~~~~~~~~~~~ In file included from /usr/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf.h:34, from /usr/include/gtk-2.0/gdk/gdkpixbuf.h:37, from /usr/include/gtk-2.0/gdk/gdkcairo.h:28, from /usr/include/gtk-2.0/gdk/gdk.h:33, from /usr/include/gtk-2.0/gtk/gtk.h:32, from src/droidcam.c:16: /usr/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-core.h:362:12: note: declared here GdkPixbuf* gdk_pixbuf_new_from_inline (gint data_length, ^~~~~~~~~~~~~~~~~~~~~~~~~~ install@gigabyte:~/git/droidcam/linux$ su - Password: root@gigabyte:~# cd /home/install/git/droidcam/linux/ root@gigabyte:/home/install/git/droidcam/linux# ./install 1920 1080 Webcam parameters: '1920' and '1080' Building v4l2loopback-dc.ko make: Entering directory '/home/install/git/droidcam/linux/v4l2loopback' make -C /lib/modules/`uname -r`/build M=`pwd` make[1]: Entering directory '/usr/src/linux-headers-5.4.0-0.bpo.4-amd64' AR /home/install/git/droidcam/linux/v4l2loopback/built-in.a CC [M] /home/install/git/droidcam/linux/v4l2loopback/v4l2loopback-dc.o Building modules, stage 2. MODPOST 1 modules CC [M] /home/install/git/droidcam/linux/v4l2loopback/v4l2loopback-dc.mod.o LD [M] /home/install/git/droidcam/linux/v4l2loopback/v4l2loopback-dc.ko make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-0.bpo.4-amd64' make: Leaving directory '/home/install/git/droidcam/linux/v4l2loopback' ./install: line 44: mokutil: command not found Moving driver and executable to system folders + cp v4l2loopback/v4l2loopback-dc.ko /lib/modules/5.4.0-0.bpo.4-amd64/kernel/ drivers/media/video/ + cp droidcam /usr/local/bin/ + cp droidcam-cli /usr/local/bin/ + set +x Registering webcam device Running depmod make: Entering directory '/home/install/git/droidcam/linux/v4l2loopback' make -C /lib/modules/`uname -r`/build M=`pwd` clean make[1]: Entering directory '/usr/src/linux-headers-5.4.0-0.bpo.4-amd64' CLEAN /home/install/git/droidcam/linux/v4l2loopback/Module.symvers make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-0.bpo.4-amd64' make: Leaving directory '/home/install/git/droidcam/linux/v4l2loopback' Adding uninstall script Adding driver to /etc/modules Done root@gigabyte:/home/install/git/droidcam/linux# Notes: ------ (default resolution is 640x480) -- the install script builds the kernel module, i.e. needs to rerun at every install ==> Test with guvcview To uninstall: # ./uninstall There is a pull request which uses dkms for building the kernel module On Android phone: - Install droidcam app on Android phone - Recommended: use usb cable for latency reasons - Run adb shell and allow computer access to phone - Exit adb shell again To run: - Start droidcam on phone - Run (for usb cable): droidcam-cli 127.0.0.1 4747 In case a DD read that far: certainly it would be a big plus if you can make a regular Debian package out of it , it seems to be little code, so hopefully the effort is limited. :-) -- Rainer Dorsch http://bokomoko.de/