RTSP Streaming
Requirements
- compatible camera
- If you use ROCK 5B, you can also use HDMI RX as the video source.
Server Configuration
- Based on FFmpeg
- Based on Gstreamer + mediamtx
- Based Gstreamer + gst-rtsp-server
When using HDMI RX, input sources with lower than 720P resolution may cause encoding failure.
After testing, ffmpeg-rockchip is not compatible with the rkmpp and librga versions we released for Debian 11 systems, Debian 12 systems are not affected.
If you are using our Debian 11 system, please go to ffmpeg-rockchip official build tutorial , build rkmpp and librga and then build ffmpeg-rockchip,
and run sudo apt-get update && sudo apt-get install librga2=2.2.0-1
。
Installation of compilation dependencies
sudo apt-get update
sudo apt-get install build-essential cmake git libdrm-dev librga-dev librockchip-mpp-dev libsdl2*-dev libx264-dev libx265-dev pkg-config
Compile and install ffmpeg-rockchip
git clone https://github.com/nyanmisaka/ffmpeg-rockchip
pushd ffmpeg-rockchip/
./configure --prefix=/usr --enable-gpl --enable-version3 --enable-libdrm --enable-rkmpp --enable-rkrga --enable-libx264 --enable-libx265 --enable-ffplay
make -j$(nproc)
sudo make install
popd
Running mediamtx and ffmpeg-rockchip
Here we assume that /dev/video-camera0
is the video source you want to use. If your camera is assigned a different name, replace the corresponding device name in the following command line.
-vf “fps=30”
and -s 3840x2160
correspond to the frame rate and resolution respectively, which need to be adjusted according to the output of the command sudo v4l2-ctl -d /dev/video-camera0 --all
, or else the encoding performance will be affected or even the startup of the push stream will fail due to the failure of reading the camera information automatically.
The -c:v
option specifies the encoder to be used, currently ffmpeg-rockchip supports h264_rkmpp
, hevc_rkmpp
and mjpeg_rkmpp
hardware encoders.
wget https://github.com/bluenviron/mediamtx/releases/download/v1.9.0/mediamtx_v1.9.0_linux_arm64v8.tar.gz
tar -xzvf mediamtx_v1.9.0_linux_arm64v8.tar.gz
nohup ./mediamtx &
ffmpeg-rockchip/ffmpeg -f v4l2 -i /dev/video-camera0 -vf "fps=30" -s 3840x2160 -c:v h264_rkmpp -rc_mode AVBR -b:v 20M -minrate 10M -maxrate 40M -profile:v main -level 5.1 -f rtsp rtsp://0.0.0.0:8554/stream
# If you only want to record the camera to a file, use the following command
# ffmpeg-rockchip/ffmpeg -f v4l2 -i /dev/video-camera0 -vf "fps=30" -s 3840x2160 -c:v h264_rkmpp -rc_mode AVBR -b:v 20M -minrate 10M -maxrate 40M -profile:v main -level 5.1 /tmp/tmp.mp4
Because mpph264enc is poorly encoded and decoded by Radxa OS in Rockchip 6.1 Linux kernel, it is recommended to use mpph265enc in preference.
When using HDMI RX, gst-mppenc does not support NV24(YCbCr444) and RGB input, you need to switch the color format of HDMI input to NV12(YCbCr420) or NV16(YCbCr422), or use FFmpeg to push the stream,
and run sudo apt-get update && sudo apt-get install librga2=2.2.0-1
.
Installation dependencies
sudo apt-get update
sudo apt-get install gstreamer1.0-rtsp
Running mediamtx and Gstreamer
Here we assume that /dev/video-camera0
is the video source you want to use. If your camera is assigned a different name, replace the corresponding device name in the following command line.
wget https://github.com/bluenviron/mediamtx/releases/download/v1.9.0/mediamtx_v1.9.0_linux_arm64v8.tar.gz
tar -xzvf mediamtx_v1.9.0_linux_arm64v8.tar.gz
nohup ./mediamtx &
# mpph264enc encoder currently has lagging problem under Rockchip 6.1 Linux kernel, we suggest to use mpph265enc encoder.
# mpph264enc, mpph265enc, mppjpegenc, mppvp8enc encoders are available. To change the encoder, you need to change the rtp*pay or *parse in the pipeline.
gst-launch-1.0 -v v4l2src device=/dev/video-camera0 ! queue ! mpph265enc bps=51200000 rc-mode=vbr ! rtspclientsink location=rtsp://localhost:8554/test
# If you only want to record the camera to a file, use the following command
# gst-launch-1.0 --gst-debug-level=3 v4l2src device=/dev/video-camera0 ! queue ! mpph265enc bps=51200000 rc-mode=vbr ! h265parse ! mp4mux ! filesink location=output.mp4
Because mpph264enc is poorly encoded and decoded by Radxa OS in Rockchip 6.1 Linux kernel, it is recommended to use mpph265enc in preference.
When using HDMI RX, gst-mppenc does not support NV24(YCbCr444) and RGB input, you need to switch the color format of HDMI input to NV12(YCbCr420) or NV16(YCbCr422), or use FFmpeg to push the stream.
Installation of compilation dependencies
sudo apt update
sudo apt install build-essential gobject-introspection libcgroup-dev libgirepository1.0-dev libgstreamer-plugins-bad1.0-dev libgstreamer-plugins-base1.0-dev meson librga-dev
Get gst-rtsp-server source code
git clone https://gitlab.freedesktop.org/gstreamer/gstreamer.git
cd gstreamer/subprojects/gst-rtsp-server
# Check the version number of gstreamer-rtsp-1.0 on your system.
pkg-config --modversion gstreamer-rtsp-1.0
# The 1.22 here corresponds to the version number queried above, all available version numbers can be queried using `git branch -a`, just use the closest version number
git switch 1.22
Compile gst-rtsp-server
meson build
cd build
ninja
Run gst-rtsp-server
Here we assume that /dev/video-camera0
is the video source you want to use. If your camera is assigned a different name, replace the corresponding device name in the following command line.
cd examples/
# mpph264enc encoder currently has lagging problem under Rockchip 6.1 Linux kernel, we suggest to use mpph265enc encoder.
# mpph264enc, mpph265enc, mppjpegenc, mppvp8enc encoders are available. To change the encoder, you need to change the rtp*pay or *parse in the pipeline.
./test-launch --gst-debug-level=3 "( v4l2src device=/dev/video-camera0 ! queue ! mpph265enc bps=51200000 rc-mode=vbr ! rtph265pay name=pay0 pt=97 )"
# If you only want to record the camera to a file, use the following command
# gst-launch-1.0 --gst-debug-level=3 v4l2src device=/dev/video-camera0 ! queue ! mpph265enc bps=51200000 rc-mode=vbr ! h265parse ! mp4mux ! filesink location=output.mp4
Client configuration
Using VLC Player
The following is an example of how to watch RTSP video stream by running VLC under Windows.
-
Download and install VLC
-
Click "Media - Open Network Streaming" to enter the RTSP stream address.
A communicable IP address is necessary.
- Click
Play
to view the RTSP remote streaming content.
Using the ffplay player on a development board
It is also possible to play directly with the ffplay utility for FFmpeg mentioned above
Should be replaced with the URL and IP address specified in the server command line.
The -vcodec
option is the specified codec, please adjust it according to the encoding of the RTSP stream. The hardware decoders supported by ffmpeg-rockchip are av1_rkmpp
, h263_rkmpp
, h264_rkmpp
, hevc_rkmpp
, mpeg1_rkmpp
, mpeg2_rkmpp
, mpeg4_rkmpp
, vp8_rkmpp
, vp9_rkmpp
.
ffmpeg-rockchip/ffplay -vcodec h264_rkmpp rtsp://192.168.10.9:8554/stream