RTSP模拟开发:轻松搭建本地摄像头推流
2026/5/31 22:12:27 网站建设 项目流程

在开发中我们可能会涉及到连接摄像头的开发,但是在本地环境我们没有相关的连接时,就需要本地进行模拟。

✅ 推荐方案:使用RTSP Simple Server(RSS)

这是一个用 Go 写的超轻量、零依赖、单文件 RTSP 服务器,专为开发模拟设计,完美匹配你的需求。

步骤 1:下载 RTSP Simple Server

  • GitHub:https://github.com/aler9/rtsp-simple-server
  • Windows 直接下载:
    👉 https://github.com/aler9/rtsp-simple-server/releases
    下载rtsp-simple-server_vX.X.X_windows_amd64.tar.gz→ 解压得到rtsp-simple-server.exe

无需安装,双击即可运行(默认配置即可用)。

步骤 2:启动 RTSP 服务器

rtsp-simple-server.exe

默认会监听:

  • RTSP 地址:rtsp://localhost:8554/
  • 推流路径:任意(如mystream
  • 无需认证(开发用很安全)

步骤 3:用 FFmpeg 从摄像头推流到 RTSP

FFmpeg 安装:https://ffmpeg.org/download.html#build-windows 下载适合自己系统的安装包,并进行环境变量配置

将软件安装的位置添加到系统环境变量的Path里

\ffmpeg-7.1.1-essentials_build\bin

确认自己系统的设备名

ffmpeg -list_devices true -f dshow -i dummy


将摄像头推送到 rtsp server上播放

ffmpeg -f dshow ^ -video_size 320x240 ^ -framerate 30 ^ -pixel_format yuyv422 ^ -i video="Integrated Camera" ^ -c:v libx264 ^ -preset ultrafast ^ -tune zerolatency ^ -pix_fmt yuv420p ^ -f rtsp rtsp://localhost:8554/mystream

🔑 关键点:

  • 必须指定-pixel_format yuyv422(你的摄像头只支持这个)
  • -tune zerolatency减少延迟(对实时检测很重要)
  • 输出格式-f rtsp推送到 RSS

步骤4 用 FFmpeg 将视频文件循环推流到 RTSP

假设你的视频文件是 C:\videos\test.mp4,执行:

ffmpeg -re ^ -stream_loop -1 ^ -i"C:\videos\test.mp4"^ -c copy ^ -f rtsp rtsp://localhost:8554/live

🛠 调试技巧

  1. 验证 RTSP 是否推成功

    ffplay rtsp://localhost:8554/live

    或用 VLC 打开网络流。

  2. 查看 RSS 日志
    启动rtsp-simple-server后,会打印:

    [tcp] client connected [rtsp] stream 'live' created

    表示推流成功。

  3. 停止推流:按qCtrl+C终止 FFmpeg。

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询