无法使用AVCaptureMovieFileoutput录制电影

时间:2012-06-05 10:04:15

标签: macos avfoundation

我正在尝试录制视频而我收到错误

  

无法记录到网址< #file url>因为它不是文件URL。

我按如下方式定义目标网址:

NSString *Path = [[NSString alloc] init];
Path = @"/Users/me/Documents/My fols/recording_try/newMovie.mov";
NSURL *dest = [[NSURL alloc] initWithString:[Path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

然后在创建会话后,输入和输出对象。我试着像这样录制。

mMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init] ;
[mSession addOutput:mMovieFileOutput];
[mMovieFileOutput startRecordingToOutputFileURL:dest recordingDelegate:self];

我已经开始运行会话,尝试使用begin和comitconfiguration等。但是每次运行时我都会遇到如下错误:

[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - Cannot record to URL /Users/me/Documents/My%20fols/recording_try/newMovie.mov because it is not a file URL.

我不知道我哪里出错......有人可以帮忙吗???

提前致谢...

2 个答案:

答案 0 :(得分:1)

尝试这样的事情:

// variable names should start with lower case letters

// also, let's do as much as we can with auto-released objects
// so we don't have to worry about leaking (if we're not using ARC)
NSString *path = [NSString stringWithString: @"/Users/me/Documents/My fols/recording_try"];
NSURL *dest = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if(dest == nil)
{
    NSLog( @"does not appear to be a valid NSURL object" );
    return;
}

NSError * error = nil;
if([[NSFileManager defaultManager] createDirectoryAtURL: dest withIntermediateDirectories: YES attributes: nil error: &error] == YES)
{
    dest = [dest URLByAppendingPathComponent: @"newMovie.mov"];

    // now you can create the session plus input and output objects
    // within this block

} else {
    NSLog( @"was not able to create the directory which contains path %@ - error is %@", path, [error localizedDescription] );
}

答案 1 :(得分:1)

只需更改NSURL配置即可符合文件网址类型

这样的事情:

NSURL * dest = [[NSURL alloc] initFileURLWithPath:<#(NSString *)#>]