1

我已经录制了一个视频并将其保存到文档目录中。现在我想将视频编辑为慢速、快速或正常速度。我可以做到快速和正常的视频速度。但我不能做慢速视频。它总是转换为正常速度。这是我的代码

    AVMutableComposition *composition = [AVMutableComposition composition];
    AVURLAsset * sourceAsset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:inputVideoPath] options:nil];
    AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
    BOOL ok = NO;

    AVAssetTrack * sourceVideoTrack = [[sourceAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];

    CMTimeRange x = CMTimeRangeMake(kCMTimeZero, [sourceAsset duration]);

    ok = [compositionVideoTrack insertTimeRange:x ofTrack:sourceVideoTrack  atTime:kCMTimeZero error:nil];
    CMTime fiveSecondsIn;
    if([Cell.text isEqualToString:@"Fast"]){
        fiveSecondsIn = CMTimeMake(10,1);
    }
    else if([Cell.text isEqualToString:@"Normal"]){
        fiveSecondsIn = CMTimeMake(1,1);
    }
    else if([Cell.textLabel.text isEqualToString:@"Slow"]){
        fiveSecondsIn = CMTimeMake(1,.5);
    }


    CMTimeRange video_timeRange = CMTimeRangeMake(kCMTimeZero,sourceAsset.duration);


    [compositionVideoTrack  scaleTimeRange:video_timeRange toDuration:fiveSecondsIn];


    if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
         [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
    }

    NSURL    *exportUrl = [NSURL  fileURLWithPath:filePath];
    AVAssetExportSession *exporter = [[AVAssetExportSession alloc]initWithAsset:composition presetName:AVAssetExportPresetHighestQuality];
    exporter.outputURL=exportUrl;
    exporter.outputFileType = @"com.apple.quicktime-movie";
    [exporter exportAsynchronouslyWithCompletionHandler:^(void){

       [self performSelectorOnMainThread:@selector(playnewVideo) withObject:nil waitUntilDone:NO];

    }];
4

0 回答 0