Reputation: 1
As long as I add the original audio track in the video, an error "Invalid sample cursor, or sample out of range" will be reported when exporting.
var audioInputParams: [AVMutableAudioMixInputParameters] = []
for audioTrack in audioTracks {
guard let track = mixComposition.addMutableTrack(withMediaType: .audio, preferredTrackID: kCMPersistentTrackID_Invalid) else {
continue
}
let audioTimeRange: CMTimeRange = .init(start: .zero, duration: audioTrack.timeRange.duration)
try track.insertTimeRange(audioTimeRange, of: audioTrack, at: .zero)
track.preferredTransform = audioTrack.preferredTransform
let audioInputParam = AVMutableAudioMixInputParameters(track: track)
audioInputParam.setVolumeRamp(fromStartVolume: factor.volume, toEndVolume: factor.volume, timeRange: audioTimeRange)
audioInputParam.trackID = track.trackID
audioInputParams.append(audioInputParam)
}
When I decrease the duration of audioTimeRange by 1 second it just works fine
let audioTimeRange: CMTimeRange = .init(start: .zero, duration: .init(seconds: audioTrack.timeRange.duration.seconds - 1, preferredTimescale: audioTrack.timeRange.duration.timescale))
Some videos are normal, and some videos are wrong. I checked the timeRange of the video track vs the audio track, they are all the same The video of the error is here: Video
I've searched a lot, but no one has the same error as me
Upvotes: 0
Views: 970