2016-06-15 7 views
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"]; 

      } 
     }]; 
    }]; 
} 

私は.MP4にファイル拡張子from.MOVを削除することによって、以下の方法を試してみましたが、私は、ギャラリーやカメラからそれを選択した状態のみ物乞いにそれを変換する必要があると思うworked.So din'tています。

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

} 
+0

http://stackoverflow.com/questions/5015050/equivalent-for-stringbydeletingpathextension-for-an-array http://stackoverflow.com/questions/1098957/objective-c-extract-filename-from-path -string – vicky

答えて

関連する問題