1

I have AVAssets that are portrait and landscape orientation. When I play them one at a time with the AVPlayer they play with the correct orientation. So the AVPlayer is reading each video's AVAssetTrack preferredTransform and adjusting accordingly.

On the other hand, when I add a portrait asset to a AVMutableComposition it shows up sideways. Presumably this is because the AVMutableCompositionTrack just has a default preferredTransform of CGAffineTransformIdentity.

What I want is for my AVMutableComposition to honor the preferredTransform of assets I add to it so everything shows up correctly.

Part 2

I know I can perform a video rotation by supplying compositing instructions (AVMutableVideoCompositionLayerInstructions) to an AVAssetExportSession, for example as explained here. But I don't want to export the video yet.

Is AVAssetExportSession the only class that takes AVMutableVideoComposition as an input?

Part 3

I'm trying to play a preview of the video I'm about to export, and the only compositing operation is a transform to either portrait or landscape. So I think there should be a lighter-weight way to do this, without running an AVAssetExportSession every time the user changes the mutable composition. Is this right?

Aside

As an aside, I guess I'm not understanding why AVMutableVideoComposition is not itself a descendent of AVAsset like AVMutableComposition is. Then you could just play the compostion directly.

Community
  • 1
  • 1
bcattle
  • 12,115
  • 6
  • 62
  • 82

2 Answers2

1
   AVPlayerItem * item item = [[AVPlayerItem alloc] initWithAsset:[collageComposition mutableCopy]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:item];
item.videoComposition = [collageVideoComposition mutableCopy];
[item setSeekingWaitsForVideoCompositionRendering:NO];
item.audioMix = audioMix;
self.previewPlayer = [AVPlayer playerWithPlayerItem:item];

that's all you need for a preview. If you use animationTool in your AVMutableVideoComposition AVPlayer don't suport it. Use AVSynchronizedLayer for this purpose.

DimaC
  • 426
  • 2
  • 8
  • what is **audioMix** , can you explain? – Vatsal Shukla Apr 05 '17 at 12:12
  • `AVAudioMix` is used for custom audio processing, `AVPlayerItem` property. [Here more](https://developer.apple.com/reference/avfoundation/avplayeritem/1388037-audiomix?language=objc) – DimaC Jun 01 '17 at 07:13
0

Ah, AVPlayerItem has a videoComposition property. Modifying the AVPlayerItem would be appropriate for a preview display.

bcattle
  • 12,115
  • 6
  • 62
  • 82