0
我正在使用AVFoundation框架。我只是想添加三個視頻合併爲一個視頻,但問題是我無法添加三個視頻。我想知道我們可以使用AVMutableComposition添加多少視頻。是否允許添加2個以上的視頻。任何幫助?AVMutableComposition不允許添加4個視頻軌道
這裏是我的代碼
/////////////////////////////////////////////
// Add video tracks 1 to mutable compositon//
/////////////////////////////////////////////
let firstTrack = compostion.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: Int32(kCMPersistentTrackID_Invalid))
do{
try firstTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset1.duration),
ofTrack: videoAsset1.tracksWithMediaType(AVMediaTypeVideo)[0], atTime: kCMTimeZero)
}
catch{
print("failed to add first track")
}
print("Time to add 1 track\(CMTimeGetSeconds(videoAsset1.duration))")
/////////////////////////////////////////////
// Add video tracks 2 to mutable compositon//
/////////////////////////////////////////////
let secondTrack = compostion.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: Int32(kCMPersistentTrackID_Invalid))
do{
try secondTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset2.duration),
ofTrack: videoAsset2.tracksWithMediaType(AVMediaTypeVideo)[0], atTime: videoAsset1.duration)
}
catch{
print("failed to add second track")
}
print("Time to add second track\(CMTimeGetSeconds(videoAsset2.duration))")
/////////////////////////////////////////////
// Add video tracks 3 to mutable compositon//
/////////////////////////////////////////////
let thirdTrack = compostion.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: Int32(kCMPersistentTrackID_Invalid))
do{
try thirdTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset3.duration), ofTrack: videoAsset3.tracksWithMediaType(AVMediaTypeVideo)[0], atTime: videoAsset2.duration)
}
catch{
print("failed to add third track")
}
謝謝,很好的回答。但我以前解決過這個問題。這是我的錯誤。 – varinder