基于rtsp-simple-server和ffmpeg搭建流媒体服务器
rtsp-simple-server安装运行
-
下载rtsp-simple-server:
https://github.com/aler9/rtsp-simple-server/releases
-
解压缩:
tar -xvf rtsp-simple-server_v0.21.6_linux_amd64.tar.gz
-
启动rtsp-simple-server服务:
cd rtsp-simple-server_v0.21.6_linux_amd64
./rtsp-simple-server
ffmpeg安装
sudo apt-get install libsdl2-dev
wget https://launchpadlibrarian.net/648139441/ffmpeg_5.1.2.orig.tar.xz
tar -xvf ffmpeg_5.1.2.orig.tar.xz
cd ffmpeg-5.1.2
./configure --enable-ffplay --disable-x86asm --enable-gpl --enable-libx264 --enable-libx265
make
sudo make install
ffmpeg --help
ffmpeg推流
RTSP协议
UDP推流
ffmpeg -re -i ./test.mp4 -c copy -f rtsp rtsp://localhost:8554/stream
TCP推流
ffmpeg -re -i ./test.mp4 -c copy -f rtsp -rtsp_transport tcp rtsp://localhost:8554/stream
循环推流
ffmpeg -re -stream_loop -1 -i ./test.mp4 -c copy -f rtsp rtsp://localhost:8554/stream
RTMP协议
ffmpeg -re -stream_loop -1 -i ./test.mp4 -c copy -f flv rtmp://localhost/stream
注:
-re 以流的方式读取
-stream_loop 循环读取视频源的次数,-1为无限循环
-i 输入的文件
-f 格式化输出到哪里
拉流
ffmpeg拉流保存到视频文件
ffmpeg -i rtsp://localhost:8554/stream -c copy output.mp4
ffmpeg -i rtmp://localhost/stream -c copy output.mp4
ffplay拉流播放
ffplay rtsp://localhost:8554/stream
ffplay rtmp://localhost/stream
vlc拉流播放
sudo apt install vlc
vlc rtsp://localhost:8554/stream
vlc rtmp://localhost/stream
在视频流媒体类AI模型推理服务中演示
在视频流媒体类AI模型推理服务的浏览器界面中,选择“云流媒体”,在“流媒体URL”输入框中填入上述使用ffmpeg推流的URL地址,例如:rtsp://localhost:8554/stream。
需要使用到此类流媒体服务的AI模型举例如下: