Skip to content

Instantly share code, notes, and snippets.

@edjdavid
Created October 13, 2022 12:45
Show Gist options
  • Save edjdavid/513cbee3f9a10cd06e9e49e8bdfa0f96 to your computer and use it in GitHub Desktop.
Save edjdavid/513cbee3f9a10cd06e9e49e8bdfa0f96 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