【发布时间】:2013-09-15 04:27:53
【问题描述】:
我将视频保存到 photolibrary。它适用于以前的 ios,在 ios 7 中 videoAtPathIsCompatibleWithSavedPhotosAlbum 这一行总是假的
这是我的代码,任何人都可以帮助我。
NSString *myPathDocs = [documentsDirectory stringByAppendingPathComponent:@"NewmergeVideo.mov"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPathDocs];
if (fileExists) {
[[NSFileManager defaultManager] removeItemAtPath: myPathDocs error:NULL];
}
NSURL *url = [NSURL fileURLWithPath:myPathDocs];
NSLog(@"%@",url);
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL=url;
//[exporter setVideoComposition:MainCompositionInst];
exporter.outputFileType = AVFileTypeQuickTimeMovie;
[exporter exportAsynchronouslyWithCompletionHandler:^
{
dispatch_async(dispatch_get_main_queue(), ^{
[self _exportDidFinish:exporter];
});
}];
这是保存代码
- (void)_exportDidFinish:(AVAssetExportSession*)session
{
NSURL *outputURL = session.outputURL;
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSLog(@"%@",outputURL);
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputURL]) {
[library writeVideoAtPathToSavedPhotosAlbum:outputURL
completionBlock:^(NSURL *assetURL, NSError *error){
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
NSLog(@"writeVideoToAssestsLibrary failed: %@", error);
}else{
NSLog(@"Writing3");
}
});
}];
}
[library release];
}
在以前的 ios nsurl 文件://localhost/var/mobile/Applications/99B72CBA-A426-4F04-B7B2-2B61F0B0C513/Documents/NewmergeVideo.mov
在 iOS 7 中 file:///var/mobile/Applications/791244EE-771B-46C9-BD57-BA0BE6CACD3C/Documents/NewmergeVideo.mov
【问题讨论】:
-
有同样的问题。还在努力解决
-
发现了错误。它不是文件路径错误。检查您的最终视频设置。在我的代码中,我不小心将 timeScale = 600,我将其更改为 30 现在它工作得很好。
-
你在设置什么对象或调用方法来设置timeScale。我正在使用这个:CMTimeRangeMake(kCMTimeZero,videoAsset.duration);
-
MainCompositionInst.frameDuration = CMTimeMake(1,TIME_SCALE);
-
非常感谢,你刚刚救了我!!!!!!