The Real-Time Streaming Protocol (RTSP) is an application layer Protocol designed for Streaming media. This article describes how to send and receive RTSP streams using GStreamer, VLC, and FFMPEG.

The premise

  • Ubuntu 18.04 LTS (Bionic Beaver)

GStreamer

Installation:

Sudo apt install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-bad Gstreamer1.0-x gstreamer1.0-alsa - Ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa - Ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa Gstreamer1.0 - gl gstreamer1.0 - gtk3 gstreamer1.0 - qt5 gstreamer1.0 - pulseaudio

View all plug-ins:

# conda deactivate gst-inspect-1.0-a

Play ~/Videos/test.mp4 file:

GST - launch - 1.0 filesrc location = ~ / Videos/test. The mp4! decodebin ! autovideosink

/dev/video0 webcam

Gst-launch -1.0v4l2src device=/dev/video0 \! video/x-raw, format=YUY2, width=640, height=480, framerate=30/1 \ ! autovideosink

For more information about /dev/video0, see “About Webcam” below.

GStreamer RTSP Server

Build test-launch example:

Sudo apt install libgstreamer1.0 - dev libgstrtspserver - 1.0 git clone https://github.com/GStreamer/gst-rtsp-server.git CD Gst-rtsp-server/git checkout 1.18 CD examples/ GCC test-launch. C-o test-launch $(pkg-config --cflags --libs Gstreamer -- RTSP server - 1.0)

Send RTSP test stream with test-launch:

$ ./test-launch "videotestsrc ! x264enc ! Rtph264pay name = pay0 pt = 96 "stream ready at RTSP: / / 127.0.0.1:8554 / test

Receive RTSP test stream with GST-launch:

GST - launch - 1.0 playbin uri = RTSP: / / 127.0.0.1:8554 / test

Send RTSP totest-launch

Send ~/Videos/test.mp4 file:

./test-launch "filesrc location=/home/john/Videos/test.mp4 ! decodebin ! x264enc ! rtph264pay name=pay0 pt=96"

Send /dev/video0 webcam:

./test-launch "v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,width=640,height=480 ! videoconvert ! x264enc ! rtph264pay name=pay0 pt=96"

Receive RTSP togst-launch

GST - launch - 1.0 playbin uri = RTSP: / / 127.0.0.1:8554 / test # or GST - launch - 1.0 RTSPSRC location = RTSP: / / 127.0.0.1:8554 / test! decodebin ! autovideosink

reference

  • GStreamer

    • Installing on Linux
    • Command line tools
    • Plugins
  • GStreamer RTSP Server
  • Stream webcam with GStreamer (RTSP)
  • x264 error: baseline profile doesn’t support 4:2:2

VLC

Installation:

sudo snap install vlc
# allow camera permission
snap connect vlc:camera :camera

To view the available modules:

vlc --list

Play ~/Videos/test.mp4 file:

vlc file:///home/john/Videos/test.mp4

/dev/video0 webcam

vlc v4l2:///dev/video0:chroma=mjpg:width=640:height=480:fps=30

Send RTSP tovlc

Send ~/Videos/test.mp4 file:

vlc file:///home/john/Videos/test.mp4 \
--sout '#transcode{vcodec=h264}:rtp{sdp=rtsp://:8554/test}'

Send /dev/video0 webcam:

vlc v4l2:///dev/video0:chroma=yuyv:width=640:height=480:fps=30 \
--sout '#transcode{vcodec=h264,width=640,height=480}:rtp{sdp=rtsp://:8554/test}'

Receive RTSP tovlc

VLC RTSP: / / 127.0.0.1:8554 / test

reference

  • VLC

    • Modules/file
    • Modules/v4l2
    • Streaming HowTo/Advanced Streaming Using the Command Line
    • Streaming HowTo/Command Line Examples
  • Ubuntu 18.04 Webcam streaming problem

FFmpeg

Installation:

sudo apt install ffmpeg

Send RTSP to FFSERVER

Configuration ffserver. Conf:

RTPPort 1554 MaxHttpConnections 2000 MaxClients 1000 MaxBandwidth 1000 CustomLog - <Stream test.mp4> File "/home/john/Videos/test.mp4" Format rtp </Stream>

Open ffserver:

