gpt4 book ai didi

ios - 如何从 Asset 中获取慢动作视频的文件 Url?

转载 作者:行者123 更新时间:2023-12-04 11:33:15 61 4
gpt4 key购买 nike

我正在获取普通视频的文件 url,但慢动作视频 Assets 类型是 AVComposition .我正在尝试 AVAssetExportSession但它消耗大量时间。

PHVideoRequestOptions *options=[[PHVideoRequestOptions alloc] init];
options.version = PHVideoRequestOptionsVersionCurrent;
options.networkAccessAllowed = YES;

[[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset *avAsset, AVAudioMix *audioMix, NSDictionary *info) {

if(([avAsset isKindOfClass:[AVComposition class]] && ((AVComposition *)avAsset).tracks.count == 2)) {

//Output URL of the slow motion file.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = paths.firstObject;
NSString *myPathDocs = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"mergeSlowMoVideo-%d.mov",arc4random() % 1000]];
NSURL *url = [NSURL fileURLWithPath:myPathDocs];

//Begin slow mo video export
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL = url;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.shouldOptimizeForNetworkUse = YES;

[exporter exportAsynchronouslyWithCompletionHandler:^{

dispatch_async(dispatch_get_main_queue(), ^{
if (exporter.status == AVAssetExportSessionStatusCompleted) {
}
});
}];
} else if ([avAsset isKindOfClass:[AVURLAsset class]]) {
}
}];

最佳答案

PHImageRequestOptions.version属性的默认值为 PHImageRequestOptionsVersionCurrent .
只需将版本分配给 PHImageRequestOptionsVersionUnadjustedPHImageRequestOptionsVersionOriginal将返回原始慢动作视频。

PHImageRequestOptions * options = [[PHImageRequestOptions alloc] init];

options.version = PHImageRequestOptionsVersionUnadjusted;
// or
options.version = PHImageRequestOptionsVersionOriginal;
希望这对某人有用。

关于ios - 如何从 Asset 中获取慢动作视频的文件 Url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45459059/

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