我有一个可以加载到 AVAsset 的视频文件。我想改变这个视频的播放速度并加倍它的速度,这样如果视频是 10 秒长,它会加速在 5 秒内完成。
这是我正在尝试的代码,有人可以告诉我哪里出错了吗?
帧持续时间是我实现目标所需的属性。
AVAsset *anAsset = self.moviePlayer.currentItem.asset;
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:anAsset];
if ([compatiblePresets containsObject:AVAssetExportPreset640x480]) {
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
initWithAsset:anAsset presetName:AVAssetExportPreset640x480];
// Implementation continues.
NSString *tmpStr = [[aclip selectedTakeUrl] stringByReplacingOccurrencesOfString:@".m4v" withString:@""];
NSString *filePath = [NSString stringWithFormat:@"%@_applied.m4v", tmpStr];
exportSession.outputURL = [NSURL fileURLWithPath:filePath];
AVMutableVideoComposition *vidcomp = [AVMutableVideoComposition videoCompositionWithPropertiesOfAsset:anAsset];
vidcomp.frameDuration = CMTimeMake(1, 24);
//self.moviePlayer.currentItem.videoComposition = vidcomp;
exportSession.videoComposition = vidcomp;
//exportSession.videoComposition.frameDuration = CMTimeMake(1, 50);
// what is the song URL before loading startRecordingViewController?
NSLog(@"From Save settgins Choose Song -Song URL : %@", exportSession.outputURL);
// NSLog(@"start time%f, end time %f", CMTimeGetSeconds(self.startTime),CMTimeGetSeconds(self.endTime));
exportSession.outputFileType = AVFileTypeMPEG4;
//CMTimeRange range = CMTimeRangeMake(CMTimeMake(0.0, 1), CMTimeMake(diffTime/currentround,1));
// startTime and endTime is the duration that we need to save.
//exportSession.timeRange = range;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status]) {
case AVAssetExportSessionStatusCompleted:
NSLog(@"Export Completed");
break;
case AVAssetExportSessionStatusWaiting:
NSLog(@"Export Waiting");
break;
case AVAssetExportSessionStatusExporting:
NSLog(@"Export Exporting");
break;
case AVAssetExportSessionStatusFailed:
{
NSError *error = [exportSession error];
NSLog(@"Export failed: %@", [error localizedDescription]);
break;
}
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
default:
break;
}
dispatch_async(dispatch_get_main_queue(), ^{
//[activityIndicator stopAnimating];
//CMTime range = CMTimeSubtract(self.endTime, self.startTime);
//NSUInteger theLength = (int)CMTimeGetSeconds(range);
//[ self.songPickedDelegate songPickerDidMakeSelection:self.songTitle :self.audioPath :theLength];
});
//[exportSession release];
}];
}