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
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.
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.
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
Get gst-rtsp-server source code
wget https://gstreamer.freedesktop.org/src/gst-rtsp-server/gst-rtsp-server-1.18.6.tar.xz
tar -xvf gst-rtsp-server-1.18.6.tar.xz
Compile gst-rtsp-server
cd gst-rtsp-server-1.18.6/
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