Konubinix' opinionated web of thoughts

Go2rtc to Use an Android Device as Webcam

Fleeting

My precious attempt at using aiortc to create a remote web camera with an android phone works well, but needs some annoying setup.

I just discovered go2rtc that supposedly does the same with (almost) no extra code required.

Let’s give it a try.

By looking at the code, I can see that it

  1. uses (hardcoded) stun:stun.l.google.com:19302 as signaling (and STUN) server,
  2. does not provide options to customize the video format, size etc,
  3. only provides the front camera,
  4. does not provide a way to hide the video from the device (I want this to mitigate the battery drain),

First, I will try it on my running android 11.

I can simply install it with nix, create this default configuration in go2rtc.yaml

streams:
  browser_cam: null

Then:

  1. open http://localhost:1984/webrtc.html?dst=browser_cam&media=camera+microphone
    1. media can be a combination of camera/display+speaker/microphone
  2. on my desktop, run ffmpeg -i "rtsp://${PHONE_NAME}:8554/browser_cam" -c:v libvpx -b:v 2M output.webm to save the stream

So far so good.

Now, I want to try it on my running on android 5.

won’t install on it, but does.

I downloaded the arm build, but could run it only using su.

I could open http://localhost:1984/webrtc.html?dst=browser_cam&media=camera+microphone, but the ffmpeg command complained that the stream was not found.

I could insist and try to run gp2rtc on my desktop instead. Because the web media api requires web secure contexts, I have to,

  1. either use https with self signed certificates and install the public key in my phone,
  2. or add a proxy for localhost to redirect to the desktop.

Because go2rtc is clearly not fit for my use cases, I won’t get into that rabbit hole.