文章目录
- 实验
- 下载推流服务端版本
- 运行
摘要:书接上回
https://blog.csdn.net/qq_20330595/article/details/146412411?spm=1001.2014.3001.5502
我们先做几个试验,方便我们理解rtsp推流,先把采集和播放体验一下,我们最后回到代码本身进行修改编译和运行。
实验
开启服务
maqi@maqi:~/Desktop/Live555/live/linux-64bit/usr/local/bin$ ./testOnDemandRTSPServer 8554
"mpeg4ESVideoTest" stream, from the file "test.m4e"
Play this stream using the URL "rtsp://192.168.145.130:8554/mpeg4ESVideoTest"
"h264ESVideoTest" stream, from the file "test.264"
Play this stream using the URL "rtsp://192.168.145.130:8554/h264ESVideoTest"
"h265ESVideoTest" stream, from the file "test.265"
Play this stream using the URL "rtsp://192.168.145.130:8554/h265ESVideoTest"
"mpeg1or2AudioVideoTest" stream, from the file "test.mpg"
Play this stream using the URL "rtsp://192.168.145.130:8554/mpeg1or2AudioVideoTest"
"mpeg1or2ESVideoTest" stream, from the file "testv.mpg"
Play this stream using the URL "rtsp://192.168.145.130:8554/mpeg1or2ESVideoTest"
"mp3AudioTest" stream, from the file "test.mp3"
Play this stream using the URL "rtsp://192.168.145.130:8554/mp3AudioTest"
"wavAudioTest" stream, from the file "test.wav"
Play this stream using the URL "rtsp://192.168.145.130:8554/wavAudioTest"
"amrAudioTest" stream, from the file "test.amr"
Play this stream using the URL "rtsp://192.168.145.130:8554/amrAudioTest"
"vobTest" stream, from the file "test.vob"
Play this stream using the URL "rtsp://192.168.145.130:8554/vobTest"
"mpeg2TransportStreamTest" stream, from the file "test.ts"
Play this stream using the URL "rtsp://192.168.145.130:8554/mpeg2TransportStreamTest"
"aacAudioTest" stream, from the file "test.aac"
Play this stream using the URL "rtsp://192.168.145.130:8554/aacAudioTest"
"dvVideoTest" stream, from the file "test.dv"
Play this stream using the URL "rtsp://192.168.145.130:8554/dvVideoTest"
"ac3AudioTest" stream, from the file "test.ac3"
Play this stream using the URL "rtsp://192.168.145.130:8554/ac3AudioTest"
"matroskaFileTest" stream, from the file "test.mkv"
Play this stream using the URL "rtsp://192.168.145.130:8554/matroskaFileTest"
"webmFileTest" stream, from the file "test.webm"
Play this stream using the URL "rtsp://192.168.145.130:8554/webmFileTest"
"oggFileTest" stream, from the file "test.ogg"
Play this stream using the URL "rtsp://192.168.145.130:8554/oggFileTest"
"opusFileTest" stream, from the file "test.opus"
Play this stream using the URL "rtsp://192.168.145.130:8554/opusFileTest"
"mpeg2TransportStreamFromUDPSourceTest" stream, from a UDP Transport Stream input source
(IP multicast address 239.255.42.42, port 1234)
Play this stream using the URL "rtsp://192.168.145.130:8554/mpeg2TransportStreamFromUDPSourceTest"
(We use port 8000 for optional RTSP-over-HTTP tunneling.)
复制测试文件
vlc播放
./testRTSPClient rtsp://127.0.0.1:8554/h264ESVideoTest
./testRTSPClient rtsp://127.0.0.1:8554/mp3AudioTest
下载推流服务端版本
https://github.com/bluenviron/mediamtx/releases/tag/v1.11.3
uname -m
mediamtx_v1.11.3_linux_amd64.tar.gz b2e65c0be00434b13e01feb64e85af4bc65fa3c62d1b9aa2d4139bd28d795cba
运行
./mediamtx
端口占用
maqi@maqi:~/Desktop$ tar -zxvf mediamtx_v1.11.3_linux_amd64.tar.gz
mediamtx
mediamtx.yml
LICENSE
maqi@maqi:~/Desktop$ ./mediamtx
2025/03/24 22:04:16 INF MediaMTX v1.11.3
2025/03/24 22:04:16 INF configuration loaded from /home/maqi/Desktop/mediamtx.yml
2025/03/24 22:04:16 ERR listen tcp :8554: bind: address already in use
2025/03/24 22:04:16 INF waiting for running hooks
运行成功
maqi@maqi:~/Desktop$ ./mediamtx
2025/03/24 22:06:56 INF MediaMTX v1.11.3
2025/03/24 22:06:56 INF configuration loaded from /home/maqi/Desktop/mediamtx.yml
2025/03/24 22:06:56 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
2025/03/24 22:06:56 INF [RTMP] listener opened on :1935
2025/03/24 22:06:56 INF [HLS] listener opened on :8888
2025/03/24 22:06:56 INF [WebRTC] listener opened on :8889 (HTTP), :8189 (ICE/UDP)
2025/03/24 22:06:56 INF [SRT] listener opened on :8890 (UDP)
投屏
全屏录制
ffmpeg -f x11grab -video_size $(xdpyinfo | grep dimensions | awk '{print $2;}') -r 30 -i :0.0 -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -f rtsp -g 5 -an rtsp://192.168.145.130:8554/mystream
vlc播放
rtsp://192.168.145.130:8554/mystream
ffplay播放
ffplay -i rtsp://192.168.145.130:8554/mystream
go2rtc在线播放
https://github.com/AlexxIT/go2rtc
运行
http://localhost:1984/log.html
录屏效果展示