如何将录制的视频保存到相机胶卷?
How to Save Recorded video to camera roll?
我正在尝试使用 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:] - Cannot record to
URL
/private/var/mobile/Containers/Data/Application/FEA51E75-B2A6-45DD-991B-AFFBF5794EAC/tmp/myApp.mov
because it is not a file URL.
但是,如果我将 URL
更改为 initFileURLWithPath
,则会出现另一个错误。
Video
/private/var/mobile/Containers/Data/Application/B6876493-4354-4607-B348-63C5262AF2D9/tmp/myApp.mov
cannot be saved to the saved photos album: Error
Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on
this server."
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=The requested URL was not found on this
server., NSUnderlyingError=0x171ad710 {Error Domain=NSPOSIXErrorDomain
Code=2 "No such file or directory"},
NSURL=file:///private/var/mobile/Containers/Data/Application/B6876493-4354-4607-B348-63C5262AF2D9/tmp/myApp.mov}
我真的不明白错误。谁能帮我解决这个问题?
开发者 Apple 网站有一个很好的示例,说明如何处理来自 iPhone 相机的视频、预处理视频并将其保存到相机胶卷。
访问 link RosyWriter example 并单击文章顶部的 "download sample" 按钮。
本教程还展示了如何使用 OpenCV 和 OpenGL 库对视频进行预处理。
你有没有这样试过:
NSString *outputFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[@"myApp" stringByAppendingPathExtension:@"mov"]];
参考:与您正在工作的示例相同,
其他
NSString *rootPath = NSTemporaryDirectory();
NSString *videoPath = [rootPath stringByAppendingPathComponent:@"myApp.mov"];
NSURL *outputURL = [NSURL fileURLWithPath:videoPath];
以上代码在 copyItemAtURL
中对我有用
我正在尝试使用 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:] - Cannot record to URL /private/var/mobile/Containers/Data/Application/FEA51E75-B2A6-45DD-991B-AFFBF5794EAC/tmp/myApp.mov because it is not a file URL.
但是,如果我将 URL
更改为 initFileURLWithPath
,则会出现另一个错误。
Video /private/var/mobile/Containers/Data/Application/B6876493-4354-4607-B348-63C5262AF2D9/tmp/myApp.mov cannot be saved to the saved photos album: Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server." 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=The requested URL was not found on this server., NSUnderlyingError=0x171ad710 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}, NSURL=file:///private/var/mobile/Containers/Data/Application/B6876493-4354-4607-B348-63C5262AF2D9/tmp/myApp.mov}
我真的不明白错误。谁能帮我解决这个问题?
开发者 Apple 网站有一个很好的示例,说明如何处理来自 iPhone 相机的视频、预处理视频并将其保存到相机胶卷。 访问 link RosyWriter example 并单击文章顶部的 "download sample" 按钮。
本教程还展示了如何使用 OpenCV 和 OpenGL 库对视频进行预处理。
你有没有这样试过:
NSString *outputFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[@"myApp" stringByAppendingPathExtension:@"mov"]];
参考:与您正在工作的示例相同,
其他
NSString *rootPath = NSTemporaryDirectory();
NSString *videoPath = [rootPath stringByAppendingPathComponent:@"myApp.mov"];
NSURL *outputURL = [NSURL fileURLWithPath:videoPath];
以上代码在 copyItemAtURL