2016-10-13 15 views
0

我正在製作一個iOS應用程序(即將推出Android),該程序涉及用戶通過應用程序在手機上錄製視頻。但我需要應用程序來減少這些視頻的默認大小,以便在將它們上傳到我的服務器時使用更少的帶寬,並且上傳速度更快。什麼是最好的方式來做到這一點?如何減少通過我的iOS應用程序在手機上錄製的視頻的文件大小

+0

壓縮您的視頻,然後將壓縮視頻數據發送到您的服務器。 –

+0

Himanshu,這就是我正在嘗試做的事情,但我需要一個腳本,一旦用戶錄製就能最佳地壓縮視頻。這是我正在尋找的。謝謝。 – Rob

回答

0

試試這個代碼希望你的任務完成。

- (void)convertVideoToLowQuailty:(NSURL*)inputURL 
             outputURL:(NSURL*)outputURL 
             handler:(void (^)(AVAssetExportSession*))handler 
    { 
     [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil]; 
     AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil]; 
     AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality]; 
     exportSession.outputURL = outputURL; 
     exportSession.outputFileType = AVFileTypeQuickTimeMovie; 
     [exportSession exportAsynchronouslyWithCompletionHandler:^(void) 
     { 
      handler(exportSession); 
      [exportSession release]; 
     }]; 
    } 

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 

    { 
     NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; 
     NSURL *outputURL = [NSURL fileURLWithPath:@"/Users/Hems/Desktop/output.mov"]; 
     [self convertVideoToLowQuailty:videoURL outputURL:outputURL handler:^(AVAssetExportSession *exportSession) 
     { 
      if (exportSession.status == AVAssetExportSessionStatusCompleted) 
      { 
       printf("completed\n"); 
      } 
      else 
      { 
       printf("error\n"); 

      } 
     }]; 

    } 
+0

謝謝。我會將此發送給我目前的開發人員,看看它是否適合我。 – Rob

+0

我發現一些信息以下鏈接。思考? – Rob

+0

https://www.quora.com/What-video-compression-library-is-used-by-WhatsApp https://7labs.heypub.com/mobile/compress-video-android-ios-wp。 html – Rob

相關問題