From 6ea6c84805cfd9c2804f3988543ce566cf209fe9 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Mon, 19 Sep 2016 15:18:47 +0200 Subject: [PATCH] Fix audio from AVFoundation ts. --- MP42/MP42AVFImporter.m | 11 +++++++++++ 1 file changed, 11 insertions(+) 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; }