2011-05-12 1 views
1

AVFoundation을 사용하여 비디오를 녹화하려고합니다. 이미지는 저장할 수 있지만 비디오는 저장할 수 없습니다. 여기AVFoundation을 사용하여 iphone에 비디오를 녹화하는 동안 오류가 발생했습니다.

[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - no active/enabled connections.' 

그리고 내 코드입니다 :


session = [[AVCaptureSession alloc] init]; 
//session is global object. 
    session.sessionPreset = AVCaptureSessionPresetMedium;    
    AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];  
    captureVideoPreviewLayer.frame = self.imgV.bounds; 
    [self.imgV.layer addSublayer:captureVideoPreviewLayer];   
    AVCaptureDevice *device =[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
    NSError *error = nil; 
    NSLog(@"start  3"); 
    AVCaptureDeviceInput *input = 
    [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; 
    if (!input) { 
     NSLog(@"Error"); 
    } 
    [session addInput:input];  
    stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; 
    NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil]; 
    [stillImageOutput setOutputSettings:outputSettings];  
    [session addOutput:stillImageOutput];  
    aMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];  
    [session addOutput:aMovieFileOutput]; 
    [session startRunning]; 
    [self performSelector:@selector(startRecording) withObject:nil afterDelay:10.0]; 
    //[aMovieFileOutput startRecordingToOutputFileURL:fileURL recordingDelegate:self]; 
    //previously i used to do this way but saw people doing it after delay thought it might be taking some time to initialized so tried this way also.   
} 
- (void) startRecording 
{ 
    NSLog(@"startRecording"); 
    NSString *plistPath; 
    NSString *rootPath;  
    rootPath= [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
    plistPath = [rootPath stringByAppendingPathComponent:@"test.mov"]; 
    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:plistPath]; 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    if ([fileManager fileExistsAtPath:plistPath]) { 
     NSLog(@"file exist %s  n  url %@ ",[rootPath UTF8String],fileURL); 
    } 
    [aMovieFileOutput startRecordingToOutputFileURL:fileURL recordingDelegate:self];  
} 

이 또한 내가 IO를-4.1과 아이폰 3G에서이를 테스트하기 위해 노력하고 비디오를 저장하려고 할 때, 나는 가 말하는 오류가 발생했습니다.

답변

1

출력을 [AVCaptureSession beginConfiguration][AVCaptureSession commitConfiguration] 쌍 사이에 추가해야합니다. 당신이 startRecordingToOutputFileURL:recordingDelegate: 방법을 사용하여 대리인으로 물체를 통과 할 때

+0

[AVCaptureSession beginConfiguration] 및 [AVCaptureSession commitConfiguration] 쌍은 현재 세션을 업데이트해야합니다. 그러나 세션을 시작하기 전에 출력을 추가하고 있습니다. – saurabh

+0

나는 비디오 녹음을 지원하지 않는 아이폰 3G 때문에 그것이 궁금하다. – saurabh

+0

헤이 작동 ... 나는 예외는 아니지만 여전히 비디오를 가지고 있지 않다 ... mov 오디오 파일을 그냥 오디오로 보았다. – saurabh

1

이 오류가 발생할 수 있지만,이 개체는 captureOutput:didStartRecordingToOutputFileAtURL:fromConnections: AVCaptureFileOutputRecordingDelegate 방법이 구현되어 있지 않습니다.

0

AVCaptureFileOutputRecordingDelegate 프로토콜을 구현하십시오. 동영상 파일 출력이 기존 자원을 덮어 쓰지 않으므로 동영상 파일의 경로가 정확하고 동영상 파일이 존재하지 않는지 확인하십시오.

3

세션 사전 설정을 '사진'으로 설정하면이 문제가 발생할 수 있습니다. 해야

[session setSessionPreset:kCaptureSessionPresetPhoto]; 

:

사과 문서에 따라
[session setSessionPreset:kCaptureSessionPresetVideo];