I have recorded a video in iphone and I am getting its local file URL. Is there any way to rotate that video by 90 degree using the URL?
Asked
Active
Viewed 1,506 times
0
-
@ Anbu.Karthik i am not getting any idea how to do it – Raman Srivastava Mar 02 '17 at 07:54
-
how do u load ur video it s AVplayer or MPMoviePlayerViewController – Anbu.Karthik Mar 02 '17 at 07:55
-
i have to merge it with other video and send it to server – Raman Srivastava Mar 02 '17 at 07:58
-
Why do you want to rotate to 90 degree? is your recorded video coming rotated? – iphonic Mar 02 '17 at 08:07
-
@iphonic because i am merging it with other video and uploading to server the recorded video gets rotated by 90 degree.So i thought to send the rotated video so that it may again rotate and should get me the right orientation – Raman Srivastava Mar 03 '17 at 06:03
-
Add your whole code how you are merging and creating video, problem is there. – iphonic Mar 03 '17 at 06:05
-
http://stackoverflow.com/questions/42504966/i-am-uploading-video-to-server-after-merging-it-with-other-video-but-the-recorde/42505363?noredirect=1#comment72193285_42505363 – Raman Srivastava Mar 03 '17 at 06:09
2 Answers
3
You can rotate the Video before exporting session using AVMutableVideoCompositionLayerInstruction
class and you can apply Transform
on it .
This is the method
[yourlayerInstruction setTransform:CGAffineTransformMakeRotation(M_PI/2) atTime:firstAssets.duration];
here is the full implementation
AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *firstTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableVideoCompositionInstruction * mainInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
mainInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeAdd(firstAsset.duration, secondAsset.duration));
AVMutableVideoCompositionLayerInstruction *firstlayerInstruction = [AVMutableVideoCompositionLayerInstruction
videoCompositionLayerInstructionWithAssetTrack:firstTrack];
// set Trasform Here
[firstlayerInstruction setTransform:CGAffineTransformMakeRotation(M_PI/2) atTime:kCMTimeZero];
[firstlayerInstruction setOpacity:0.0 atTime:firstAsset.duration];
mainInstruction.layerInstructions = [NSArray arrayWithObjects:firstlayerInstruction,nil];;
AVMutableVideoComposition *mainCompositionInst = [AVMutableVideoComposition videoComposition];
mainCompositionInst.instructions = [NSArray arrayWithObject:mainInstruction];
mainCompositionInst.frameDuration = CMTimeMake(1, 30);
mainCompositionInst.renderSize = CGSizeMake(320.0, 480.0);
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition
presetName:AVAssetExportPreset640x480];
exporter.outputURL=url;
exporter.videoComposition=mainCompositionInst;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.shouldOptimizeForNetworkUse = YES;
[exporter exportAsynchronouslyWithCompletionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^
{
[self exportDidFinish:exporter];
});
}];
i hope this will help you

Dhiru
- 3,040
- 3
- 25
- 69
-2
If you are using MPMoviePlayerViewController for playing video:- Then you can try this, First fetch your url from bundle using below line,
NSURL *fileUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"your video" ofType:@"mp4"]];
Or you can use your local file url directly in mpmovieplayerviewcontroller
Then create MPmovieplayerview controller's object and use your video file as shown below :-
MPMoviePlayerViewController *moviePlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:fileUrl];
[moviePlayerController.moviePlayer prepareToPlay];
moviePlayerController.view.transform = CGAffineTransformMakeRotation(M_PI/2);
[self.view addSubview:moviePlayerController.view];
Hope it helps!

Zalak Patel
- 1,937
- 3
- 26
- 44
-
Well this will just rotate the video while playing, he wants it to rotate while exporting and sending the video to server. – iphonic Mar 02 '17 at 08:06