Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: rtsp: replace gst-rtsp-server with mediamtx #577

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions docs/common/dev/_rtsp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
:::tip
使用 HDMI RX 时,低于 720P 分辨率的输入源可能会导致编码失败。
经测试,ffmpeg-rockchip 与我们发布的 Debian 11 系统的 rkmpp 和 librga 版本不兼容,Debian 12 系统不受影响。
如果你使用的是我们发布的 Debian 11 系统请移步[ ffmpeg-rockchip 官方编译教程](https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Compilation),构建 rkmpp 和 librga 后构建 ffmpeg-rockchip。
如果你使用的是我们发布的 Debian 11 系统请移步 [ffmpeg-rockchip 官方编译教程](https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Compilation),构建 rkmpp 和 librga 后构建 ffmpeg-rockchip,
并运行 `sudo apt-get update && sudo apt-get install librga2=2.2.0-1`。
:::

### 安装编译依赖
Expand Down Expand Up @@ -53,7 +54,42 @@ ffmpeg-rockchip/ffmpeg -f v4l2 -i /dev/video-camera0 -vf "fps=30" -s 3840x2160 -

</TabItem>

<TabItem value="gstreamer" label="基于 Gstreamer">
<TabItem value="gstreamer-mediamtx" label="基于 Gstreamer + mediamtx">

:::tip
因为 mpph264enc 在 Rockchip 6.1 Linux 内核的 Radxa OS 编解码效率很差,推荐优先使用 mpph265enc。
使用 HDMI RX 时,目前 gst-mppenc 暂不支持 NV24(YCbCr444) 与 RGB 输入,需要 HDMI 输入端切换颜色格式为 NV12(YCbCr420) 或 NV16(YCbCr422),或者使用 FFmpeg 进行推流。
:::

### 安装依赖

```bash
sudo apt-get update
sudo apt-get install gstreamer1.0-rtsp
RadxaYuntian marked this conversation as resolved.
Show resolved Hide resolved
```

### 运行 mediamtx 和 Gstreamer

:::info
此处我们假定 `/dev/video-camera0` 是你想要使用的视频源。如果你的摄像头被分配到了其他的名称下,请替换以下命令行中对应的设备名。
:::

```bash
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 编码器目前在 Rockchip 6.1 Linux 内核下有卡顿问题,建议使用 mpph265enc 编码器
# 可用的编码器有 mpph264enc、mpph265enc、mppjpegenc、mppvp8enc,修改编码器需要修改 pipeline 后的 rtp*pay 或 *parse
gst-launch-1.0 -v v4l2src device=/dev/video-camera0 ! queue ! mpph265enc bps=51200000 rc-mode=vbr ! rtspclientsink location=rtsp://localhost:8554/test

# 如果仅想将摄像头录制成文件,请使用以下命令
# 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
```

</TabItem>

<TabItem value="gst-rtsp-server" label="基于 Gstreamer + gst-rtsp-server">

:::tip
因为 mpph264enc 在 Rockchip 6.1 Linux 内核的 Radxa OS 编解码效率很差,推荐优先使用 mpph265enc。
Expand All @@ -64,20 +100,23 @@ ffmpeg-rockchip/ffmpeg -f v4l2 -i /dev/video-camera0 -vf "fps=30" -s 3840x2160 -

```bash
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
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
```

### 获取 gst-rtsp-server 源码

```bash
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
git clone https://gitlab.freedesktop.org/gstreamer/gstreamer.git
cd gstreamer/subprojects/gst-rtsp-server
# 查询系统内 gstreamer-rtsp-1.0 的版本号
RadxaYuntian marked this conversation as resolved.
Show resolved Hide resolved
pkg-config --modversion gstreamer-rtsp-1.0
# 此处的 1.22 对应上面查询到的版本号,所有可用版本号可使用 `git branch -a` 查询,使用最相近的版本号即可
git switch 1.22
```

### 编译 gst-rtsp-server

```bash
cd gst-rtsp-server-1.18.6/
meson build
cd build
ninja
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
:::tip
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 ](https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Compilation), build rkmpp and librga and then build ffmpeg-rockchip.
If you are using our Debian 11 system, please go to [ffmpeg-rockchip official build tutorial ](https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Compilation), 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
Expand Down Expand Up @@ -53,7 +54,43 @@ ffmpeg-rockchip/ffmpeg -f v4l2 -i /dev/video-camera0 -vf "fps=30" -s 3840x2160 -

</TabItem>

<TabItem value="gstreamer" label="Based on Gstreamer">
<TabItem value="gstreamer-mediamtx" label="Based on Gstreamer + mediamtx">

:::tip
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

```bash
sudo apt-get update
sudo apt-get install gstreamer1.0-rtsp
```

### Running mediamtx and Gstreamer

:::info
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.
:::

```bash
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
```

</TabItem>

<TabItem value="gst-rtsp-server" label="Based Gstreamer + gst-rtsp-server">

:::tip
Because mpph264enc is poorly encoded and decoded by Radxa OS in Rockchip 6.1 Linux kernel, it is recommended to use mpph265enc in preference.
Expand All @@ -64,20 +101,23 @@ When using HDMI RX, gst-mppenc does not support NV24(YCbCr444) and RGB input, yo

```bash
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
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

```bash
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
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

```bash
cd gst-rtsp-server-1.18.6/
meson build
cd build
ninja
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,28 @@ Most radxa sbc's can be powered from the GPIO connector on the 40 PIN, except fo
The power supply must be a stable 5V output, if the power supply fluctuates more than 5.2V, it may burn the board.
:::

- Find 5V and GND in 40 PIN GPIO (you can find the infomation at **Hardware Info** Part of the product's docs)
- Find 5V and GND in 40 PIN GPIO (you can find the information at **Hardware Info** Part of the product's docs)

<img src="/img//rock5b/rock5bp_40pin_power_3.webp" alt="rock 40 pin" width="300" />
<img
src="/img//rock5b/rock5bp_40pin_power_3.webp"
alt="rock 40 pin"
width="300"
/>

- Use DuPont cables to connect the positive and negative terminals of the power supply, 2 to the positive terminal and 2 to the negative terminal.
- Adjust the power supply voltage to 5V, then power on the board.
- Connect the positive end of the DuPont cable to the 5V input PIN of the 40 PIN, and the negative end of the DuPont cable to the GND of the 40 PIN.

<img src="/img//rock5b/rock5bp_40pin_power_1.webp" alt="rock 40 pin power" width="700" />
<img src="/img//rock5b/rock5bp_40pin_power_2.webp" alt="rock 40 pin power" width="700" />
<img
src="/img//rock5b/rock5bp_40pin_power_1.webp"
alt="rock 40 pin power"
width="700"
/>
<img
src="/img//rock5b/rock5bp_40pin_power_2.webp"
alt="rock 40 pin power"
width="700"
/>

## Frequently Asked Questions

Expand Down