Skip to content

Instantly share code, notes, and snippets.

@neilyoung
Last active February 24, 2024 18:56
Show Gist options
  • Save neilyoung/38ed9139fdb9396c8998bd1b4464d833 to your computer and use it in GitHub Desktop.
Save neilyoung/38ed9139fdb9396c8998bd1b4464d833 to your computer and use it in GitHub Desktop.
How to make an Ubuntu 16.04 an RTSP streamer and how to consume that?

How to make an Ubuntu 16.04 an RTSP streamer and how to consume that?

Prerequisites

It is recommended to to the following steps in a new VM in order to not accidently mess up an existing installation!

sudo apt-get install build-essential
sudo apt-get install bison
sudo apt-get install flex
sudo apt-get install libglib2.0-dev

Get the required GStreamer sources from https://gstreamer.freedesktop.org/src/. Focus on version 1.14.2

  1. Download

  2. Unpack tar.xz files

tar -xf <filename>
  1. Change into each of the unpacked dirs
  2. Execute these commands in each directory
./configure
make
sudo make install
  1. Change into gst-rtsp-server-1.14.2/examples
  2. Attach a webcam via USB, make sure to have /dev/video0 (or change to whatever is there)
ls /dev/video*
  1. Run server command

Running a test image

./test-launch --gst-debug=3 '( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )'

Using /dev/video0 and H.264 software encoder

./test-launch  --gst-debug=3 '( v4l2src device=/dev/video0 ! video/x-raw,width=640,height=480,framerate=30/1 ! x264enc tune="zerolatency" byte-stream=true bitrate=2000 ! rtph264pay name=pay0 pt=96 )'

If your camera exposes H.264 directly (ways less CPU power required)

./test-launch  --gst-debug=0 '( v4l2src device=/dev/video0 ! video/x-h264,width=640,height=480,framerate=30/1 ! h264parse ! rtph264pay name=pay0 pt=96 )'

Consume the stream on a Mac, replace ip-of-rtsp-server by the real IP (GStreamer installation required)

/Library/Frameworks/GStreamer.framework/Commands/gst-launch-1.0 -v rtspsrc location=rtsp://<ip-of-rtsp-server>:8554/test latency=0 buffer-mode=auto ! decodebin ! videoconvert ! osxvideosink sync=false

Consume on a Linux system, replace ip-of-rtsp-server by the real IP (GStreamer installation required)

gst-launch-1.0 -v rtspsrc location=rtsp://<ip-of-rtsp-server>:8554/test latency=0 buffer-mode=auto ! decodebin ! videoconvert ! autovideosink sync=false
@SreekanthTeja
Copy link

Can you tell me, if this works for you on the server side? It works here and produces a test video.
./test-launch --gst-debug=3 '( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )'
So here at least the client pipeline is correct. The problem is the camera control.

I get this error bash: ./test-launch: No such file or directory

Hi.. I am unable to view the video showing error while running the command " gst-launch-1.0 -v rtspsrc location=rtsp://:8554/test latency=0 buffer-mode=auto ! decodebin ! videoconvert ! autovideosink sync=false" ----------------------------ERROR--------------------------------------------------- Setting pipeline to PAUSED ... Pipeline is live and does not need PREROLL ... Progress: (open) Opening Stream Progress: (connect) Connecting to rtsp://127.0.0.1:8554/test Progress: (open) Retrieving server options Progress: (open) Retrieving media info ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: Could not read from resource. Additional debug info: gstrtspsrc.c(5670): gst_rtspsrc_send (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: Got error response: 503 (Service Unavailable). ERROR: pipeline doesn't want to preroll. Setting pipeline to PAUSED ... Setting pipeline to READY ... Setting pipeline to NULL ... Freeing pipeline ...

Try these steps:
$ cd gst-rtsp-server-1.14.2/examples
$ ./test-launch --gst-debug=3 '( v4l2src device=/dev/video0 ! video/x-raw,width=640,height=480,framerate=30/1 ! x264enc tune="zerolatency" byte-stream=true bitrate=2000 ! rtph264pay name=pay0 pt=96 )'

rtsp://127.0.0.1:8554/test
Now open new tab and replace rtsp ip in bellow command
$ gst-launch-1.0 rtspsrc location='rtsp://127.0.0.1:8554/test' der=TRUE ! rtph264depay ! video/x-h264, width=640,height=480,framerate=15/1, format=avc,alignment=au ! kvssink stream-name="test1" storage-size=512 access-key=ATR secret-key=huB****52q2 aws-region=us-east-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment