I wanted to view my webcam feed from a browser on my local network. This turns out to be useful for testing video conferencing setups, monitoring a room, or checking camera angles before a recording. The challenge is that browsers can’t directly access webcam RTSP streams, but they do support WebRTC.
After some tinkering, I found a clean solution: ffmpeg captures the webcam and streams it via RTSP, while MediaMTX converts that RTSP feed to WebRTC that browsers can consume.
Installation
| |
Setup
You need to run two processes in parallel.
1. Start MediaMTX server
| |
This starts the MediaMTX server which will handle the protocol conversion and serve the web interface.
2. Stream webcam with ffmpeg
In a separate terminal:
| |
The -f avfoundation flag is macOS-specific for capturing video devices. On Linux, you’d use -f v4l2 instead. The "0" refers to the first video device (your default webcam). The ultrafast preset and zerolatency tuning minimize encoding overhead for real-time streaming.
Viewing the Stream
Once both processes are running, open your browser and navigate to:
| |
The feed should appear in your browser. You can access this URL from any device on your local network by replacing 127.0.0.1 with your machine’s IP address.
MediaMTX handles all the WebRTC negotiation and serves a basic web player interface. If you need to customize the player or embed it elsewhere, MediaMTX also exposes a WebRTC API you can integrate with.
