将mp4video保存到设备相机胶卷

我首先只是一个NSString,它是一个.mp4文件的URL,从这里我希望将该video保存到设备相机胶卷。 看来我只能保存.mov文件,所以我必须首先转换.mp4,但我看到的关于这个的几个post没有帮助。

任何人都可以帮我完成这个吗?

提前致谢…

如果使用支持的编解码器,您可以将mp4文件保存到相机胶卷。 例如:

NSURL *sourceURL = [NSURL URLWithString:@"http://path/to/video.mp4"]; NSURLSessionTask *download = [[NSURLSession sharedSession] downloadTaskWithURL:sourceURL completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) { NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject]; NSURL *tempURL = [documentsURL URLByAppendingPathComponent:[sourceURL lastPathComponent]]; [[NSFileManager defaultManager] moveItemAtURL:location toURL:tempURL error:nil]; UISaveVideoAtPathToSavedPhotosAlbum(tempURL.path, nil, NULL, NULL); }]; [download resume]; 

或者,在iOS 6及更高版本上:

 NSURL *sourceURL = [NSURL URLWithString:@"http://path/to/video.mp4"]; NSURLRequest *request = [NSURLRequest requestWithURL:sourceURL]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject]; NSURL *tempURL = [documentsURL URLByAppendingPathComponent:[sourceURL lastPathComponent]]; [data writeToURL:tempURL atomically:YES]; UISaveVideoAtPathToSavedPhotosAlbum(tempURL.path, nil, NULL, NULL); }];