Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-fade within AVMutableVideoComposition

I have successfully composed an AVMutableComposition with multiple video clips and can view it and export it, and I would like to be able to transition between them using a cross-fade, so I want to use AVMutableVideoComposition. I can't find any examples on how to even arrange and play a couple AVAsset videos in succession. Does anyone have an example of how to add tracks to an AVMutableVideoComposition with the equivalent of AVMutableComposition's insertTimeRange, or how to set up a cross-fade?

[self.composition insertTimeRange:CMTimeRangeMake(kCMTimeZero,asset.avAsset.duration)
                                         ofAsset:asset.avAsset
                                          atTime:self.composition.frameDuration
                                           error:nil]
like image 808
Peter DeWeese Avatar asked Sep 30 '10 13:09

Peter DeWeese


1 Answers

I found an example called AVEditDemo from Apple's WWDC 2010 Sample Code.

https://developer.apple.com/library/ios/samplecode/AVCustomEdit/Introduction/Intro.html

There is a lot of detail in the sample, but I'll summarize: You need to use both AVMutableComposition and AVMutableVideoComposition. Add tracks individually to AVMutableComposition instead of with the simpler insertTimeRange, as it allows you to set overlapping times on the tracks. The tracks also need to be added to the AVMutableVideoComposition as AVMutableVideoCompositionLayerInstructions with an opacity ramp. Finally, to play back in an AVPlayer, you need to create an AVPlayerItem using both the AVMutableComposition and AVMutableVideoComposition.

It seems like going each level deeper in the api – in this case from MPMoviePlayer with an asset to AVPlayer with an AVComposition and finally to an AVVideoComposition – increases necessary coding exponentially.

like image 82
Peter DeWeese Avatar answered Sep 28 '22 14:09

Peter DeWeese