srs/trunk
Jacob Su 30ea67f5f2 MP4 DVR: Fix audio/video synchronization issues in WebRTC recordings. v6.0.172 v7.0.52 (#4230)
Fixes #3993 - WebRTC streams recorded to MP4 via DVR exhibit audio/video
synchronization issues, with audio typically ahead of video. **Note:
This issue is specific to MP4 format; FLV recordings are not affected.**

When WebRTC streams are converted to RTMP and then muxed to MP4, the
audio and video tracks may start at different timestamps. The MP4 muxer
was not accounting for this timing offset between the first audio and
video samples in the STTS (Sample Time-to-Sample) table, causing the
tracks to be misaligned in the final MP4 file.

Introduces `SrsMp4DvrJitter` class specifically for MP4 audio/video
synchronization:

- **Timestamp Tracking**: Records the DTS of the first audio and video
samples
- **Offset Calculation**: Computes the timing difference between track
start times
- **MP4 STTS Correction**: Sets appropriate `sample_delta` values in the
MP4 STTS table to maintain proper A/V sync

- Added `SrsMp4DvrJitter` class in `srs_kernel_mp4.hpp/cpp`
- Integrated jitter correction into `SrsMp4SampleManager::write_track()`
for MP4 format only
- Added comprehensive unit tests covering various timing scenarios
- **Scope**: Changes are isolated to MP4 kernel code and do not affect
FLV processing

This fix ensures that MP4 DVR recordings from WebRTC streams maintain
proper audio/video synchronization regardless of the relative timing of
the first audio and video frames, while leaving FLV format processing
unchanged.

---------

Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: john <hondaxiao@tencent.com>
Co-authored-by: winlin <winlinvip@gmail.com>
Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-08-12 09:54:29 -04:00
..
3rdparty Feature: Support HLS with fmp4 segment for HEVC/LLHLS. v7.0.51 (#4159) 2025-08-11 20:55:06 -04:00
auto fix srt cmake 4.x compiling error. v7.0.52 (#4431) 2025-08-12 08:32:36 -04:00
conf fix rtc listen port conflict for origin2/3 conf (#4186) 2025-08-11 21:33:51 -04:00
doc MP4 DVR: Fix audio/video synchronization issues in WebRTC recordings. v6.0.172 v7.0.52 (#4230) 2025-08-12 09:54:29 -04:00
etc/init.d Squash: Fix bugs 2022-01-13 18:26:28 +08:00
gdb The identifier "ShowCouroutines" needs to be modified to "ShowCoroutines" in order to rectify the typographical error. v6.0.63 (#3703) 2023-07-27 08:12:39 +08:00
ide/srs_clion NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
modules Moduels: Refine the description 2021-04-21 11:18:35 +08:00
packaging Windows: Refine cygwin pipeline (#3260) 2022-11-21 14:32:26 +08:00
research Player: Get codec by webrtc api: pc.getStats. v7.0.42 (#4310) 2025-06-04 10:28:46 -04:00
scripts AI: Add guide for Augment. (#4404) 2025-06-27 07:23:45 -04:00
src MP4 DVR: Fix audio/video synchronization issues in WebRTC recordings. v6.0.172 v7.0.52 (#4230) 2025-08-12 09:54:29 -04:00
usr/lib/systemd/system Squash: Support RPM. Fix bugs. 2021-11-04 07:37:17 +08:00
.gitignore rtc2rtmp: Support RTC-to-RTMP remuxing with HEVC. v7.0.43 (#4349) 2025-07-03 08:24:42 -04:00
AUTHORS.md Update CHANGELOG for #4309. v7.0.31 2025-04-26 06:58:00 -04:00
AUTHORS.txt Update AUTHORS 2021-08-25 07:43:35 +08:00
configure Feature: Support HLS with fmp4 segment for HEVC/LLHLS. v7.0.51 (#4159) 2025-08-11 20:55:06 -04:00
Dockerfile.builds Refine code and add tests for #4289. v7.0.45 (#4412) 2025-07-04 17:26:12 -04:00
Dockerfile.cov Asan: Refine asan warning message for macOS. 2022-12-31 21:20:51 +08:00
Dockerfile.pkg Merge branch v5.0.103 into develop 2022-12-03 21:15:22 +08:00
Dockerfile.test NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00