国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

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

2019-10-21 18:46:46
字體:
供稿:網(wǎng)友

之前寫過圖片上傳PHP服務(wù)器,今天把接口稍微改了一下,把視頻上傳的代碼貼出來,目前上傳功能已經(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í)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到IOS開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 水城县| 冷水江市| 西吉县| 邛崃市| 佛山市| 宜兰县| 肇州县| 湖南省| 沧州市| 洛阳市| 宜川县| 尚志市| 彭泽县| 错那县| 江口县| 玛沁县| 胶州市| 博兴县| 石门县| 孙吴县| 梁河县| 柳州市| 阜南县| 乌拉特中旗| 桦南县| 于田县| 渑池县| 和田市| 阜城县| 常德市| 十堰市| 中山市| 江阴市| 饶平县| 建瓯市| 怀柔区| 平昌县| 大石桥市| 浑源县| 桃江县| 平利县|