我正在尝试从RTSP服务器获取HTML页面上的音频流。
RTSP服务器是运行下面命令行的rtsp-简单-服务器。
./rtsp-simple-server rtsp-simple-server.yml
。
配置文件是默认的。
流播放器正在FFmpeg下面运行一个命令行。
ffmpeg -re -stream_loop -1 -i myaudio.mp3 -c copy -f rtsp -rtsp_transport tcp rtsp://localhost:8554/mystream
启动rtsp简单服务器和ffmpeg时的控制台日志如下所示。
2022/05/29 19:06:38 INF rtsp-simple-server v0.18.4
2022/05/29 19:06:38 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
2022/05/29 19:06:38 INF [RTMP] listener opened on :1935
2022/05/29 19:06:38 INF [HLS] listener opened on :8888
2022/05/29 19:09:16 INF [RTSP] [conn [::1]:62737] opened
2022/05/29 19:09:16 INF [RTSP] [session 271690815] created by [::1]:62737
2022/05/29 19:09:16 INF [RTSP] [session 271690815] is publishing to path 'mystream', 1 track with TCP
当VLC打开rtsp路径(rtsp://localhost:8554/mystream)时,内容可以正常播放。此时的附加控制台日志如下所示。
2022/05/29 19:13:19 INF [RTSP] [conn 127.0.0.1:62780] opened
2022/05/29 19:13:19 INF [RTSP] [session 734209460] created by 127.0.0.1:62780
2022/05/29 19:13:19 INF [RTSP] [session 734209460] is reading from path 'mystream', 1 track with UDP
2022/05/29 19:13:29 INF [RTSP] [session 734209460] destroyed (teared down by 127.0.0.1:62780)
2022/05/29 19:13:29 INF [RTSP] [conn 127.0.0.1:62780] closed (EOF)
2022/05/29 19:13:29 INF [RTSP] [conn 127.0.0.1:62781] opened
2022/05/29 19:13:29 INF [RTSP] [session 445756113] created by 127.0.0.1:62781
2022/05/29 19:13:29 INF [RTSP] [session 445756113] is reading from path 'mystream', 1 track with TCP
但是,我打开VLC的“网络”选项卡中的rtsp流,如下所示,
配置如下所示的“流输出”
我试着从下面的HTML页面上得到这个流,
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>transcode test</title>
</head>
<body>
<h1>transcode test</h1>
<audio src="http://localhost:9999/mystream" autoplay="autoplay"></audio>
</body>
</html>
浏览器控制台显示Failed to load resource: the server responded with a status of 404 (Not found)
。我已经尝试过其他端口(例如8080)。
因此,如何从HTML页面上的rtsp服务器获取RTSP流。有什么想法吗?
我的环境。
发布于 2022-05-30 12:32:05
RTSP简单服务器可以发布RTSP或RTMP (https://github.com/aler9/rtsp-simple-server):
不幸的是,浏览器通常不能本地播放RTMP或RTSP。
典型的方法是将RTSP流转换为浏览器可以本地或通过普通的基于HTML5的播放器(如视频is、沙卡播放器等)播放的内容,例如HLS流。
这是一个常见的场景,尽管许多人关注的是视频,而不是像您这样的音频流。您将找到多个指南来帮助解决这个问题,许多基于ffmpeg的命令-例如,参见以下答案:https://stackoverflow.com/a/60082821/334402
https://stackoverflow.com/questions/72422980
复制相似问题