1. 安装 MediaMTX
你可以用 Homebrew 安装
brew install mediamtx
2. 启动 MediaMTX
在终端运行:
mediamtx
默认会监听本地的 RTSP(rtsp://localhost:8554)和 HLS(http://localhost:8888)等端口。
image.png
3. 本地推流到 MediaMTX
假设你有一个本地视频文件 test.mp4
,可以用 ffmpeg 推流到 MediaMTX:
ffmpeg -re -stream_loop -1 -i /Users/pengchao/Documents/workspace/upload_rtsp/jiaoben/new_new_out.ts -c:v copy -c:a aac -f rtsp rtsp://localhost:8554/mystream
本地推流的视频格式为ts格式信息如下
Input #0, mpegts, from '/Users/pengchao/Documents/workspace/upload_rtsp/jiaoben/new_new_out.ts':
Duration: 00:01:00.18, start: 1.400000, bitrate: 1098 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 960x544 [SAR 1:1 DAR 30:17], 25 fps, 25 tbr, 90k tbn
Stream #0:1[0x101](und): Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 130 kb/s
-
-re
:按原始帧率读取 -
-stream_loop -1
:循环播放 -
-c copy
:不转码 -
-f rtsp
:以 RTSP 协议推流 -
rtsp://localhost:8554/mystream
:推流地址
4. 播放推流
你可以用 VLC 或 ffplay 播放:
ffplay rtsp://localhost:8554/mystream
或在 VLC 打开网络串流,输入 rtsp://localhost:8554/mystream
。
检查网络流是否符合
ffprobe -v debug -i rtsp://172.17.112.195:8554/mystream