Overview
Currently, I am using scrcpy with v4l2loopback (Option 7) for the easiest and most performant way. It works with both a USB cable or over WiFi. Before that I was using gstreamer mpeg with IP Webcam android app. However gstreamer v42loopback broke with modern Ubuntu. All other options I tested had too much delay. I will be testing Android 14’s latest USB webcam option soon.
If you want to use OBS Read my previous article to install obs: jphein.com/how-to-instal…
Preparation for Options 1-5
I will be using the free Android app called IP webcam. www.google.com/url?sa=t&…
1. Start and configure IP webcam. Run the server.
You can use either USB or Wi-Fi. My Wi-Fi is rather slow, so I’ll be using a USB cable to connect my Android phone to my Ubuntu computer.
2. The second step is to plug your phone into your computer using the USB micro or USB C cable. Then turn on USB tethering on your phone.
NOTE: Some unrooted phones do not allow you to turn on USB tethering if your current ISP does not allow it. If that is the case, you can adb port forwarding instead with this command: (USB debugging must be turned on in Developer settings.
adb forward tcp:8080 tcp:8080
If you use port forwarding instead of USB tethering, or Wifi then your url portion of your uri will be localhost instead of the IP address of the phone.
Option 1 – Use built-in OBS Media Source
The delay is too great for me…
Option 2 – VLC
An easy way is by using VLC, but it seems to also create a delay on my machine. Does anyone have suggestions?
sudo apt --yes install vlc
Then add a VLC media source in OBS, Click the small “+” sign, and “Add Path/URL” then paste your IP Webcam url. See below examples:
MPEG
http://192.168.42.129:8080/videofeed
ULAW (This no longer works for me)
rtsp://192.168.42.129:8080/h264-ulaw.sdp
PCM (This no longer works for me)
rtsp://192.168.42.129:8080/h264-pcm.sdp
Option 3 – Gstreamer with OBS gstreamer plugin
UPDATE: The OBS Snap now includes the gstreamer plugin! It seems to work better than before.
I noticed someone has made a Gstreamer plugin for OBS.
In order to use this you’ll need to use the PPA version and not the Snap version.
Install OBS using PPA:
launchpad.net/~obsprojec…Download the .so file from obsproject.com/forum/res… and install in /usr/lib/obs-plugins/Add source “gstreamer source” in OBS.
Enter the gstreamer command in the gstreamer input box:
MPEG
souphttpsrc location="http://192.168.42.129:8080/videofeed" do-timestamp=true is-live=true ! multipartdemux ! jpegdec ! videoconvert ! video.
H264 (I can’t get this to work anymore)
uridecodebin uri=rtsp://192.168.42.129:8080/h264_ulaw.sdp name=bin ! queue ! video. bin. ! queue ! audio.
maybe this?
rtspsrc location="rtsp://localhost:8080/h264_opus.sdp" protocols=tcp latency=0 onvif-rate-control=false is-live=true name=bin \
bin. ! queue ! rtph264depay ! h264parse ! vaapih264dec ! videoconvert ! video. \
bin. ! queue ! rtpopusdepay ! opusparse ! opusdec ! audioconvert ! audio.
H264 seems to have more delay. MPEG seems to have less delay:
Option 4 – Gstreamer with v4l2loopback
This is my favorite way. Gstreamer seems to have less delay then the OBS media plugin, VLC, or even ffmpeg. The loopback is sweet, because it let’s you treat your phone just like any other v4l2 device, like a UVC webcam. That way you can use it as a cam for Google Meet, Duo, etc…
Make sure you have gestreamer plugins installed:
sudo apt --yes install gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-plugins-rtp gstreamer1.0-vaapi
You can test to make sure that gstreamer connects with the IP webcam from your Android phone by issuing the below command.
gst-launch-1.0 souphttpsrc location="http://192.168.42.129:8080/videofeed" do-timestamp=true is-live=true ! multipartdemux ! jpegdec ! videoconvert ! ximagesink
Install v4loopback
sudo apt install --yes v4l2loopback-utils sudo modprobe v4l2loopback
Create the virtual webcam
This seems to work with the MPEG stream:
gst-launch-1.0 souphttpsrc location="http://192.168.42.129:8080/videofeed" do-timestamp=true is-live=true ! multipartdemux ! jpegdec ! videoconvert ! v4l2sink device="/dev/video2"
I can’t get this one to work yet.
gst-launch-1.0 souphttpsrc location="http://192.168.42.129:8080/videofeed" do-timestamp=true is-live=true \
! multipartdemux \
! decodebin3 \
! videoconvert \
! videoscale \
! videorate \
! video/x-raw,format=YUY2,width=640,height=480,framerate=24/1 \
! v4l2sink device="/dev/video2"
I wonder how you would receive the IP Webcam H264 stream with gstreamer? maybe:
`gst-launch-1.0 rtspsrc location='rtsp://192.168.42.129:8080/h264-ulaw.sdp' ! rtph264depay ! h264parse ! avdec_h264 ! v4l2sink device="/dev/video2"`
maybe this?
rtspsrc location="rtsp://localhost:8080/h264_opus.sdp" protocols=tcp latency=0 onvif-rate-control=false is-live=true name=bin \
bin. ! queue ! rtph264depay ! h264parse ! vaapih264dec ! videoconvert ! video. \
bin. ! queue ! rtpopusdepay ! opusparse ! opusdec ! audioconvert ! audio.
Use the output of OBS as a virtual webcam
NOTE: The v42lsink is now inlcuded in OBS! It’s called Start Virtual Camera, and will appear after you install v42loopback.
If you want more than one Android phone streaming to your computer using the loop-back method. You’ll have to reload the loopback mosudo modprobe v4l2loopback devices=1 video_nr=10 card_label=”OBS Cam” exclusive_caps=1dule inter kernel with a variable telling it how many loopback devices to make. For two, use the commands below:
sudo modprobe -r v4l2loopback
sudo modprobe v4l2loopback devices=2
NOTE: All this needs to be done before you add the Video Capture Device (V4L2) in OBS. If you make any changes to the video stream after you add the source, you will need to remove the source or close OBS in order to create the loopback again.
I had to use this command to get it to work with Google meet:
sudo modprobe -r v4l2loopback
sudo modprobe v4l2loopback devices=1 video_nr=10 card_label="OBS Cam" exclusive_caps=1
Option 5 – using ffmpeg
ffmpeg -i http://127.0.0.1:8080/video -vf format=yuv420p -f v4l2 /dev/video0
Option 6 – using vdo.ninja
Another option is to use the 3rd party service vdo.ninja. Then add the url as a browser source to OBS.
Option 7 – using scrcpy
Install latest version: github.com/Genymobile/sc…
optional enable wireless adb on your android phone:
plug phone into computer with usb cable and then run:
adb tcpip 5555
Add loopback device:
sudo modprobe v4l2loopback devices=1 video_nr=10 card_label="scrcpy" exclusive_caps=1
Configure camera: github.com/Genymobile/sc…
For example:
scrcpy --video-source=camera --camera-id=1 --camera-size=1920x1080 --camera-fps=60 --tcpip=10.0.6.105 --v4l2-sink=/dev/video10 --no-playback
Further Reading
Arch wiki has some good ideas: wiki.archlinux.org/title…
Learn more about Gstreamer, and rtspatt here: medium.com/nutanix-iot/t…
For automated script for Ubuntu from the “IP Webcam” developer see here: (Uses adb port forwarding, gstreamer, and v42loopback) github.com/bluezio/ipweb…
The blog that has the working mpeg gstreamer command I used: cubethethird.wordpress.c…
ustreamer: If you want to do this with a raspberry pi, or other linux computer with a webcam, instead of an android phone: github.com/pikvm/ustream…
iPhone and Windows
For iPhone see: obsproject.com/forum/res… or apps.apple.com/us/app/nd…
For Windows see here: ip-webcam.appspot.com/