gpt4 book ai didi

ios - 使用 AVAssetExportSession 保存视频时如何提高视频速度

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:46:55 26 4
gpt4 key购买 nike

我有一个可以加载到 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];
}];
}

最佳答案

您可以使用 -[AVMutableCompositionTrack scaleTimeRange:toDuration:] 将整个 Assets 从 10 秒缩放到 5 秒。 frameDuration 属性将简单地执行帧速率转换。

关于ios - 使用 AVAssetExportSession 保存视频时如何提高视频速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21084047/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com