我是 iOS 新手。
我有一个用于录制视频并在 iPad 上播放的应用程序。
现在我必须在视图中打开相机。所以我为此使用了avcapturesession。
现在通过我的编码,我可以录制和播放视频,但录制的视频处于旋转模式。
我使用 LandscapeRight 进行录制。
这是我的编码:
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:&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];