2015-01-20 3 views
2

비디오를 레코딩하고 AVCaptureSession을 사용하여 파일에 저장하려고합니다. 비디오 미리보기를 표시하는 응용 프로그램에 여러 VC가 있으므로 캡처 세션을 처리하는 데 싱글 톤을 사용하고 있습니다.AVCaptureSession을 사용한 비디오 레코딩이 모든 비디오를 저장하지 않습니다.

동영상 미리보기가 올바르게 표시되지만 동영상을 녹화하려고 할 때 모든 것이 제대로 작동하는 것처럼 보이지만 앱 컨테이너를 보면 아무런 오류가 없지만 동영상 파일은 저장되지 않았습니다.

SafeCurveSpeed[9060:3691230] Adding Movie File Output 
SafeCurveSpeed[9060:3691230] Added output to capture session 
SafeCurveSpeed[9060:3691230] Setting image quality 
SafeCurveSpeed[9060:807] Video Recording Started 
SafeCurveSpeed[9060:807] Path to video: "/var/mobile/Containers/Data/Application/44A52ADB-0E36-4303-9DE3-99E9CCCAF3FC/Documents/video/survey-video-10.mp4" 
SafeCurveSpeed[9060:807] Video Recording Ended 

편집 2 : 내가 추가 한이 나는 로그 출력을 얻을 수 있습니다 몇 가지 추가 정보를 원하시면 : 여기

내 캡처 세션 코드에서 해당 기능

-(void)recordVideoSetup{ 
    // Code adapted from 
    // www.ios-developer.net/iphone-ipad-programmer/development/camera/record-video-with-avcapturesession-2 

    NSLog(@"Adding Movie File Output"); 

    MovieFileOutput = [[AVCaptureMovieFileOutput alloc] init]; 

    Float64 TotalSeconds = 600; // 10 minutes max 
    int32_t preferredTimeScale = 30; //fps 
    CMTime maxDuration = CMTimeMakeWithSeconds(TotalSeconds, preferredTimeScale); // Set Max Duration 

    MovieFileOutput.maxRecordedDuration = maxDuration; 
    MovieFileOutput.minFreeDiskSpaceLimit = 1024*1024*10; // 10 MB 

    if ([captureSession canAddOutput:MovieFileOutput]) { 
     NSLog(@"Added output to capture session"); 
     [captureSession addOutput:MovieFileOutput]; 
    } 


    AVCaptureConnection *CaptureConnection = [MovieFileOutput connectionWithMediaType:AVMediaTypeVideo]; 

    // SET LANDSCAPE ORIENTATION 
    if ([CaptureConnection isVideoOrientationSupported]) { 
     AVCaptureVideoOrientation orientation = AVCaptureVideoOrientationLandscapeRight; 
     [CaptureConnection setVideoOrientation:orientation]; 
    } 


    NSLog(@"Setting image quality"); 
    [captureSession setSessionPreset:AVCaptureSessionPresetMedium]; 
    if ([captureSession canSetSessionPreset:AVCaptureSessionPreset640x480]) 
     [captureSession setSessionPreset:AVCaptureSessionPreset640x480]; 

} 

-(NSURL*)startRecordingVideo:(NSString *)surveyID { 
    DDLogCInfo(@"Video Recording Started"); 

    // Get URL to record to 

    NSString *documentsDirPath =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; 
    documentsDirPath = [documentsDirPath stringByAppendingPathComponent:@"video"]; 
    NSURL *documentsDirUrl = [NSURL fileURLWithPath:documentsDirPath isDirectory:YES]; 
    NSString *filename = [NSString stringWithFormat:@"%@.mp4", surveyID]; 
    NSURL *url = [NSURL URLWithString:filename relativeToURL:documentsDirUrl]; 

    DDLogCInfo(@"Path to video: %@", url.path); 

    NSFileManager *filemanager = [NSFileManager defaultManager]; 
    if ([filemanager fileExistsAtPath:[documentsDirPath stringByAppendingString:filename]]) { 
     NSError *error; 
     if ([filemanager removeItemAtURL:url error:&error] == NO) { 
      DDLogCError(@"Could not record video"); 
      return nil; 
     } 
    } 

    [MovieFileOutput startRecordingToOutputFileURL:url recordingDelegate:self]; 

    return url; 
} 

-(void)stopRecordingVideo { 
    DDLogCInfo(@"Video Recording Ended"); 
    [MovieFileOutput stopRecording]; 

} 


-(void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error { 

    // Check if Recording was successfull 

    BOOL recordedSuccessfully = YES; 

    if ([error code] != noErr) { 
     NSLog(@"A Problem occurred with recording"); 

     // A Problem Occurred 
     id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey]; 
     if (value) { 
      recordedSuccessfully = [value boolValue]; 
     } 
    } 

    if (!recordedSuccessfully) { 
     DDLogCInfo(@"!!! - VIDEO RECORDING ERROR"); 
    } 

} 

EDIT 있습니다 "AVCaptureSessionRuntimeErrorNotification"알림을 관찰하는 방법이지만 '녹음'중에는 알림이 표시되지 않습니다. 또한 captureOutput didFinishRecordingToOutputFileAtURL: 메서드의 맨 위에 로그 호출을 추가했으며 녹음이 끝난 후 해당 메서드에 전혀 도달하지 못했다는 것을 알았습니다. 아직도 원인의 확실하지.

+0

나는 불행하게도 더 이상 캡처 세션을 관리하기 위해 싱글 톤을 사용하여 내 메인 메뉴의 UI에서 카메라 미리보기를 희생하여 작업을 비디오 녹화를 얻을 수 있었다. 이 방법으로 캡처 세션을 사용하면 비디오를 올바르게 기록하지 못하는 것 같습니다. –

답변

0

비디오 경로 후이 코드를 추가

UISaveVideoAtPathToSavedPhotosAlbum(url.path, self, @selector(video:didFinishSavingWithError:contextInfo:), nil); 

라이브러리

- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo: (void *) contextInfo { 
    if (error == nil) { 
     [[[UIAlertView alloc] initWithTitle:@"Saved to camera roll" message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; 
    } else { 
     [[[UIAlertView alloc] initWithTitle:@"Failed to save" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; 
    } 
} 

사용을 VC이 타사을이 방법을 추가

https://www.cocoacontrols.com/controls/screcorder

https://github.com/rFlex/SCRecorder

http://www.ios-developer.net/iphone-ipad-programmer/development/camera/record-video-with-avcapturesession-2

+0

안녕하세요, 답변 해 주셔서 감사합니다. 내 앱에서 카메라 롤에 아무것도 저장하지 않고 VC의 비디오 미리보기를 UI의 일부로 구성 했으므로 비디오를 동시에 녹화하고 싶습니다. 동영상이 나중에 가져와 재생 될 수 있도록 핵심 데이터 항목에 URL이 저장되므로 앱 번들 내에 파일로 저장됩니다. –