1
當我從圖庫中選擇一個視頻時,我將選定的文件擴展名爲.MOV,因此想將其轉換爲.MP4,但未能完成此操作在這種情況下。如果你有任何想法,請幫助。將.MOV轉換爲.MP4,從圖庫中選擇或從相機中錄製
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
selectedVideoURL = info[UIImagePickerControllerMediaURL];
if([picker sourceType] == UIImagePickerControllerSourceTypeCamera)
{
NSURL *videoURL=info[UIImagePickerControllerMediaURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];
[library writeVideoAtPathToSavedPhotosAlbum:videoURL completionBlock:^(NSURL *assetURL, NSError *error)
{
//here is your URL : assetURL
NSLog(@"url is%@",assetURL);
// here in debugger it shows as assets.MOV i want .MP4
PHFetchResult<PHAsset*> *assets = [PHAsset fetchAssetsWithALAssetURLs:@[assetURL]
options:nil];
PHAsset *asset1 = assets.firstObject;
[[PHImageManager defaultManager] requestAVAssetForVideo:asset1 options:nil resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
if ([asset isKindOfClass:[AVURLAsset class]]) {
AVURLAsset* urlAsset = (AVURLAsset*)asset;
NSNumber *size;
[urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
NSLog(@"size video of camera %f",[size floatValue]/(1024.0*1024.0)); //size is 43.703005
NSData *data = [NSData dataWithContentsOfURL:urlAsset.URL];
NSLog(@"length of camera %f",[data length]/(1024.0*1024.0)); // data size is 43.703005
sizeofVideo=[size floatValue]/(1024.0*1024.0);
NSLog(@"sizeofVideo arvin %f",sizeofVideo);
if (!sizeofVideo>50.00) {
selectedVideoURL=nil;
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Alert" message:@"size of video exist 50MB" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
attachnoteLbl.text=[NSString stringWithFormat:@"Attach Note:0"];
}
attachnoteLbl.text=[NSString stringWithFormat:@"Attach Note:1"];
}
}];
}];
}
我試圖通過刪除文件擴展名from.MOV到.MP4以下方式,但din't worked.So我認爲需要將其轉換隻在從畫廊或相機中選擇了乞討。
-(void)afnetworking{
NSString *videoUrl=[selectedVideoURL path];
if(videoUrl){
NSString *videoName = [[videoUrl lastPathComponent]stringByDeletingPathExtension];
NSData *videoData = [NSData dataWithContentsOfURL:selectedVideoURL];
[bodyData appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *tmpfileinfo = [NSString stringWithFormat:@"Content-Disposition: form-data; name=\"video_clip\"; filename=\"%@.mp4\"\r\n",videoName];
[bodyData appendData:[tmpfileinfo dataUsingEncoding:NSUTF8StringEncoding]];
[bodyData appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[bodyData appendData:[NSData dataWithData:videoData]];
}
http://stackoverflow.com/questions/5015050/equivalent-for-stringbydeletingpathextension-for-an-array http://stackoverflow.com/questions/1098957/objective-c-extract-filename-from-path - 字符串 – vicky