如何将 RTSP 流发布到配置了 TLS 加密的 MediaMTX 实例?

如何将 RTSP 流发布到配置了 TLS 加密的 MediaMTX 实例?

我有一个例子(媒体MTX) 在我的笔记本电脑上运行。我有一台 Amcrest IP 摄像头。我可以将摄像头的 RTSP 流发布到服务器,以便可以从 MediaMTX 实例访问该流。

但是,我想加密流。在 MediaMTX 的 Github 页面上,他们详细介绍了如何通过生成 server.key 和 server.crt 并编辑 .yml 配置文件中的行来为传入和传出的 RTSP 流启用 TLS 加密。然后可以使用 RTSPS 和端口 8322 发布和读取流。

我已按照以下步骤操作,并在 .yml 中为我的 IP 摄像机设置了以下路径:

###############################################
# Path settings

# Settings in "paths" are applied to specific paths, and the map key
# is the name of the path.
# Any setting in "pathDefaults" can be overridden here.
# It's possible to use regular expressions by using a tilde as prefix,
# for example "~^(test1|test2)$" will match both "test1" and "test2",
# for example "~^prefix" will match all paths that start with "prefix".
paths:

  cam1:
    source: rtsp://user:[email protected]:554
    runOnInit: ffmpeg -i rtsp://user:[email protected]:554 -c:v copy -c:a copy -f rtsp rtsps://localhost:8322/stream/cam1

但是当我的 MediaMTX 实例运行时,我得到了以下输出:

2024/02/15 18:20:59 INF [path cam1] [RTSP source] ready: 2 tracks (H264, MPEG-4 Audio)
Input #0, rtsp, from 'rtsp://user:[email protected]:554':
  Metadata:
    title           : Media Server
  Duration: N/A, start: 0.030000, bitrate: N/A
  Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1920x1080, 100 tbr, 90k tbn
  Stream #0:1: Audio: aac (LC), 16000 Hz, mono, fltp
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
2024/02/15 18:21:00 INF [RTSPS] [conn [::1]:60147] opened
2024/02/15 18:21:00 INF [RTSPS] [session 07a8f23e] created by [::1]:60147
2024/02/15 18:21:00 INF [RTSPS] [conn [::1]:60147] closed: path 'stream/cam1' is not configured
2024/02/15 18:21:00 INF [RTSPS] [session 07a8f23e] destroyed: not in use
[out#0/rtsp @ 00000225c75fe9c0] Could not write header (incorrect codec parameters ?): Server returned 400 Bad Request
Conversion failed!
2024/02/15 18:21:00 INF [path cam1] runOnInit command exited: command exited with code 3486501640
2024/02/15 18:21:29 WAR [path cam1] [RTSP source] 10 RTP packets lost
2024/02/15 18:21:33 WAR [path cam1] [RTSP source] 2 RTP packets lost
2024/02/15 18:21:39 WAR [path cam1] [RTSP source] 11 RTP packets lost

我没有遇到任何错误,并且能够在不使用加密的情况下使用相同的路径配置(使用 rtsp://,而不是 rtsps://)发布流。我可以尝试哪些可能的解决方案?

相关内容