I am trying to combine some videos in a unique output.mov. The exported file does not play, and now I do not understand why. Can anybody help me?
func exportVideo2(path:String, outputPath:String, nMovie:Int) -> Bool{ var composition = AVMutableComposition() let track:AVMutableCompositionTrack = composition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: CMPersistentTrackID()) var insertTime = kCMTimeZero var movie = movieOfProject(path) if movie.count == nMovie{ for (index,mov) in enumerate(movie){ let moviePath = path.stringByAppendingPathComponent(mov) // moviePath = path to the .mov file println(moviePath) let moviePathUrl = NSURL(fileURLWithPath: moviePath) let sourceAsset = AVURLAsset(URL: moviePathUrl, options: nil) println(sourceAsset) let tracks = sourceAsset.tracksWithMediaType(AVMediaTypeVideo) println(sourceAsset.playable) // print true println(sourceAsset.exportable) // print true println(sourceAsset.readable) // print true if tracks.count > 0{ let assetTrack:AVAssetTrack = tracks[0] as AVAssetTrack track.insertTimeRange(CMTimeRangeMake(kCMTimeZero,sourceAsset.duration), ofTrack: assetTrack, atTime: insertTime, error: nil) insertTime = CMTimeAdd(insertTime, sourceAsset.duration) } } let completeMovie = outputPath.stringByAppendingPathComponent("movie.mov") let completeMovieUrl = NSURL(fileURLWithPath: completeMovie) var exporter = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetHighestQuality) exporter.outputURL = completeMovieUrl exporter.outputFileType = AVFileTypeMPEG4 exporter.exportAsynchronouslyWithCompletionHandler(nil) let ass = AVURLAsset(URL: completeMovieUrl, options: nil) println(ass.readable) // print false println(ass.exportable) // print false println(ass.playable) // print false return true }else{ return false } }
The .mov files that I need to combine are readable, so I think the problem is in the last part where the output video is exported.
Marco source share