2014-03-05 16 views
3

我正在使用AVFoundation僅使用音頻 - 即無視頻 - 並試圖將多個AVComposition一個接一個地連接在一起,最終以單個AVComposition結尾。嘗試將AVComposition的時間範圍插入到AVMutableComposition時出錯-11800

示例:僅兩個AVComposition s。他們每個人都扮演着由從而創建一個AVPlayer罰款:

_player = [AVPlayer playerWithPlayerItem:[AVPlayerItem playerItemWithAsset:comp]] 

其中compAVMutableComposition一個實例。 (順便說一句,這是值得注意的是,_player必須是伊娃否則ARC過早地釋放它,它起着前 - 花了一段時間來跟蹤一個向下)

那好 - 執行

[_player play] 

結果comp正在播放成功。

然而,這種失敗:

self.segmentsNSMutableArray含有元素是AVMutableComposition定製子類)

AVMutableComposition *comp = [AVMutableComposition composition]; 
NSError *err; 
for (AVMutableComposition* c in self.segments) { 
    [comp insertTimeRange:CMTimeRangeMake(kCMTimeZero, segment.duration)  
        ofAsset:segment atTime:comp.duration error:&err]; 
    DLog(@"Error was %@", segment, err); 
} 

對於self.segments每個元素代碼執行時,出現此錯誤時調用insertTimeRange::::方法:

Error was Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not 
be completed" UserInfo=0x14e8e7f0 {NSLocalizedDescription=The operation could not be 
completed, NSUnderlyingError=0x14d7f580 "The operation couldn’t be completed. (OSStatus 
error -12780.)", NSLocalizedFailureReason=An unknown error occurred (-12780)} 

我找不到任何inf關於這個錯誤表明什麼的信息 - 似乎只是一個全面的 - 我看不出我做錯了什麼。有任何想法嗎?

+0

我剛剛嘗試過使用for循環和objectAtIndex:而不是快速枚舉self.segments NSMutableArray,它沒有什麼不同。 –

+1

你有沒有想過?我遇到了一個非常類似的問題(不過,視頻不僅僅是音頻 - 錯誤號碼也略有不同,AVFoundationErrorDomain代碼= -11801和'(OSStatus 錯誤-12786。)') – Hugo

+0

嘗試使用:fileURLWithPath改爲的:urlwithstring – Nik

回答

0

在我的情況下,我輸入錯誤的CMTimeRange,持續時間爲0,因爲CMTimeMake會將輸入轉換爲整數,然後失去精度。

爲了解決這個問題,我使用了更大的時間尺度。

問題代碼:

CMTime startTime = CMTimeMake(timeStamp.begin, 1); 
CMTime duration = CMTimeMake(timeStamp.duration, 1); 

權代碼:

CMTime startTime = CMTimeMake(timeStamp.begin*1000, 1000); 
CMTime duration = CMTimeMake(timeStamp.duration*1000, 1000); 

然後它的權利。

[videoTrack insertTimeRange:CMTimeRangeMake(startTime, duration) ofTrack:videoTracks.firstObject atTime:kCMTimeZero error:&error]; 
相關問題