2012-05-27 48 views
4

我想知道如何从时间标记,如做一个时间范围AVAssetExportSession创建一个时间范围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); 

感谢您的帮助!

回答

11

AVAssetExportSession中的属性timeRange允许您执行资产的部分导出,指定资产的起始位置和持续时间。如果未指定,则会导出整个视频,换句话说,它将从零开始并导出总持续时间。

开始时间和持续时间应该表示为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参考其他方法来计算您需要的确切时间。

+0

非常感谢!全部排序。唯一的问题是CMTimeMakeWithSeconds需要有两个参数。所以第二个参数只是首选的时间尺度。 – user1273431

+0

Opps,固定。这发生在文本区域编写代码w/out实时语法检查:) – djromero