$nohup ffserver.conf & $tail nohup.out libavcodec 57.107.100/57.107.100 libavformat 57.103.100/57. 83.100 libavDevice 57. 10.100/57. 10.100 libavFilter 6.107.100/6.107.100 libavresample 3.7.0/3.7.0 libswscale 4. 8.100/4. 8.100 libswresample 2.9.100/2. 9.100 libpostproc 54. 7.100/54. 7.100 Wed APR 21 11:28:39 2021 Opening  feed file '/home/john/Videos/test.mp4' for stream 'test.mp4' Wed Apr 21 11:28:39 2021 FFserver started.

Receive RTSP to FFPLAY

Ffplay RTSP: / / 127.0.0.1:1554 / test. Mp4

reference

  • FFmpeg

    • ffserver
  • Streaming RTSP with ffmpeg?
  • Run real time streaming with ffserver?

About the Media

$sudo apt install ffmpeg $ffprobe ~/Videos/test.mp4 ffprobe version 3.4.8-0ubuntu.2 Copyright (C) 2007-2020 the FFmpeg Developers Built with GCC 7 (Ubuntu 7.5.0-3Ubuntu 1~18.04) Configuration: -- prefix = / usr - extra - version = 0 ubuntu0. 2 - the toolchain = hardened - libdir = / usr/lib/x86_64 - Linux - gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 -- Enable -Chromaprint -- Enable -Frei0r -- Enable -LibOpenCv -- Enable -Libx264 -- Enable -Shared Libavutil 55.78.100/55. 78.100 libavcodec 57.107.100/57.107.100 libavformat 57.83.100/57.83.100 libavdevice 57.100/57.107.100 libavcodec 57.107.100/57.107.100 libavformat 57.83.100/57.83.100 libavdevice 57.100/57.10.100 LibavFilter 6.107.100/6.107.100 libavresample 3.7.0/3.7.0 libswscale 4.8.100/4.8.100 libswresample 2.9.100 / 2. 9.100 libpostproc 54. 7.100/54. 7.100 Input # 0, mov, mp4, : m4a, 3 gp, 3 g2, mj2, from '/ home/John/Videos/test. The mp4' : Metadata: major_brand: isom minor_version: 512 compatible_brands: isomiso2avc1mp41 encoder: Lavf58.20.100 Duration: compatible_brands: isomiso2avc1mp41 00:10:22.04, start: 0.000000, bitrate: 4205 KB /s Stream #0:0(und): Video: Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080, 4204 kb/s, 25 fps, 25 tbr, 1200k tbn, 2400k tbc (default) Metadata: handler_name : VideoHandler
  • ffprobe

On a Webcam

$sudo apt install v4l-utils $v4l2-ctl --list-devices HD Webcam: HD Webcam (USB-0000 :00:14.0-13): /dev/video0 /dev/video1 $ v4l2-ctl -d 0 --list-formats-ext ioctl: VIDIOC_ENUM_FMT Index : 0 Type : Video Capture Pixel Format: 'MJPG' (compressed) Name : Motion-JPEG Size: Discrete 640x480 Interval: Discrete 0.033s (3000fps) Size: Discrete 1280x720 Interval: Discrete 0.033s (3000fps) Size: Discrete 640x360 Interval: Discrete 0.033s (3000fps) Size: Discrete 352x288 Interval: Discrete 0.033s (30.000 FPS) Size: Discrete 320x240 Interval: Discrete 0.033s (30.000 FPS) Size: Discrete 176x144 Interval: Discrete 0.033s (30.000 FPS) Size: Discrete 160x120 Interval: Discrete 0.033s (30000 FPS) Index: 1 Type: Video Capture Pixel Format: 'YUYV' Name: YUYV 4:2:2 Size: Discrete 640x480 Interval: Discrete 0.033s (30.000 FPS) Interval: Discrete 0.050s (20.000 FPS) Size: Discrete 1280x720 Interval: Discrete 0.100s (10.000 FPS) Size: Discrete 640x360 Interval: Discrete 0.033s (30.000 FPS) Size: Discrete 352x288 Interval: Discrete 0.033s (30.000 FPS) Size: Discrete 320x240 Interval: Discrete 0.033s (3000fps) Size: Discrete 176x144 Interval: Discrete 0.033s (30.000 FPS) Size: Discrete 160x120 Interval: Discrete 0.033s (30.000 FPS)

Gocoding personal practice experience sharing, can pay attention to the public number!