AVMutableComposition drops portion of audio track

Number:rdar://FB8742994 Date Originated:2020-09-25
Status:Open Resolved:
Product:AVFoundation Product Version:
Classification:Bug Reproducible:
When adding the contents of an AVURLAsset to an AVComposition using either of the following methods:

- [composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration) ofAsset:asset atTime:kCMTimeZero error:&error];
- [compositionTrack insertTimeRange:track.timeRange ofTrack:track atTime:kCMTimeInvalid error:&error];

And then exporting the asset through AVAssetExportSession, the resulting asset is missing some portion of the beginning of the audio track. On some assets, the effect is more drastic than others, and causes the audio and video to appear out of sync.

We can see this issue compound by running the same export 25 times in a row, using the output of the previous operation as the input to the next.

Per ffprobe, the original asset has the following durations:
- Video: 15.015000
- Audio: 15.000000

After one export, this is the result:
- Video: 15.015000
- Audio: 14.952109

After 25 export, this is the result:
- Video: 15.015000
- Audio: 13.802698

Could this be a result of AAC priming being dropped?

This reproduces on iOS 13 and 14.


Thanks -- I actually had that set already, however. There doesn't seem to be a difference with it present versus not.

By cellsworth at Nov. 18, 2020, 7:59 p.m. (reply...)

Could you please modify your laod of asset to something like below and test again? (please convert to to obj-c if required)

let options: [String: Any] = [AVURLAssetPreferPreciseDurationAndTimingKey: true]

let layerAsset: AVURLAsset = AVURLAsset(url: layerURL, options: options)

I had a similar issue and by adding AVURLAssetPreferPreciseDurationAndTimingKey: YES I had the problem sorted.

By pepa.amorim at Oct. 23, 2020, 10:03 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!