Repository navigation
recorder: fix timestamps of MPEG-1/2 Audio tracks in fMP4 recordings - #6361
Merged
Merged
Conversation
The DTS of every sample was computed as the unit PTS plus the unit PTS, so sample durations in the recording were twice the real ones, and the frames of a unit that holds several of them got the same timestamp. Advance the PTS by the duration of each frame instead, and move the NTP of each frame by the same offset, as the Opus, MPEG-4 Audio and AC-3 cases do.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6361 +/- ##
==========================================
+ Coverage 70.97% 71.14% +0.16%
==========================================
Files 282 282
Lines 21611 21610 -1
==========================================
+ Hits 15339 15374 +35
+ Misses 6272 6236 -36 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
merged, thanks! |
Contributor
|
This issue is mentioned in release v1.21.3 🚀 |
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.
A path has
record: yesandrecordFormat: fmp4(the default), and a client publishes MP3 or MP2 audio. The recorder writes every sample with a DTS of twice the PTS, so recorded time runs twice as fast as absolute time. After 5 seconds the drift check informatFMP4Track.writefires, the log showsdetected drift between recording duration and absolute time, resetting, and the segment is closed; a new one starts 2 seconds later. A 20 second stream gives three files, each with about 5 seconds of audio that it says lasts about 10, and the audio between them is lost. Inside each file a 44.1 kHz sample is 4702 ticks long instead of 2351, and when a unit holds several frames, all but the last get a duration of 0.Cause: the MPEG-1/2 Audio case computes
dts: u.PTS + u.PTS(format_fmp4.go#L752). Adtthat adds up the frame durations is declared at L732 and updated per frame but never read. This came with #2925 (v1.5.0), which moved the other codecs toPTS + dtand wrotePTS + PTShere; before it, this case useddts: ptswith a per-frame advance. Since the drift reset of #5239 (v1.15.5), the doubled time also cuts the recording.Fix: keep a
ptsthat starts at the unit PTS and moves forward by each frame's length in clock rate ticks, and use it as the DTS. The NTP of each frame moves by the same offset, as in the Opus, MPEG-4 Audio and AC-3 cases. The RTMP muxer already steps through these frames the same way.The new
TestRecorderFMP4MPEG1AudioDurationis shaped likeTestRecorderFMP4H264RecoveryPoint. It records three units of two frames each, reads the parts back withfmp4.Parts.Unmarshal, and checks that the five samples last 2351 ticks.Before the fix the test fails with
expected: 0x92f,actual : 0x0. After it, the test passes (-count=10), and the package passes with-race. Putting back any one of the three DTS changes fails it again.No open PR touches this case. #5714, #5984 and #6305 also edit
recorder_test.go, and none conflicts with this change.