Skip to content

Commit

Permalink
perf: rtsp: replace gst-rtsp-server with mediamtx
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeChenL committed Nov 20, 2024
1 parent a2cade3 commit 7bcd224
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 46 deletions.
35 changes: 12 additions & 23 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 @@ -60,40 +61,28 @@ ffmpeg-rockchip/ffmpeg -f v4l2 -i /dev/video-camera0 -vf "fps=30" -s 3840x2160 -
使用 HDMI RX 时,目前 gst-mppenc 暂不支持 NV24(YCbCr444) 与 RGB 输入,需要 HDMI 输入端切换颜色格式为 NV12(YCbCr420) 或 NV16(YCbCr422),或者使用 FFmpeg 进行推流。
:::

### 安装编译依赖

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

### 获取 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
```

### 编译 gst-rtsp-server

```bash
cd gst-rtsp-server-1.18.6/
meson build
cd build
ninja
sudo apt-get update
sudo apt-get install gstreamer1.0-rtsp
```

### 运行 gst-rtsp-server
### 运行 mediamtx 和 Gstreamer

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

```bash
cd examples/
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
./test-launch --gst-debug-level=3 "( v4l2src device=/dev/video-camera0 ! queue ! mpph265enc bps=51200000 rc-mode=vbr ! rtph265pay name=pay0 pt=97 )"
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
```
Expand Down
35 changes: 12 additions & 23 deletions i18n/en/docusaurus-plugin-content-docs/current/common/dev/_rtsp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,43 +57,32 @@ ffmpeg-rockchip/ffmpeg -f v4l2 -i /dev/video-camera0 -vf "fps=30" -s 3840x2160 -

:::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.
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 of compilation dependencies

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

### Get gst-rtsp-server source code
### Installation dependencies

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

### Compile gst-rtsp-server

```bash
cd gst-rtsp-server-1.18.6/
meson build
cd build
ninja
sudo apt-get update
sudo apt-get install gstreamer1.0-rtsp
```

### Run gst-rtsp-server
### 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
cd examples/
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.
./test-launch --gst-debug-level=3 "( v4l2src device=/dev/video-camera0 ! queue ! mpph265enc bps=51200000 rc-mode=vbr ! rtph265pay name=pay0 pt=97 )"
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
```
Expand Down

0 comments on commit 7bcd224

Please sign in to comment.