您的“慢动作”视频文件实际上只是具有高帧率的视频文件。iOS 正在降低播放速率,以慢动作的形式展示多余的帧。问题是其他播放器以 1 的播放速率播放,因此要使效果可移植,您需要改为修改帧呈现时间戳。
您可能可以使用 an 来执行此操作,AVMutableComposition
但我更喜欢使用所见即所得AVAssetReader
/AVAssetWriter
对。输入文件中的每一帧都是这样的:
if let inSampleBuffer = readerOutput.copyNextSampleBuffer() {
let inTimeStamp = CMSampleBufferGetPresentationTimeStamp(inSampleBuffer)
let outTimeStamp = CMTimeMultiplyByFloat64(inTimeStamp, 240.0/30) // slow 240 fps down to 30fps (8x slowmo)
var outSampleBuffer: CMSampleBuffer?
var outTimingInfo = CMSampleTimingInfo(duration: kCMTimeInvalid, presentationTimeStamp: outTimeStamp, decodeTimeStamp: kCMTimeInvalid)
if CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault, inSampleBuffer, 1, &outTimingInfo, &outSampleBuffer) == noErr {
writerInput.appendSampleBuffer(outSampleBuffer!)
}
} else {
// finished
}