Go2rtc to Use an Android Device as Webcam
FleetingMy 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
- uses (hardcoded) stun:stun.l.google.com:19302 as signaling (and STUN) server,
- does not provide options to customize the video format, size etc,
- only provides the front camera,
- 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
I can simply install it with nix, create this default configuration in
go2rtc.yaml
streams:
browser_cam: null
Then:
- open http://localhost:1984/webrtc.html?dst=browser_cam&media=camera+microphone
- media can be a combination of camera/display+speaker/microphone
- 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
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,
- either use https with self signed certificates and install the public key in my phone,
- 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.