{"id":14987650,"url":"https://github.com/wanghaoxi3000/gin-rtsp","last_synced_at":"2025-04-05T20:06:13.727Z","repository":{"id":36661611,"uuid":"228441204","full_name":"wanghaoxi3000/gin-rtsp","owner":"wanghaoxi3000","description":"基于Gin + WebSocket + JSMpeg，在HTML页面上直接播放RTSP视频流。","archived":false,"fork":false,"pushed_at":"2024-07-09T02:19:26.000Z","size":7924,"stargazers_count":266,"open_issues_count":4,"forks_count":95,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-29T18:09:04.079Z","etag":null,"topics":["gin","golang","rtsp","websocket"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wanghaoxi3000.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-16T17:38:36.000Z","updated_at":"2025-03-25T09:38:28.000Z","dependencies_parsed_at":"2024-07-09T05:57:17.740Z","dependency_job_id":null,"html_url":"https://github.com/wanghaoxi3000/gin-rtsp","commit_stats":{"total_commits":27,"total_committers":7,"mean_commits":3.857142857142857,"dds":0.6666666666666667,"last_synced_commit":"14a438ad89314fd5d93815b0f6d0eada6d57afb1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wanghaoxi3000%2Fgin-rtsp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wanghaoxi3000%2Fgin-rtsp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wanghaoxi3000%2Fgin-rtsp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wanghaoxi3000%2Fgin-rtsp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wanghaoxi3000","download_url":"https://codeload.github.com/wanghaoxi3000/gin-rtsp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393569,"owners_count":20931812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gin","golang","rtsp","websocket"],"created_at":"2024-09-24T14:15:06.882Z","updated_at":"2025-04-05T20:06:13.693Z","avatar_url":"https://github.com/wanghaoxi3000.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# gin-rtsp\n基于 [**JSMpeg**](https://github.com/phoboslab/jsmpeg/) 的原理，在HTML页面上直接播放RTSP视频流，使用Gin框架开发。\n\n\n## 主要模块\n- API 接口：接收FFMPEG的推流数据和客户端的HTTP请求，将客户端需要播放的RTSP地址转换为一个对应的WebSocket地址，客户端通过这个WebSocket地址便可以直接播放视频，为了及时释放不再观看的视频流，这里设计为客户端播放时需要在每隔60秒的时间里循环请求这个接口，超过指定时间没有收到请求的话后台便会关闭这个视频流。\n\n- FFMPEG 视频转换：收到前端的请求后，启动一个Goroutine调用系统的FFMPEG命令转换指定的RTSP视频流并推送到后台对应的接口，自动结束已超时转换任务。\n\n- WebSocket Manager：管理WebSocket客户端，将请求同一WebSocket地址的客户端添加到一个Group中，向各个Group广播对应的RTSP视频流，删除Group中已断开连接的客户端，释放空闲的Group。\n\n\n## 注意\n- 需要摄像头的码流为H264码流\n\n\n## 编译\n**项目需要运行在安装有FFMPEG程序的环境中。**\n\n### Docker\nDockerfile 中已经封装好了需要的环境，可以使用Docker build后，以Docker的方式运行。\n```\n$ docker build -t ginrtsp .\n$ docker run -td -p 3000:3000 ginrtsp\n```\n\n### 本地编译\n\n**linux**\n\n```shell\ngo build -o ./bin/linux/rtsp-relay\n```\n\n**windows**\n\n```shell\ngo build -o ./bin/windows/rtsp-relay.exe\n```\n\n### 环境变量\n- RTSP_PORT 默认为3000\n- RTSP_CORS 默认为false, 设置为true时跨域，其他不跨域\n\n\n## 测试\n### 使用内置的FFMPEG转换\n将需要播放的RTSP流地址提交到 /stream/play 接口，例如：\n```\nPOST /stream/play\n{\n   \"url\": \"rtsp://admin:password@192.168.3.10:554/cam/realmonitor?channel=1\u0026subtype=0\"\n}\n```\n\n后台可以正常转换此RTSP地址时便会返回一个对应的地址，例如：\n```\n{\n    \"code\": 0,\n    \"data\": {\n        \"path\": \"/stream/live/5b96bff4-bdb2-3edb-9d6e-f96eda03da56\"\n    },\n    \"msg\": \"success\"\n}\n```\n\n编辑`html`文件夹下view-stream.html文件，将script部分的url修改为此地址，在浏览器中打开，便可以看到视频了。\n\n### 手动运行FFMPEG\n由于后台转换RTSP的进程在超过60秒没有请求后便会停止，也可以通过手动运行ffmpeg命令，来更方便地在测试状态下查看视频。\n```\nffmpeg -rtsp_transport tcp -re -i 'rtsp://admin:password@192.168.3.10:554/cam/realmonitor?channel=1\u0026subtype=0' -q 0 -f mpegts -c:v mpeg1video -an -s 960x540 http://127.0.0.1:3000/stream/upload/test\n```\n\n通过如上命令，运行之后在view-stream.html文件的url中填入对应的地址为`/stream/live/test`，在浏览器中打开查看视频。\n\n\n### 显示效果\n\n![](./video-example.png)\n\n\n## 参考\n[JSMpeg – MPEG1 Video \u0026 MP2 Audio Decoder in JavaScript](https://github.com/phoboslab/jsmpeg/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwanghaoxi3000%2Fgin-rtsp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwanghaoxi3000%2Fgin-rtsp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwanghaoxi3000%2Fgin-rtsp/lists"}