Skip to content

Instantly share code, notes, and snippets.

@santiagovdk
Forked from neilyoung/receipt4.md
Last active February 9, 2023 20:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santiagovdk/80c378a315722a1b813ae5da1661f890 to your computer and use it in GitHub Desktop.
Save santiagovdk/80c378a315722a1b813ae5da1661f890 to your computer and use it in GitHub Desktop.
How to make an Ubuntu 18.04 an RTSP streamer and how to consume that?

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

Prerequisites

Using a fresh Ubuntu 18.04 server install you may need to enable ssh.

sudo apt update
sudo apt upgrade
sudo ufw allow ssh

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
sudo apt install libssl-dev
sudo apt-get install libx264-devw
sudo apt install libffi-dev libssl-dev
sudo apt-get install python3
sudo apt-get install python3-pip

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

  1. Download & follow order

    1. gstreamer https://gstreamer.freedesktop.org/src/gstreamer/gstreamer-1.16.2.tar.xz
    2. gst-plugins-base https://gstreamer.freedesktop.org/src/gst-plugins-base/gst-plugins-base-1.16.2.tar.xz
    3. gst-plugins-good https://gstreamer.freedesktop.org/src/gst-plugins-good/gst-plugins-good-1.16.2.tar.xz
    4. gst-plugins-bad https://gstreamer.freedesktop.org/src/gst-plugins-bad/gst-plugins-bad-1.16.2.tar.xz
    5. gst-plugins-ugly https://gstreamer.freedesktop.org/src/gst-plugins-ugly/gst-plugins-ugly-1.16.2.tar.xz
    6. gst-libav https://gstreamer.freedesktop.org/src/gst-libav/gst-libav-1.16.2.tar.xz
    7. gst-rtsp-server https://gstreamer.freedesktop.org/src/gst-rtsp/gst-rtsp-server-1.16.2.tar.xz
  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.16.2/examples

Running a test image

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

Using /dev/video0 and H.264 software encoder Use VLC lo check the RTSP feed.

Install docker

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER

sudo pip3 install docker-compose
./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
@gusarg81
Copy link

Hi,

I am currently using Ubuntu 20.04, gstreamer 1.16.2. When I consume the rtsp server from linux (running also the rtsp-server in another machine with Realtek Semiconductor Corp. HK 2M CAM USB, also Ubuntu 20.04), I got:

./test-launch --gst-debug=3 '( v4l2src device=/dev/video0 ! video/x-raw,width=1920,height=1080,framerate=30/1 ! x264enc tune="zerolatency" byte-stream=true bitrate=2000 ! rtph264pay name=pay0 pt=96 )'
stream ready at rtsp://127.0.0.1:8554/test
0:00:38.884082723 87255 0x7f656c00c460 WARN basesrc gstbasesrc.c:3072:gst_base_src_loop: error: Internal data stream error.
0:00:38.884126825 87255 0x7f656c00c460 WARN basesrc gstbasesrc.c:3072:gst_base_src_loop: error: streaming stopped, reason not-negotiated (-4)
0:00:38.884226999 87255 0x7f6574003460 WARN rtspmedia rtsp-media.c:3001:default_handle_message: 0x7f657403f220: got error Internal data stream error. (gstbasesrc.c(3072): gst_base_src_loop (): /GstPipeline:media-pipeline/GstBin:bin0/GstV4l2Src:v4l2src0:
streaming stopped, reason not-negotiated (-4))
0:00:38.884283568 87255 0x55c1c690f860 WARN rtspmedia rtsp-media.c:3272:wait_preroll: failed to preroll pipeline
0:00:38.884298256 87255 0x55c1c690f860 WARN rtspmedia rtsp-media.c:3652:gst_rtsp_media_prepare: failed to preroll pipeline
0:00:38.885428257 87255 0x55c1c690f860 ERROR rtspclient rtsp-client.c:1077:find_media: client 0x55c1c6900e20: can't prepare media
0:00:38.885702712 87255 0x55c1c690f860 ERROR rtspclient rtsp-client.c:2963:handle_describe_request: client 0x55c1c6900e20: no media

0:00:49.109923321 87255 0x7f6574003ea0 WARN basesrc gstbasesrc.c:3072:gst_base_src_loop: error: Internal data stream error.
0:00:49.109953463 87255 0x7f6574003ea0 WARN basesrc gstbasesrc.c:3072:gst_base_src_loop: error: streaming stopped, reason not-negotiated (-4)
0:00:49.110034939 87255 0x7f6574003cc0 WARN rtspmedia rtsp-media.c:3001:default_handle_message: 0x7f6570016230: got error Internal data stream error. (gstbasesrc.c(3072): gst_base_src_loop (): /GstPipeline:media-pipeline/GstBin:bin1/GstV4l2Src:v4l2src1:
streaming stopped, reason not-negotiated (-4))
0:00:49.110105850 87255 0x7f656c00c460 WARN rtspmedia rtsp-media.c:3272:wait_preroll: failed to preroll pipeline
0:00:49.110119862 87255 0x7f656c00c460 WARN rtspmedia rtsp-media.c:3652:gst_rtsp_media_prepare: failed to preroll pipeline
0:00:49.111010972 87255 0x7f656c00c460 ERROR rtspclient rtsp-client.c:1077:find_media: client 0x55c1c6900f50: can't prepare media
0:00:49.111278152 87255 0x7f656c00c460 ERROR rtspclient rtsp-client.c:2963:handle_describe_request: client 0x55c1c6900f50: no media

Any ideas?

Thanks.

@idoudika
Copy link

Hello,
Try to compile gst-plugins-bad1.16.2 from sources returns the error on Ubuntu 18.04 . Any ideas ?

make[3]: Entering directory '/home/kaleido/Documents/MobyRTSP/doc/gst-plugins-bad-1.16.2/sys/nvdec'
CC libgstnvdec_la-gstnvdec.lo
In file included from nvcuvid.h:38:0,
from gstnvdec.h:33,
from gstnvdec.c:32:
cuviddec.h:39:10: fatal error: cuda.h: No such file or directory
#include <cuda.h>
^~~~~~~~
compilation terminated.
Makefile:875: recipe for target 'libgstnvdec_la-gstnvdec.lo' failed
make[3]: *** [libgstnvdec_la-gstnvdec.lo] Error 1

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