2

我必须将视频保存到相机胶卷,视频是 nsdata 的形式。我知道这是方法

UISaveVideoAtPathToSavedPhotosAlbum(videopath, self,  @selector(video:didFinishSavingWithError:contextInfo:), nil);
- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {

    NSLog(@"is error?%@",error);
}

也试过这个但不适合我

 NSURL *movieURL = [NSURL fileURLWithPath:self.videoPath];

        NSLog(@"movie url== %@",self.videoPath);
                    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
                 [library writeVideoAtPathToSavedPhotosAlbum:movieURL
                                             completionBlock:^(NSURL *assetURL, NSError *error){NSLog(@"complete ");}];

此方法接受路径不是 nsdata 。我应该怎么办?

这里视频路径 = @"/var/mobile/Applications/AE75E729-7F10-478B-9DAF-E730EB4231D1/Documents/Videos/12.mp4"

4

3 回答 3

0

我看过一个例子 [这里] ( https://github.com/versluis/Video-Recorder )

我没有尝试过,但希望它会对你有所帮助。

下载代码,查看 ViewController.m 中的代码

NSURL *chosenMovie = [info objectForKey:UIImagePickerControllerMediaURL];

// save it to the documents directory
NSURL *fileURL = [self grabFileURL:@"video.mov"];
NSData *movieData = [NSData dataWithContentsOfURL:chosenMovie];
[movieData writeToURL:fileURL atomically:YES];

// save it to the Camera Roll
UISaveVideoAtPathToSavedPhotosAlbum([chosenMovie path], nil, nil, nil);

首先使用 NSData 创建一个文件,然后将该文件的路径传递给 UISaveVideoAtPathToSavedPhotosAlbum 方法。

这也是 [stackoverflow answer] 的另一个链接(将 mp4 视频保存到设备相机胶卷),它以 .mp4 格式保存视频。

于 2014-11-10T12:29:11.683 回答
0

如果你的 VideoPath 像

 UploadfilePathString = @"/var/mobile/Applications/AE75E729-7F10-478B-9DAF-E730EB4231D1/Documents/Videos/12.mp4"

然后以这种方式将视频路径转换为 ​​NSData

 NSError* error = nil;
 NSData *uploadFileData = [NSData dataWithContentsOfFile:UploadfilePathString  options:0 error:&error];
    NSLog(@"Data read from %@ with error: %@", uploadFileData, error);

输出:它以数据格式出现,然后只需将数据格式上传到服务器。谢谢

于 2017-10-04T06:55:44.020 回答
0
NSData *video_data=//Your Video NSData
    // Write it to cache directory
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"file1.mp4"];
    [video_data writeToFile:path atomically:YES];
    NSLog(@"Path:%@",path);
    // After that use this path to save it to PhotoLibrary
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:path] completionBlock:^(NSURL *assetURL, NSError
*error) {
        if (error) {
            NSLog(@"%@", error.description);
        }else {
            NSLog(@"Done :)");
        }
    }];
于 2016-02-04T13:51:16.797 回答