views:

119

answers:

1

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]
+1  A: 

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

http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?code=y&source=x&bundleID=20645

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.

Peter DeWeese
Peter, I've installed and run this application. I'm wondering, how do you get clips into the application to test it out?
Sean Seefried
I didn't try to get the "File Sharing" view to work in that demo, as in my app I modified some of that code and used a UIImagePickerController to get clips in. It looks like it is using any clips in NSDocumentDirectory, so if you can get them into there, they should show up.
Peter DeWeese