Monday, September 6, 2021

How to quickly publish an RTSP stream from a webcam on Ubuntu

I wanted to quickly publish an RTSP video stream from a webcam on Linux without having to work with the complexity of sources and layers in OBS Studio. I found this neat software RtspSimpleServer downloadable from https://github.com/aler9/rtsp-simple-server

 For my testing purposes using just the default parameters, I did the following:

Install and run RtspSimpleServer

  1. Using a browser, download and extract the RtspSimpleServer binary from the github repo https://github.com/aler9/rtsp-simple-server into a folder, e.g. /path/to/rtsp/

    The files rtsp-simple-server and the rtsp-simple-server.yml are extracted out into a directory /path/to/rtsp/.

  2. Open up a Terminal. At the prompt, type in the cd command to change to the directory of the rtsp-simple-server.

    $ cd /path/to/rtsp/

  3. At the prompt, run the rtsp-simple-server server:

    $ ./rtsp-simple-server

    Process messages appear to show the server is running.



Publish a video stream

  1. Optional. If the video for linux utils are not installed, then run the apt command to install it.

    $ sudo apt install v4l-utils

  2. Open up a new Terminal. Type in the ffmpeg command to publish the stream from the webcam device (assuming /dev/video0).

    $ ffmpeg \
    -f v4l2 \
    -framerate 90 \
    -re -stream_loop -1 \
    -video_size 640x320 \
    -input_format mjpeg \
    -i /dev/video0 \
    -c copy \
    -f rtsp \
    rtsp://localhost:8554/mystream




    Processing messages appear.


     

Open the stream with a VLC client

  1. Open up a new Terminal.

     
  2. Run the vlc command to open the published stream.

    $ vlc rtsp://localhost:8554/mystream



    The VLC client pops up to show the RTSP stream from the webcam.