G33K-TRICKS: Quick Guide to RTSP streaming related tools

Saturday, February 25, 2023

Quick Guide to RTSP streaming related tools



Quick Guide to RTSP streaming related Tools

Real-time streaming protocol (RTSP) has become increasingly popular in recent years, particularly in the world of online video streaming. As a result, it is more important than ever to understand how to use RTSP effectively to provide the best possible experience to your users.

One of the key benefits of RTSP is that it allows for real-time streaming of media, meaning that there is little to no buffering or lag time. This is particularly important for applications such as online gaming, live events, and video conferencing, where any delay can significantly impact the user experience.

guide to rtsp streaming related tools
To help you make the most of RTSP, we will explore three popular applications that are commonly used for sending and receiving RTSP streams: GStreamer, VLC, and FFmpeg for Linux.

GStreamer is an open-source multimedia framework that provides a modular approach to building media streaming applications. It is widely used in Linux-based systems and is particularly popular for its flexibility and scalability.

VLC is another popular media player that supports RTSP streaming and is available for Windows, Mac, and Linux. It is known for its versatility and ability to handle a wide range of media formats, making it a popular choice for both personal and professional use.

FFmpeg is a command-line tool that can be used for a wide range of media processing tasks, including RTSP streaming. It is particularly powerful and flexible, with a wide range of options and filters that can be used to customize the streaming experience.

Overall, understanding how to use RTSP and the tools available for streaming media is becoming increasingly important in the digital age. By taking the time to learn about GStreamer, VLC, FFmpeg, and other related technologies, you can ensure that your streaming applications provide the best possible experience to your users.


GStreamer

Installing GStreamer:

sudo apt install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-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 plugins:

# conda deactivate 

gst-inspect-1.0 -a

Play ~/Videos/test.mp4file :

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

Play /dev/video0webcam:

gst-launch-1.0 v4l2src device=/dev/video0\

!video/x-raw, format=YUY2, width=640, height=480, framerate=30/1 \

!autovideosink /dev/video0


GStreamer RTSP Server

Compile test-launchexample :

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)


test-launchSend RTSP test stream with:

$ ./test-launch "videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96" 

stream ready at rtsp://127.0.0.1:8554/test


gst-launch Receive RTSP test stream with:

gst-launch-1.0 playbin uri=rtsp://127.0.0.1:8554/test



Send RTSP totest-launch

Send ~/Videos/test.mp4file :

./test-launch "filesrc location=/home/user/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


VLC

To Install VLC
sudo snap install vlc

 # run below command to grant camera permission 
snap connect vlc:camera :camera 

To find available modules:
vlc --list

To Play ~/Videos/test.mp4file :
vlc file:///home/user/Videos/test.mp4

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

Send RTSP tovlc

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


Send /dev/video0webcam:
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

FFmpeg

To Install FFmpeg:

sudo apt install ffmpeg

Send RTSP to ffserver

Configuration ffserver.conf:

HTTPPort  8091 
HTTPBindAddress  0.0.0.0 
RTSPPort  1554 
MaxHTTPConnections  2000 
MaxClients  1000 
MaxBandwidth  1000 
CustomLog -

<Stream test.mp4> 
  File  "/home/user/Videos/test.mp4" 
  Format rtp
 </Stream>

To Start ffserver:

$ nohup ffserver -f ffserver.conf &

$ tail nohup.out
  libavcodec 57.107.100 / 57.107.100
  libavformat 57.83.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/user/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

$ sudo apt install ffmpeg

$ ffprobe ~/Videos/test.mp4
ffprobe version 3.4.8-0ubuntu0.2 Copyright (c) 2007-2020 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version=0ubuntu0.2 --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. 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
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/user/Videos/test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
  Duration: 00:10:22.04, start: 0.000000, bitrate: 4205 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080, 4204 kb/s, 25 fps, 25 tbr, 1200k tbn, 2400k tbc (default)
    Metadata:
      handler_name    : VideoHandler


No comments: