2012-05-27 50 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