为AVAssetExportSession创建时间范围

use*_*431 6 iphone time ios cmtime avassetexportsession

我想知道如何为AVAssetExportSession时间戳制作时间范围,例如:

NSTimeInterval start = [[NSDate date] timeIntervalSince1970];
NSTimeInterval end = [[NSDate date] timeIntervalSince1970];
Run Code Online (Sandbox Code Playgroud)

我用于导出会话的代码如下:

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];

exportSession.outputURL = videoURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
exportSession.timeRange = CMTimeRangeFromTimeToTime(start, end);
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!

djr*_*ero 13

该酒店timeRangeAVAssetExportSession允许你做一个资产指定的部分出口从哪里开始和持续时间.如果没有指定它将导出整个视频,换句话说,它将从零开始并将导出总持续时间.

开始和持续时间都应表示为CMTime.

例如,如果要导出资产的前半部分:

CMTime half = CMTimeMultiplyByFloat64(exportSession.asset.duration, 0.5);
exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, half);
Run Code Online (Sandbox Code Playgroud)

或下半场:

exportSession.timeRange = CMTimeRangeMake(half, half);
Run Code Online (Sandbox Code Playgroud)

或者最后10秒:

CMTime _10 = CMTimeMakeWithSeconds(10, 600);
CMTime tMinus10 = CMTimeSubtract(exportSession.asset.duration, _10);
exportSession.timeRange = CMTimeRangeMake(tMinus10, _10);
Run Code Online (Sandbox Code Playgroud)

检查CMTime参考以了解计算所需精确时间的其他方法.