Skip to main content

Cross-platform RTSP H.264 webcam streamer using GStreamer

Project description

webcam2rtsp

webcam2rtsp streams a local laptop or USB webcam over RTSP using Python and GStreamer. It supports Linux, macOS, and Windows when the matching GStreamer camera source plugin is installed.

Default stream URL:

rtsp://<computer-ip>:8854/webcam1

Features

  • RTSP server with configurable bind address, port, and mount path
  • Platform defaults for Linux, macOS, and Windows webcams
  • Configurable camera device, resolution, framerate, and H.264 bitrate
  • Custom GStreamer source support for unusual camera drivers
  • Compatible with VLC, FFplay, and other RTSP clients

Install GStreamer

macOS

brew install gstreamer gst-plugins-base gst-plugins-good gst-libav gst-plugins-bad gst-plugins-ugly pygobject3

If Python cannot find the GStreamer libraries, export these variables:

webcam2rtsp --print-env

The command detects /opt/homebrew on Apple Silicon Macs and /usr/local on Intel Macs. It prints values like PATH, DYLD_LIBRARY_PATH, GI_TYPELIB_PATH, GST_PLUGIN_PATH, and GST_PLUGIN_SYSTEM_PATH_1_0 only when those paths exist.

Linux

Debian/Ubuntu:

sudo apt update
sudo apt install -y python3-gi python3-gst-1.0 gir1.2-gst-rtsp-server-1.0 \
  gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
  gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly

Fedora:

sudo dnf install -y python3-gobject gstreamer1 gstreamer1-plugins-base \
  gstreamer1-plugins-good gstreamer1-plugins-bad-free gstreamer1-plugins-ugly \
  gstreamer1-rtsp-server

Windows

PyGObject usually does not install from normal PyPI on Windows. If you see No module named gi or Could not find a version that satisfies the requirement PyGObject, do not keep retrying pip install PyGObject.

Recommended Windows setup:

  1. Install MSYS2 from:
https://www.msys2.org/
  1. Open the MSYS2 UCRT64 shell.

  2. Install Python, PyGObject, GStreamer, plugins, and RTSP server bindings:

pacman -S --needed mingw-w64-ucrt-x86_64-python mingw-w64-ucrt-x86_64-python-gobject mingw-w64-ucrt-x86_64-gstreamer mingw-w64-ucrt-x86_64-gst-plugins-base mingw-w64-ucrt-x86_64-gst-plugins-good mingw-w64-ucrt-x86_64-gst-plugins-bad mingw-w64-ucrt-x86_64-gst-plugins-ugly mingw-w64-ucrt-x86_64-gst-libav mingw-w64-ucrt-x86_64-gst-rtsp-server
  1. Install webcam2rtsp using the MSYS2 Python:
python -m pip install webcam2rtsp
webcam2rtsp-doctor

Install webcam2rtsp

After installing GStreamer for your operating system:

python -m pip install webcam2rtsp

If you want pip to also try installing the Python PyGObject binding on macOS or Linux, use the optional extra:

python -m pip install "webcam2rtsp[pygobject]"

For Debian/Ubuntu virtual environments that use python3-gi from apt, create the environment with system packages visible:

python3 -m venv --system-site-packages .venv
source .venv/bin/activate
python -m pip install webcam2rtsp

Verify the native GStreamer setup:

webcam2rtsp-doctor

On macOS and Windows, webcam2rtsp automatically detects common GStreamer install paths before importing PyGObject. If your shell still needs the same values permanently, print them with:

webcam2rtsp --print-env

Then add the printed lines to your shell profile, such as ~/.zshrc on macOS.

For local development from this repository:

git clone https://github.com/CosminBMemetea/webcam2rtsp.git
cd webcam2rtsp
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install -e .

On Debian/Ubuntu, prefer this venv command when using python3-gi from apt:

python3 -m venv --system-site-packages venv

requirements.txt is intentionally empty for runtime dependencies. The gi module comes from native PyGObject packages installed through Homebrew, apt, dnf, pacman, or another operating-system package manager.

Local development can run the same checks with:

python -m webcam2rtsp --doctor
python -m webcam2rtsp --print-env

Run

Use the default webcam:

python -m webcam2rtsp

Open the stream from another machine on the same network:

rtsp://<computer-ip>:8854/webcam1

Local test with FFplay:

ffplay rtsp://127.0.0.1:8854/webcam1

Configuration

python -m webcam2rtsp \
  --address 0.0.0.0 \
  --port 8554 \
  --mount-point /camera \
  --device /dev/video2 \
  --width 1280 \
  --height 720 \
  --framerate 30 \
  --bitrate 2500

Device examples:

# Linux
python -m webcam2rtsp --device /dev/video0

# macOS
python -m webcam2rtsp --device 0

# Windows
python -m webcam2rtsp --device 0

Use a custom GStreamer source when the default source is not right for your camera:

python -m webcam2rtsp --source "autovideosrc"
python -m webcam2rtsp --source "dshowvideosrc device-name=\"Integrated Camera\""

Available options:

python -m webcam2rtsp --help

Publish to PyPI

Build the package:

python -m pip install --upgrade build twine
python -m build

Check the package metadata:

python -m twine check dist/*

Upload to TestPyPI first:

python -m twine upload --repository testpypi dist/*

Upload to PyPI when the TestPyPI package installs correctly:

python -m twine upload dist/*

Platform Defaults

  • Linux: v4l2src device="/dev/video0"
  • macOS: avfvideosrc device-index=0
  • Windows: mfvideosrc device-index=0

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

webcam2rtsp-0.1.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

webcam2rtsp-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file webcam2rtsp-0.1.0.tar.gz.

File metadata

  • Download URL: webcam2rtsp-0.1.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for webcam2rtsp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 39bffedbabad9a7f304d044b83c7b5636096f5ab0418792713379bc3d085cbb1
MD5 a4b8bb5b7e5df88bee2482745ca3ebf6
BLAKE2b-256 41d25478cf19fd637ab2a9bbe848b02f30e88ce4299740151634574cb1d5598b

See more details on using hashes here.

File details

Details for the file webcam2rtsp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: webcam2rtsp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for webcam2rtsp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54b635c0e88a66537dd377b8bc02a3afa4e442084dec91b33bfad3d7b87ea604
MD5 ce90b92bf650090ef44ba3de7d49ec2b
BLAKE2b-256 71d667d926719f4dbb91f2671f74bcc344bad7fb6e6fdadcc7ee9f646da684e3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page