Как создать пользовательский захват изображения с камеры и программную запись и сохранение в ios target-c? - PullRequest
0 голосов
/ 26 октября 2018

видео не записывается при нажатии захваченной кнопки и кнопки остановки.

-(void)showSessionRecorder {
    movieOutPut = [[AVCaptureMovieFileOutput alloc]init];
    session = [[AVCaptureSession alloc] init];

    [session setSessionPreset:AVCaptureSessionPresetHigh];

    inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    NSError *error;
    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->recorderView.layer;
        [rootLayer setMasksToBounds:YES];

        [previewLayer setFrame:CGRectMake(0, 0, self->recorderView.frame.size.width+40, self->recorderView.frame.size.height+40)];

        [rootLayer insertSublayer:previewLayer atIndex:0];
        [session addOutput:movieOutPut];
        [session startRunning];
}

-(void)recordVideo:(UIButton*)sender {
    if(sender.tag == 10) {
        [session startRunning];

        NSArray *paths = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];

        NSURL *fileUrl = [paths[0] URLByAppendingPathComponent:@"output.mov"];
        [[NSFileManager defaultManager]removeItemAtURL:fileUrl error:nil];
        [movieOutPut startRecordingToOutputFileURL:fileUrl recordingDelegate:self];
        [self.stop setHidden:NO];
        [self.recordButton setHidden:YES];
    }
    else if(sender.tag == 11) {
        if([movieOutPut isRecording]) {
            [movieOutPut stopRecording];
        }

        [self.stop setHidden:YES];
        [self.recordButton setHidden:NO];
    }
}

- (void)captureOutput:(AVCaptureFileOutput *)output didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray<AVCaptureConnection *> *)connections error:(NSError *)error {
    if(error == nil) {
        UISaveVideoAtPathToSavedPhotosAlbum([outputFileURL path], nil, nil, nil);
        [session stopRunning];
    }
}
...