> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 设置 RTSP

> 设置 RTSP 服务器，并在 Qualcomm Device Cloud 设备之间收发视频流

1. 下载 [MediaMTX](https://github.com/bluenviron/mediamtx) 工具以搭建 RTSP 监听服务器。

   以下步骤已针对 MediaMTX 版本 `v1.11.3_linux_arm64v8` 验证，可从
   [mediamtx\_v1.11.3\_linux\_arm64v8.tar.gz](https://github.com/bluenviron/mediamtx/releases/download/v1.11.3/mediamtx_v1.11.3_linux_arm64v8.tar.gz) 获取。

2. 解压下载的归档文件，并编辑 `mediamtx.yml` 文件以在端口 `8901` 上启用 RTSP 流。

   ```yaml theme={null}
   ###############################################
   # Global settings -> RTSP server

   # Enable publishing and reading streams with the RTSP protocol.
   rtsp: yes

   # List of enabled RTSP transport protocols.
   # UDP is the most performant, but doesn't work when there's a NAT/firewall between
   # server and clients, and doesn't support encryption.
   # UDP-multicast allows to save bandwidth when clients are all in the same LAN.
   # TCP is the most versatile, and does support encryption.
   # The handshake is always performed with TCP.
   rtspTransports: [udp, multicast, tcp]

   # Encrypt handshakes and TCP streams with TLS (RTSPS).
   # Available values are "no", "strict", "optional".
   rtspEncryption: "no"

   # Address of the TCP/RTSP listener. This is needed only when encryption is "no" or "optional".
   rtspAddress: :8901

   # Address of the TCP/TLS/RTSPS listener. This is needed only when encryption is "strict" or "optional".
   rtspsAddress: :8322
   ```

3. 将 `mediamtx.yml` 文件和 `mediamtx` 可执行文件复制到设备：

   ```shell theme={null}
   scp -P 2222 -o StrictHostKeychecking=no -o UserKnownHostsFile=/dev/null <mediamtx path>/mediamtx root@localhost:/opt
   ```

   ```shell theme={null}
   scp -P 2222 -o StrictHostKeychecking=no -o UserKnownHostsFile=/dev/null <mediamtx path>/mediamtx.yml root@localhost:/opt
   ```

4. 打开一个新的 SSH shell 并运行 `mediamtx` 工具：

   ```shell theme={null}
   cd /opt
   chmod +x mediamtx
   ./mediamtx
   ```

   <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Tools/Qualcomm-Device-Cloud/_images/qdc/execute-mediamtx.png" alt="在设备上运行的 MediaMTX 工具" />

5. 在主机上的 localhost 端口 `8901` 上启动一路 RTSP 流。

   以下示例使用 [FFmpeg](https://ffmpeg.org/) 捕获来自已连接网络摄像头的输入，并将其作为 RTSP 流发送。如果未安装 FFmpeg，请从 FFmpeg 网站[下载](https://ffmpeg.org/download.html)。

   ```shell theme={null}
   ffmpeg -f dshow -video_size 640x480 -i video="Integrated Camera" -framerate 15 -vf format=yuv420p -c:v h264 -f rtsp -rtsp_transport tcp rtsp://127.0.0.1:8901/live1.mkv
   ```

   <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Tools/Qualcomm-Device-Cloud/_images/qdc/ffmpeg-cmd.png" alt="用于 RTSP 流传输的 FFmpeg 命令" />

6. 使用 VLC 媒体播放器验证 RTSP 流输出：

   1. 打开 VLC 媒体播放器。
   2. 按 `Ctrl+N`。
   3. 在输入栏中输入 URL `rtsp://127.0.0.1:8901/live1.mkv`。
   4. 选择 **Play**。

   <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Tools/Qualcomm-Device-Cloud/_images/qdc/rtsp-vlc-output.png" alt="VLC 媒体播放器中的 RTSP 流输出" />
