Mohamed Helmy
Mohamed Helmy

Reputation: 832

How Convert Capturing video to NsData?

Hello I using camera to capturing video

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

And I can't use dataWithContentsOfFile it give me nil all the time.

_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]; 

Both FileData and VideoData is null and videoData2 is only one have value

My question is how use dataWithContentsOfURL with temp url from camera not from the gallery ?

Upvotes: 0

Views: 577

Answers (2)

Harish
Harish

Reputation: 609

Converting video File into NSData

NSData *videoData = [NSData dataWithContentsOfFile:videopath];

or else video from url

NSData *videoData = [NSData dataWithContentsOfURL:VideoUrl];

Upvotes: 2

PinkeshGjr
PinkeshGjr

Reputation: 8680

all you need to do is replace you code with this and it will work fine

 NSData *dataVideo = [NSData dataWithContentsOfURL:@"file:///private/var/mobile/Containers/Data/Application/F5A89447-0720-4956-BD83-EEB541EE69AC/tmp/capture-T0x146e04ad0.tmp.TnQgmW/capturedvideo.MOV"];

Upvotes: -1

Related Questions