最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS實(shí)現(xiàn)視頻壓縮上傳實(shí)例代碼

 更新時(shí)間:2017年04月27日 14:59:00   作者:最愛陰雨天  
本篇文章主要介紹了iOS實(shí)現(xiàn)視頻壓縮上傳實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

之前寫過(guò)圖片上傳PHP服務(wù)器,今天把接口稍微改了一下,把視頻上傳的代碼貼出來(lái),目前上傳功能已經(jīng)調(diào)通,視頻的壓縮代碼上似乎并不完善,后續(xù)會(huì)完善壓縮部分的代碼;

- (void)convertVideoWithURL:(NSURL *)url
{
  NSDate *date = [NSDate date];
  NSDateFormatter *dateformatter = [[NSDateFormatter alloc]init];
  [dateformatter setDateFormat:@"YYYY-MM-dd-HH-mm-ss"];
  NSString *dateName = [dateformatter stringFromDate:date];
  NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
  NSString *pathName = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4",dateName]];
  NSLog(@"沙盒:%@",pathName);
  //轉(zhuǎn)碼配置
  AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
  AVAssetExportSession *exportSession= [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetMediumQuality];
  exportSession.shouldOptimizeForNetworkUse = YES;
  exportSession.outputURL = [NSURL fileURLWithPath:pathName];
  exportSession.outputFileType = AVFileTypeMPEG4;
  [exportSession exportAsynchronouslyWithCompletionHandler:^{
    int exportStatus = exportSession.status;
    switch (exportStatus)     {
      case AVAssetExportSessionStatusFailed:
      {
        // log error to text view
        NSError *exportError = exportSession.error;
        NSLog (@"AVAssetExportSessionStatusFailed: %@", exportError);
        [SVProgressHUD showErrorWithStatus:@"視頻壓縮失敗"];
        [SVProgressHUD dismissWithDelay:1.0];
        break;
      }
      case AVAssetExportSessionStatusCompleted:
      {
        self.videoData = [NSData dataWithContentsOfFile:pathName];

        [[NetTool shareDL]upLoadVideoWithURL:@"http://192.168.1.102/php/image.php" paremeter:nil data:self.videoData videoName:[NSString stringWithFormat:@"%@.mp4",dateName] progress:^(NSProgress * _Nonnull uploadProgress) {

          [SVProgressHUD showProgress:1.0*uploadProgress.completedUnitCount/uploadProgress.totalUnitCount status:@"正在上傳"];
          NSLog(@"正在上傳%f%%",(1.0*uploadProgress.completedUnitCount/uploadProgress.totalUnitCount)*100);

        } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
          [SVProgressHUD showSuccessWithStatus:@"上傳成功"];
          [SVProgressHUD dismissWithDelay:1.0];
        } fail:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
          [SVProgressHUD showErrorWithStatus:@"上傳失敗"];
          [SVProgressHUD dismissWithDelay:1.0];
        }];

      }
    }
  }];
}

[manager POST:url parameters:parameter constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
    [formData appendPartWithFileData:videoData name:@"upimage" fileName:videoName mimeType:@"video/mp4"];
  } progress:^(NSProgress * _Nonnull uploadProgress) {
    progress(uploadProgress);
  } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
    success(task,responseObject);
  } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    fail(task,error);
  }];

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 以代碼實(shí)例總結(jié)iOS應(yīng)用開發(fā)中數(shù)據(jù)的存儲(chǔ)方式

    以代碼實(shí)例總結(jié)iOS應(yīng)用開發(fā)中數(shù)據(jù)的存儲(chǔ)方式

    這篇文章主要介紹了iOS應(yīng)用開發(fā)中數(shù)據(jù)的存儲(chǔ)方式的實(shí)例總結(jié),代碼為傳統(tǒng)的Objective-C語(yǔ)言,需要的朋友可以參考下
    2016-02-02
  • iOS中Swift UISearchController仿微信搜索框

    iOS中Swift UISearchController仿微信搜索框

    這篇文章主要介紹了iOS中Swift UISearchController仿微信搜索框效果,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-05-05
  • iOS 引導(dǎo)頁(yè)的鏤空效果實(shí)例

    iOS 引導(dǎo)頁(yè)的鏤空效果實(shí)例

    這篇文章主要介紹了iOS 引導(dǎo)頁(yè)的鏤空效果實(shí)例的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • IOS開發(fā)中取消文本框輸入時(shí)的小鍵盤

    IOS開發(fā)中取消文本框輸入時(shí)的小鍵盤

    這篇文章主要介紹了IOS開發(fā)中取消文本框輸入時(shí)的小鍵盤,需要的朋友可以參考下
    2015-05-05
  • 最新評(píng)論

    齐齐哈尔市| 东辽县| 华阴市| 高阳县| 栾川县| 赫章县| 巫山县| 筠连县| 湛江市| 江津市| 湖口县| 洮南市| 富川| 广宗县| 江华| 密云县| 华阴市| 广水市| 泗阳县| 阜康市| 济宁市| 尚义县| 清镇市| 梨树县| 盐津县| 洮南市| 深圳市| 缙云县| 新宾| 桓台县| 廊坊市| 平邑县| 尖扎县| 桐柏县| 墨竹工卡县| 霍州市| 外汇| 荔浦县| 嘉黎县| 隆化县| 饶平县|