This repository was archived by the owner on Apr 16, 2026. It is now read-only.
Force audio rate to 90khz to comply with rtsp spec#74
Open
wltechblog wants to merge 6 commits into
Open
Conversation
This patch implements comprehensive RTSP timestamp normalization for perfect audio/video sync: 1. Audio frame timestamp improvements: - Added timestamp field back to H264NALUnit structure - Start timestamps at zero instead of the raw encoder value - Calculate precise frame durations based on sample rate - Switch to microsecond precision for better accuracy 2. Video timestamp normalization: - Base timestamps from a zero reference point - Handle cases with missing or zero timestamps - Add small increments for frames in the same batch - Avoid zero and negative timestamps 3. Timestamp tracking infrastructure: - Added base_timestamp and timestamp_initialized fields to streams - Store the first timestamp as reference for normalization - Reset timestamp on new connections - Proper initialization in constructors 4. Better error handling: - Drop oversized frames instead of partial delivery - Start with non-zero timestamps to avoid player errors - Enhanced first frame handling This approach ensures timestamps for both audio and video start from zero and increment in perfect synchronization, preventing any A/V sync issues in players like mpv.
This commits addresses several critical issues with RTSP stream synchronization: 1. Non-Zero Stream Start Time: - Streams were starting at arbitrary large timestamps (around 30000+ seconds) - Now normalized to start from zero for proper player compatibility 2. Audio/Video Sync Drift: - Added base_timestamp and timestamp_initialized fields to both streams - First frame timestamp is now exactly zero for clean synchronization - Implemented independent timestamp resets to prevent long-term drift 3. Frame Handling and Buffer Management: - Added 1ms frame pacing delay for regular frames - Added 3ms delay for larger I-frames to prevent network buffer overflows - Improved detection and handling of oversized frames - Added frame drop tracking and error reporting 4. AudioReframer Improvements: - Modified to use precise frame duration calculations with high precision - Implemented periodic timestamp reset (every 300 frames) - Better timestamp normalization for consistent audio timing These changes together create a robust synchronization system that maintains proper A/V sync across different players and network conditions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
… duration calculation
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Reference https://datatracker.ietf.org/doc/html/rfc6416#:~:text=default%20value%20of-,90,-kHz%2C%20unless%20specified