【问题标题】:Recording a video with AVFoundation使用 AVFoundation 录制视频
【发布时间】:2014-12-29 16:03:54
【问题描述】:

我已经创建了会话、设备、输入和输出,但是当我调用 startRecordingToOutputFileURL:recordingDelegate: 方法时,它调用了 didFinishRecordingToOutputFileAtURL 委托方法,所以它在没有开始!

这是我的代码..

-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

AVCaptureSession *session = [[AVCaptureSession alloc] init];
[session setSessionPreset:AVCaptureSessionPresetPhoto];

AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];


AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error];

if ([session canAddInput:deviceInput]) {
[session addInput:deviceInput];
}

AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
CALayer *rootLayer = [[self view] layer];
[rootLayer setMasksToBounds:YES];
CGRect frame = self.view.frame;

[previewLayer setFrame:frame];

[rootLayer insertSublayer:previewLayer atIndex:0];

_movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];

if ([session canAddOutput:movieFileOutput]) {
    [session addOutput:movieFileOutput];
}

[session startRunning];
}
-(void)buttonClicked {
[_movieFileOutput startRecordingToOutputFileURL:url recordingDelegate:self];
}

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
      fromConnections:(NSArray *)connections
            error:(NSError *)error {
    //This method is getting called when I press the button
    NSLog(@"Finished Recording");

}

那么我的代码有什么问题? 我错过了什么吗?

谢谢

【问题讨论】:

  • AVCaptureSessionPresetPhoto

标签: ios objective-c iphone avfoundation avcapturesession


【解决方案1】:

终于成功了!

问题出在 URL 上。 我尝试了许多 URL,但没有一个有效,它必须在 NSDocumentsDirectory 中,就是这样!

【讨论】:

    猜你喜欢
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多