feat(media): SRS WebRTC streaming via mediamtx push-to-RTMP#11
Merged
Conversation
Make the optional SRS path actually work end-to-end so teammates can
view cameras over WHEP. The previous implementation advertised a
`webrtc://host/path` URL that no client could fetch and bound mediamtx
WebRTC to the same UDP port SRS needs (8000), so the two coexisted in
config but never both worked at runtime.
- mediamtx: new `webrtc_udp` ListenerPort (default :8189), rendered as
`webrtcLocalUDPAddress`. When any path has `push_to`, force RTSP to
TCP-only and zero out RTP/RTCP UDP — that frees host UDP 8000 for
SRS. Always-on the source for `push_to` paths so the upstream pull
doesn't deadlock waiting on a local viewer.
- endpoints: build a real WHEP URL —
`http://<webrtc_host>/rtc/v1/whep/?app=<app>&stream=<id>&codec=h264`.
Real http(s):// because WHEP is HTTP-POST-application/sdp; pinned to
H.264 so Electron builds with optional HEVC don't trip SRS into a
codec path Chrome never offers.
- onvif_camera: default to H.264 passthrough (was HEVC). Production
cameras already emit H.264 Baseline; the `{id}_h264` transcode path
becomes opt-in for legacy gear that can't be reconfigured. When
transcoding is on, push the `{id}_h264` path; otherwise push the
passthrough path with `-c copy`.
- recipes: cameras-jzt31.yaml now wires `remote_rtmp` against the local
SRS dev compose (1935/1985/18085); onvif-camera.yaml and
media-gateway.md updated to match.
审查者指南(Reviewer's Guide)通过调整 mediamtx 监听器配置以避免 UDP 8000 端口冲突、改变 push-to-RTMP 通过 ffmpeg 的接线方式、将 ONVIF 摄像头默认为 H.264 直通并提供可选的 H.264 转码来承载远程推流、以及更新端点生成逻辑和文档/示例,以输出真实的 SRS WHEP URL 和开发环境中 SRS 的接线,从而实现端到端的 SRS WebRTC(WHEP)支持。 文件级变更
提示与命令与 Sourcery 交互
自定义你的体验访问你的 控制面板 以:
获取帮助Original review guide in EnglishReviewer's GuideImplements end-to-end SRS WebRTC (WHEP) support by adjusting mediamtx listener configuration to avoid UDP 8000 conflicts, changing how push-to-RTMP is wired through ffmpeg, defaulting ONVIF cameras to H.264 passthrough with optional H.264 transcode carrying the remote push, and updating endpoint generation and docs/recipes to emit real SRS WHEP URLs and dev SRS wiring. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并留下了一些高层次的反馈:
render_config_unchecked函数现在内联了两段很长且大部分重复的 ffmpeg 命令字符串,分别用于转码和推流场景;建议把共享的参数(编解码器、时延调节、音频设置等)抽取成辅助构造器或常量,这样以后修改时不需要同时改两处,从而避免行为漂移的风险。should_reserve_udp_8000_for_remote当前只要任一路径设置了push_to就会保留 UDP 8000,隐含假设推流目标是 SRS;如果还有其他不需要该端口的 RTMP/RTSP 后端,你可能需要一个更明确的标志(例如reserve_webrtc_udp_for_srs),或基于 scheme/host 的检查,以避免对 mediamtx 传输施加不必要的约束。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `render_config_unchecked` function now embeds two large, mostly duplicated ffmpeg command strings for the transcode + push cases; consider factoring out shared flags (codec, latency knobs, audio settings) into helper builders or constants so future changes don’t need to touch both branches and risk drifting behaviour.
- `should_reserve_udp_8000_for_remote` currently reserves UDP 8000 whenever any path has `push_to` set, implicitly assuming push targets are SRS; if other RTMP/RTSP backends are used that don’t need this port, you may want a more explicit flag (e.g. `reserve_webrtc_udp_for_srs`) or a scheme/host check to avoid unnecessarily constraining mediamtx transports.
## Individual Comments
### Comment 1
<location path="docs/recipes/media-gateway.md" line_range="119-121" />
<code_context>
+OpenFGA `network-service` already occupies 8080. See
+`docker/docker-compose.srs.yaml`.)
+
+If your dev host port 1935/18085/1985 is taken, override via
+`SRS_RTMP_PORT` / `SRS_HTTP_PORT` / `SRS_API_PORT` in
+`docker/.env.dev`.
+
</code_context>
<issue_to_address>
**nitpick (typo):** Consider rephrasing the "dev host port 1935/18085/1985" clause for grammatical agreement and clarity.
Using singular "port" with a slash-separated list can be confusing. Consider pluralizing and listing them with commas, e.g., "If any of the dev host ports 1935, 18085, or 1985 are taken, override via ..." to improve clarity and agreement.
```suggestion
If any of the dev host ports 1935, 18085, or 1985 are taken, override via
`SRS_RTMP_PORT` / `SRS_HTTP_PORT` / `SRS_API_PORT` in
`docker/.env.dev`.
```
</issue_to_address>Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- The
render_config_uncheckedfunction now embeds two large, mostly duplicated ffmpeg command strings for the transcode + push cases; consider factoring out shared flags (codec, latency knobs, audio settings) into helper builders or constants so future changes don’t need to touch both branches and risk drifting behaviour. should_reserve_udp_8000_for_remotecurrently reserves UDP 8000 whenever any path haspush_toset, implicitly assuming push targets are SRS; if other RTMP/RTSP backends are used that don’t need this port, you may want a more explicit flag (e.g.reserve_webrtc_udp_for_srs) or a scheme/host check to avoid unnecessarily constraining mediamtx transports.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `render_config_unchecked` function now embeds two large, mostly duplicated ffmpeg command strings for the transcode + push cases; consider factoring out shared flags (codec, latency knobs, audio settings) into helper builders or constants so future changes don’t need to touch both branches and risk drifting behaviour.
- `should_reserve_udp_8000_for_remote` currently reserves UDP 8000 whenever any path has `push_to` set, implicitly assuming push targets are SRS; if other RTMP/RTSP backends are used that don’t need this port, you may want a more explicit flag (e.g. `reserve_webrtc_udp_for_srs`) or a scheme/host check to avoid unnecessarily constraining mediamtx transports.
## Individual Comments
### Comment 1
<location path="docs/recipes/media-gateway.md" line_range="119-121" />
<code_context>
+OpenFGA `network-service` already occupies 8080. See
+`docker/docker-compose.srs.yaml`.)
+
+If your dev host port 1935/18085/1985 is taken, override via
+`SRS_RTMP_PORT` / `SRS_HTTP_PORT` / `SRS_API_PORT` in
+`docker/.env.dev`.
+
</code_context>
<issue_to_address>
**nitpick (typo):** Consider rephrasing the "dev host port 1935/18085/1985" clause for grammatical agreement and clarity.
Using singular "port" with a slash-separated list can be confusing. Consider pluralizing and listing them with commas, e.g., "If any of the dev host ports 1935, 18085, or 1985 are taken, override via ..." to improve clarity and agreement.
```suggestion
If any of the dev host ports 1935, 18085, or 1985 are taken, override via
`SRS_RTMP_PORT` / `SRS_HTTP_PORT` / `SRS_API_PORT` in
`docker/.env.dev`.
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Address PR #11 review feedback. - Add `pushes_to_srs: bool` to `MediaPath` and check that flag (renamed to `should_reserve_webrtc_udp_for_srs`) instead of `push_to.is_some()` when deciding whether to free host UDP 8000. Generic RTMP relays (Twitch, YouTube, etc.) no longer trigger the gateway's TCP-only RTSP fallback. `OnvifCameraConfig::paths()` sets the flag when `remote_rtmp.webrtc_host` is configured — the unambiguous "this push feeds a server we'll also read over WHEP" signal. - Extract the libx264/AAC encoder flags into FFMPEG_H264_LOWLATENCY_- ENCODE so the rtsp-republish and direct-RTMP-push branches share one encoder string. Future tuning lands in one place instead of two. - Add a regression test contrasting SRS push (forces TCP-only) with a generic RTMP relay (transports unchanged). - docs/recipes/media-gateway.md: rephrase the dev-port-override hint.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make the optional SRS path actually work end-to-end so teammates can view cameras over WHEP. Previously the code advertised a
webrtc://host/pathURL that no client could fetch and bound mediamtx WebRTC to the same UDP port SRS needs (8000), so the two coexisted in config but never both worked at runtime.webrtc_udpListenerPort (default:8189), rendered aswebrtcLocalUDPAddress. When any path haspush_to, force RTSP TCP-only and zero out RTP/RTCP UDP to free host UDP 8000 for SRS. Always-on the source forpush_topaths so the upstream pull doesn't deadlock waiting on a local viewer.http://<webrtc_host>/rtc/v1/whep/?app=<app>&stream=<id>&codec=h264. WHEP is HTTP-POST-application/sdp; H.264 pinned so Electron builds with optional HEVC don't trip SRS into a codec path Chrome never offers.{id}_h264transcode path becomes opt-in for legacy gear that can't be reconfigured. Push the passthrough path with-c copywhen transcoding is off; otherwise push{id}_h264.cameras-jzt31.yamlnow wiresremote_rtmpagainst the local SRS dev compose (1935/1985/18085);onvif-camera.yamlandmedia-gateway.mdupdated to match.Pairs with the Xyzen team-channel SRS WebRTC PR.
Test plan
cargo check --all-featurescleancargo test --all-features— all 161 tests passcam131reaches the team-channel viewer over WHEP athttp://localhost:1985/rtc/v1/whep/?app=live&stream=cam131&codec=h264:8889/<id>/whepstill works while the camera is also pushed to SRS🤖 Generated with Claude Code
Summary by Sourcery
集成可选的 SRS RTMP/WebRTC 采集到 mediamtx 中,同时保留本地 WebRTC,并调整摄像头默认配置和文档以支持基于 H.264 直通的流媒体。
New Features:
Bug Fixes:
Enhancements:
ffmpeg直接路由到 SRS FLV/RTMP,而不再通过 mediamtxtee分路;同时将直通模式的推流保留给非转码路径。Documentation:
Original summary in English
Summary by Sourcery
Integrate optional SRS RTMP/WebRTC ingest with mediamtx while preserving local WebRTC, and adjust camera defaults and docs for H.264 passthrough-based streaming.
New Features:
Bug Fixes:
Enhancements:
Documentation: