使用AVFoundation在iPhone上录制视频时出错 [英] Error while recording video on iphone using AVFoundation

查看:136
本文介绍了使用AVFoundation在iPhone上录制视频时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用AVFoundation录制视频 我可以保存图像,但不能保存视频.尝试保存视频时,我 出现错误消息:

Im trying to record video using AVFoundation I can save images but not video. When trying to save a video, I got an error saying:

[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];    
}

我也在尝试在IOs-4.1的Iphone 3G上进行测试.

Also I am trying to test this on Iphone 3G with IOs-4.1.

推荐答案

您应该在[AVCaptureSession beginConfiguration][AVCaptureSession commitConfiguration]对之间添加输出.

You should be adding your outputs between a [AVCaptureSession beginConfiguration] and [AVCaptureSession commitConfiguration] pair.

这篇关于使用AVFoundation在iPhone上录制视频时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