Skip to content

Instantly share code, notes, and snippets.

@babibn
Forked from edjdavid/file.md
Created January 4, 2024 11:25
Show Gist options
  • Save babibn/5635eb606eb0e1a7f29d9ae4e60df98e to your computer and use it in GitHub Desktop.
Save babibn/5635eb606eb0e1a7f29d9ae4e60df98e to your computer and use it in GitHub Desktop.
Stream Windows webcam/desktop via RTSP

Can be used for streaming data (webcam or screen capture) from the Windows to WSL

Install

  1. Simple RTSP Server
  2. ffmpeg

Get the internal IP of WSL

Run from a WSL terminal

ip route list default | awk '{print $3}'

RTSP Server

Start the simple rtsp server (in Windows) before running any of the ffmpeg commands

Webcam

All of the ffmpeg commands should be executed within the Windows environment. Add -hide_banner -loglevel error to any ffmpeg command to hide the log messages

View available devices (wiki)

ffmpeg -list_devices true -f dshow -i dummy

View available resolutions

ffmpeg -list_options true -f dshow -i video="Integrated Camera"

Stream from one of the available video devices (replace Integrated Camera with the video device name and <ip> with the IP address from the commands above)

ffmpeg -f dshow -i video="Integrated Camera" -framerate 30 -video_size 640x480 -f rtsp -rtsp_transport udp rtsp://<ip>:8554/webcam.h264

This stream can be opened on Python OpenCV from WSL (replace <ip>)

cv2.VideoCapture("rtsp://<ip>:8554/desktop.h264")

Desktop (screen capture)

Replace <ip> with the WSL IP

ffmpeg -f gdigrab -framerate 15 -i desktop -f h264 -f rtsp -rtsp_transport tcp rtsp://<ip>:8554/desktop.h264
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment