0

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

Zeretyh
  • 17
  • 1
  • 6
  • I have same problem. Can you say me how you resolved that? – Gaby Fitcal Aug 18 '15 at 08:06
  • It was quite hard to solve the issue, I suggest to read all this to understand how AVfoundation [link](https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/AVFoundationPG.pdf) Also, note that depending on the os and phone model you'll get different results, so in ly case i had to identify the phone model and apply the necessary transforms.good luck! – Zeretyh Aug 18 '15 at 08:51

1 Answers1

0

Create video Composition

vidComposition = [AVMutableVideoComposition videoComposition];

set vidComposition.instructions = mainInstruction (AVMutableVideoCompositionInstruction) after edit video play with AVPlayer

Uncomment newPlayerItem.videoComposition = mainCompositionInst; and set vidComposition instead of mainCompositionInst. newPlayerItem.videoComposition = vidComposition;

For editing video this tutorial might be help you. raywenderlich.com/13418/how-to-play-record-edit-videos-in-io‌​s

I hope this helps.

  • I have that problem too. Could you please check this http://stackoverflow.com/questions/43292059/rotate-totally-landscape-view-when-movie-play-in-vlcplayer-with-swift-3/43314526?noredirect=1#comment73694186_43314526 ? – May Phyu Apr 10 '17 at 04:19
  • @MayPhyu , I have answered on your question. it might help you. – i a m a g a m Apr 11 '17 at 09:56