如何将录制的视频保存到相机胶卷?

问题描述:

我试图用iPhone摄像头录制视频并保存到相机胶卷之后blog。但是,使用AVCaptureSession,摄像机会被初始化。但是,当试图将视频保存到相机胶卷时,它会给出URL错误。这里是我的代码片段如何将录制的视频保存到相机胶卷?

NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"myApp.mov"]; 

      NSURL *outputURL = [NSURL URLWithString:outputPath]; 
      // NSLog(@"Output URL %@ AND ABSOLUTE STRING %@",outputURL,outputURL.absoluteString); 
      NSFileManager *fileManager = [NSFileManager defaultManager]; 
      if ([fileManager fileExistsAtPath:outputPath]) 
      { 
       NSError *error; 
       if ([fileManager removeItemAtPath:outputPath error:&error] == NO) 
       { 
        //Error - handle if requried 
       } 
      } 
      //Start recording 
      [MovieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self]; 

它给下面的错误

[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - 无法记录到 URL /私营/无功/移动/集装箱/数据/应用/ FEA51E75-B2A6-45DD-991B-AFFBF5794EAC/tmp/myApp.mov ,因为它不是文件URL。

但是,如果我将URL更改为initFileURLWithPath,则会出现另一个错误。

视频 /private/var/mobile/Containers/Data/Application/B6876493-4354-4607-B348-63C5262AF2D9/tmp/myApp.mov 不能保存到存储的照片相册:错误 域= NSURLErrorDomain代码= -1100“请求的URL在 此服务器上找不到。” UserInfo = {NSErrorFailingURLStringKey = file:///private/var/mobile/Containers/Data/Application/B6876493-4354-4607-B348-63C5262AF2D9/tmp/myApp.mov, NSErrorFailingURLKey = file:/// private/var /mobile/Containers/Data/Application/B6876493-4354-4607-B348-63C5262AF2D9/tmp/myApp.mov, NSLocalizedDescription =在此 服务器上找不到请求的URL。,NSUnderlyingError = 0x171ad710 {错误域= NSPOSIXErrorDomain 代码= 2“没有这样的文件或目录”}, NSURL = file:///private/var/mobile/Containers/Data/Application/B6876493-4354-4607-B348-63C5262AF2D9/tmp/myApp.mov}

我真的不明白这个错误。任何人都可以帮我整理一下吗?

你有没有尝试过这样的:

NSString *outputFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[@"myApp" stringByAppendingPathExtension:@"mov"]]; 

参考:同样的例子像你工作,https://stackoverflow.com/a/21118720/4557505

其他

NSString *rootPath = NSTemporaryDirectory(); 
NSString *videoPath = [rootPath stringByAppendingPathComponent:@"myApp.mov"]; 
NSURL *outputURL = [NSURL fileURLWithPath:videoPath]; 

上面的代码对我的作品在copyItemAtURL

+0

感谢你的回答。但它没有奏效。给我同样的错误。 –

+0

@ user6April我已更新答案 – HardikDG

+0

在工作链接中的答案。 –

开发者苹果网站有一个很好的例子,如何使用iPhone摄像头的视频,预处理和保存视频到相机胶卷。 访问链接RosyWriter example并点击文章顶部的“下载示例”按钮。

本教程还演示如何使用OpenCV和OpenGL库预处理视频。