音频慢动作,如使用240FPS的默认Slo-Mo相机功能

时间:2014-09-20 11:24:46

标签: ios objective-c audio video avmutablecomposition

我想在相机中实现慢动作视频,例如Slo-Mo的Defalut功能,我使用了以下代码,它适用于视频。 但在音频轨道中该视频无法正常工作。

   double videoScaleFactor =8.0;


 compositionAudioTrack scaleTimeRange:CMTimeRangeMake(kCMTimeZero, videoDuration)
                                     toDuration:CMTimeMake(videoDuration.value* videoScaleFactor,videoDuration.timescale)];
 [compositionVideoTrack scaleTimeRange:CMTimeRangeMake(kCMTimeZero, videoDuration)
   toDuration:CMTimeMake(videoDuration.value* videoScaleFactor, videoDuration.timescale)];

 this scenario is woking properly for video slowmotion.But in audio slow-motion it is not working...

请帮帮我..

1 个答案:

答案 0 :(得分:7)

我找到了Audio SlowMotion的解决方案

double videoScaleFactor = 8.0;

[compositionAudioTrack scaleTimeRange:CMTimeRangeMake(kCMTimeZero,videoDuration)                                      toDuration:CMTimeMake(videoDuration.value * videoScaleFactor,videoDuration.timescale)];

它正常工作但不能在AVPlayer中工作 所以你必须设置AVPlayerItem的以下属性

AVPlayerItem * playerItem = nil;

playerItem.audioTimePitchAlgorithm = AVAudioTimePitchAlgorithmVarispeed;