Im using the code found [here][1] to attach image on video taken using UIImagePickerController
.
the video is in portrait and playing fine but once I use AVURLASSet
it turning landscape orientation instead of portrait and I cant find why?
Can any one point me to the right direction ?
My Code:
-(IBAction)addWaterMark:(id)sender {
AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:[NSURL fileURLWithPath:tempPath] options:nil];
AVMutableComposition* mixComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *clipVideoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)
ofTrack:clipVideoTrack
atTime:kCMTimeZero error:nil];
[compositionVideoTrack setPreferredTransform:[[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] preferredTransform]];
CGSize videoSize = [videoAsset naturalSize];
NSLog(@"%f %f",videoSize.width,videoSize.height);
}
at this point I get 480,360 instead of the correct size for temppath
found detailed tutorial describing how to edit and manipulate videos with AVfoundation introduction here
If they are landscape, we can use the naturalSize property we are supplied with, but if they are portrait, we must flip the the naturalSize so that the width is now the height and vice-versa