I am recording videos with AVcapture and playing them in an AVplayer.
NSURL *videoUrl1 = [self.mediaInfo objectAtIndex:0];
AVURLAsset *videoAsset1 = [AVURLAsset URLAssetWithURL:videoUrl1 options:nil];
NSURL *videoUrl2 = [self.mediaInfo objectAtIndex:1];
AVURLAsset *videoAsset2 = [AVURLAsset URLAssetWithURL:videoUrl2 options:nil];
AVAssetTrack *videoTrack1 = [[videoAsset1 tracksWithMediaType:AVMediaTypeVideo]objectAtIndex:0];
AVAssetTrack *videoTrack2 = [[videoAsset2 tracksWithMediaType:AVMediaTypeVideo]objectAtIndex:0];
both tracks are put together:
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, video1) ofTrack:videoTrack1 atTime:kCMTimeZero error:nil];
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, video2) ofTrack:videoTrack2 atTime:(compositionVideoTrack.timeRange.duration) error:nil];
and played:
AVPlayerItem * newPlayerItem = [AVPlayerItem playerItemWithAsset:self.composition];
//newPlayerItem.videoComposition = mainCompositionInst;
self.mediaPlayer = [AVPlayer playerWithPlayerItem:newPlayerItem];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.mediaPlayer];
[[self view].layer insertSublayer:self.playerLayer atIndex:0];
self.playerLayer.frame = [self view].layer.bounds;
self.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill ;
[self playItem];
The strange thing is that the preferredTransform of the initial AVURLAsset is different from the AVAssetTrack for the exact same file:
AVURLASSET
txf.a = 1.000000 txf.b = 0.000000 txf.c = 0.000000 txf.d = 1.000000 txf.tx = 0.000000 txf.ty = 0.000000
AVAssetTrack
txf.a = 0.000000 txf.b = 1.000000 txf.c = -1.000000 txf.d = 0.000000 txf.tx = 480.000000 txf.ty = 0.000000
Any help to solve this rotation would be much appreciated, thanks in advance.
CL