如何将捕获视频转换为NsData?

时间:2016-07-02 01:01:50

标签: ios objective-c

您好我使用相机拍摄视频

url = "file:///private/var/mobile/Containers/Data/Application/F5A89447-0720-4956-BD83-EEB541EE69AC/tmp/capture-T0x146e04ad0.tmp.TnQgmW/capturedvideo.MOV"

而且我无法使用dataWithContentsOfFile它总是给我零。

_videourl = [info objectForKey:UIImagePickerControllerMediaURL];
        NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];

[picker dismissViewControllerAnimated:YES completion:NULL];

if (CFStringCompare ((__bridge_retained CFStringRef)mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {


 NSString *str=[[NSBundle mainBundle] pathForResource:@"capturedvideo" ofType:@"MOV"];

NSData *fileData = [NSData dataWithContentsOfFile:str];


NSData *videoData = [NSData dataWithContentsOfFile:[_videourl absoluteString]];    
 NSData *videoData2 = [NSData dataWithContentsOfURL:_videourl]; 

FileDataVideoData都为空,videoData2只有一个有值

我的问题是如何使用dataWithContentsOfURL来自相机而不是来自相册的临时网址?

2 个答案:

答案 0 :(得分:1)

将视频文件转换为NSData

NSData *videoData = [NSData dataWithContentsOfFile:videopath];

或来自网址的视频

NSData *videoData = [NSData dataWithContentsOfURL:VideoUrl];

答案 1 :(得分:-1)

你需要做的就是用这个代替你的代码,它会正常工作

'1234' > '456' => false