Add SRT Stream Persistence with Silence Generation #4832
+869
−14
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
This PR implements a new feature that maintains stream continuity when SRT publishers disconnect temporarily. Instead of terminating the stream, MediaMTX now generates silence for audio tracks, keeping consumers connected until the publisher reconnects.
Motivation
In production streaming environments, brief network interruptions can cause SRT publishers to disconnect, forcing all consumers to reconnect and disrupting the viewing experience. This feature addresses this issue by maintaining stream availability during temporary disconnections.
Changes
Core Features
srtPersistOnDisconnect(default:false)srtPersistTimeout(default:20m)Technical Implementation
SilenceGeneratorclass ininternal/stream/silence_generator.gointernal/core/path.goto handle persistenceinternal/conf/path.goUsage
YAML Configuration
API Configuration
REST API Examples
Behavior
When SRT Publisher Disconnects (persistence enabled)
"SRT publisher disconnected, maintaining stream with silence generation for 20m"When SRT Publisher Reconnects
"SRT publisher reconnecting, stopping silence generation"When Timeout Expires (no reconnection)
"SRT persistence timeout reached, closing stream"Testing
Test Scripts Included
test_srt_persistence_api.sh- API functionality verificationtest_srt_persistence.sh- Full feature demonstrationexample_srt_persistence.yml- Example configurationDocumentation
SRT_PERSISTENCE_README.md)Breaking Changes
None. The feature is disabled by default and fully backward compatible.
Files Changed
internal/stream/silence_generator.go- New silence generation logicinternal/core/path.go- Path persistence managementinternal/conf/path.go- Configuration supportmediamtx.yml- Updated default configurationexample_srt_persistence.yml- Example configurationSRT_PERSISTENCE_README.md- Feature documentationUse Cases
Performance Impact
Future Improvements
Related Issues
This feature addresses common production issues with SRT streaming:
Compatibility