我想知道如何根据时间戳为AVAssetExportSession设置一个时间范围,例如:
NSTimeInterval start = [[NSDate date] timeIntervalSince1970];
NSTimeInterval end = [[NSDate date] timeIntervalSince1970];我在导出会话中使用的代码如下:
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
exportSession.outputURL = videoURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
exportSession.timeRange = CMTimeRangeFromTimeToTime(start, end);谢谢你的帮忙!
发布于 2012-05-27 18:46:44
AVAssetExportSession中的属性timeRange允许您执行资产的部分导出,指定从何处开始以及持续时间。如果没有指定,它将导出整个视频,换句话说,它将从零开始并导出总时长。
start和duration都应该用CMTime表示。
例如,如果要导出资源的前半部分:
CMTime half = CMTimeMultiplyByFloat64(exportSession.asset.duration, 0.5);
exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, half);或者是下半场:
exportSession.timeRange = CMTimeRangeMake(half, half);或结尾的10秒:
CMTime _10 = CMTimeMakeWithSeconds(10, 600);
CMTime tMinus10 = CMTimeSubtract(exportSession.asset.duration, _10);
exportSession.timeRange = CMTimeRangeMake(tMinus10, _10);有关计算所需确切时间的其他方法,请查看CMTime参考。
https://stackoverflow.com/questions/10772992
复制相似问题