diff --git a/MP42/MP42AVFImporter.m b/MP42/MP42AVFImporter.m index 5f9112b..29b14e3 100644 --- a/MP42/MP42AVFImporter.m +++ b/MP42/MP42AVFImporter.m @@ -572,6 +572,17 @@ - (NSUInteger)timescaleForTrack:(MP42Track *)track { AVAssetTrack *assetTrack = [_localAsset trackWithTrackID:track.sourceId]; + + // Prefer the asbd sample rate, naturalTimeScale might not be + // the right one if we are reading for .ts + if ([assetTrack.mediaType isEqualToString:AVMediaTypeAudio]) { + CMFormatDescriptionRef formatDescription = (CMFormatDescriptionRef)assetTrack.formatDescriptions.firstObject; + + if (formatDescription) { + const AudioStreamBasicDescription *asbd = CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription); + return asbd->mSampleRate; + } + } return assetTrack.naturalTimeScale; }