更新时间:2023-02-16 21:18:18
AVAssetExportSession timeRange
/ code>允许您对资产进行部分导出,指定从哪里开始和持续时间。如果没有指定它将导出整个视频,换句话说,它将从零开始并将导出总持续时间。
The property timeRange
in AVAssetExportSession
allows you to do a partial export of an asset specifying where to start and which duration. If not specified it'll export the whole video, in other words, it'll start at zero and will export the total duration.
应该表示开始和持续时间as CMTime
。
Both start and duration should be expressed as CMTime
.
例如,如果您想要导出资产的前半部分:
For instance, if you want to export the first half of the asset:
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
其他计算方法的参考你需要的确切时间。
Check CMTime
reference for other ways to calculate the exact timing you need.