Skip to content

Commit b842860

Browse files
bmatherlyddennedy
authored andcommitted
Fix #1156 Crackling sound when cutting pcm_s24le in mkv
For the provided test clip, Libav provides an audio timebase of 1000 ticks per second for the PTS. However, the sample rate is 48000 samples per second. That means each pts tick represents 48 audio samples. The PTS calculation is drived from muliple calculations including the profile frame rate. Those calculations create opportunities for rounding errors in the sample calculation. In this case, after an initial synchornization, the PTS calculation still would occasionally find an offset of 1 tick. This change essentially changes the synchronization to not take action unless the offset is greater than 1 tick. When it does take action to synchronize, it uses all the precision that it has.
1 parent 7707aac commit b842860

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/modules/avformat/producer_avformat.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3347,7 +3347,11 @@ static int decode_audio(producer_avformat self,
33473347

33483348
if (req_pts > pts) {
33493349
// We are behind, so skip some
3350-
*ignore = lrint(timebase * (req_pts - pts) * codec_context->sample_rate);
3350+
int sample_error_margin = ceil(timebase * codec_context->sample_rate);
3351+
int sample_delta = lrint(timebase * (req_pts - pts) * codec_context->sample_rate);
3352+
if (sample_delta > sample_error_margin) {
3353+
*ignore = sample_delta;
3354+
}
33513355
} else if (self->audio_index != INT_MAX && int_position > req_position + ahead_threshold
33523356
&& !self->is_audio_synchronizing) {
33533357
// We are ahead, so seek backwards some more.

0 commit comments

Comments
 (0)