title: Rotate video in iOS
body: <p>I am new to iOS.</p>
  
  <p>I have an app for record video and play it in iPad.</p>
  
  <p>Now I have to open camera in view. So I used avcapturesession for that.</p>
  
  <p>Now by my coding I can record and play video but the video recorded is in rotated mode.</p>
  
  <p>I use LandscapeRight for recording.</p>
  
  <p>Here is my coding:</p>
  
  <pre><code>AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
                      captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
  
                      captureVideoPreviewLayer.orientation=AVCaptureVideoOrientationLandscapeRight;
                      captureVideoPreviewLayer.frame = vwvideo.bounds;
  
                      [vwvideo.layer addSublayer:captureVideoPreviewLayer];
  
                      AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
  
                      NSError *error = nil;
                      AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&amp;error];
                      if (!input) {
                          // Handle the error appropriately.
                          NSLog(@"ERROR: trying to open camera: %@", error);
                      }
  
                      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  
                      AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
  
                      NSString *documentsDirectory = [paths objectAtIndex:0];
  
                      NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
                      [dateFormat setDateFormat:@"yyyy-MM-dd HH.mm.SS"];
                      NSDate *now = [[[NSDate alloc] init] autorelease];
                      theDate = [dateFormat stringFromDate:now];
  
                      NSString *tempPath = [NSString stringWithFormat:@"%@/%@.mp4",documentsDirectory,theDate];
                      [tempPath retain];
                      NSLog(@"Path::%@",tempPath);
  
                      NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:tempPath];
                                          [session addInput:input];
                      [session addOutput:movieFileOutput];
                      [session commitConfiguration];
                      [session startRunning];
  
                      [movieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
  </code></pre>