Commit 8f7f7dd2829f60411571b6e324569b2ccd2f72bf
1 parent
96b6c870
提交
Showing
15 changed files
with
247 additions
and
247 deletions
CNLiveUploadManager.podspec
| @@ -137,8 +137,8 @@ TODO:加入压缩测试 | @@ -137,8 +137,8 @@ TODO:加入压缩测试 | ||
| 137 | # 依赖类库 | 137 | # 依赖类库 |
| 138 | s.dependency "AFNetworking", "~> 3.1.0" | 138 | s.dependency "AFNetworking", "~> 3.1.0" |
| 139 | s.dependency "Qiniu", "~> 7.1" | 139 | s.dependency "Qiniu", "~> 7.1" |
| 140 | - s.dependency "PLShortVideoKit", "~> 1.13.1" | ||
| 141 | - s.dependency "PLPlayerKit", "~> 3.3.3" | 140 | + # s.dependency "PLShortVideoKit", "~> 1.13.1" |
| 141 | + # s.dependency "PLPlayerKit", "~> 3.3.3" | ||
| 142 | 142 | ||
| 143 | 143 | ||
| 144 | end | 144 | end |
CNLiveUploadManager/CNTools.h renamed to CNLiveUploadManager/util/CNTools.h
CNLiveUploadManager/CNTools.m renamed to CNLiveUploadManager/util/CNTools.m
CNLiveUploadManager/HttpService.h renamed to CNLiveUploadManager/util/HttpService.h
CNLiveUploadManager/HttpService.m renamed to CNLiveUploadManager/util/HttpService.m
CNLiveUploadManager/UserInformationModel.h renamed to CNLiveUploadManager/util/UserInformationModel.h
CNLiveUploadManager/UserInformationModel.m renamed to CNLiveUploadManager/util/UserInformationModel.m
CNLiveUploadManager/CNLiveUploadManager.h renamed to CNLiveUploadManager/上传/CNLiveUploadManager.h
| @@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
| 8 | 8 | ||
| 9 | #import <Foundation/Foundation.h> | 9 | #import <Foundation/Foundation.h> |
| 10 | #import <UIKit/UIKit.h> | 10 | #import <UIKit/UIKit.h> |
| 11 | -#import <PLShortVideoKit/PLShortVideoKit.h> | 11 | +//#import <PLShortVideoKit/PLShortVideoKit.h> |
| 12 | #import <Qiniu/QNResponseInfo.h> | 12 | #import <Qiniu/QNResponseInfo.h> |
| 13 | #import "UIImage+zipData.h" | 13 | #import "UIImage+zipData.h" |
| 14 | 14 | ||
| @@ -179,8 +179,8 @@ typedef void (^progressHandlerBlock)(float progress);//进度 | @@ -179,8 +179,8 @@ typedef void (^progressHandlerBlock)(float progress);//进度 | ||
| 179 | /// 请求token 单个视频上传 (video - 系统压缩 - 限制 - 筛选) | 179 | /// 请求token 单个视频上传 (video - 系统压缩 - 限制 - 筛选) |
| 180 | + (void)uploadRequestVideoType:(CNLiveUploadType)type url:(NSString *)url dic:(NSDictionary *)dic asset:(id)asset outputPath:(NSString *)outputPath progress:(progressHandlerBlock)progress success:(successModelBlock)success failure:(failureModelBlock)failure; | 180 | + (void)uploadRequestVideoType:(CNLiveUploadType)type url:(NSString *)url dic:(NSDictionary *)dic asset:(id)asset outputPath:(NSString *)outputPath progress:(progressHandlerBlock)progress success:(successModelBlock)success failure:(failureModelBlock)failure; |
| 181 | 181 | ||
| 182 | -/// 请求token 单个视频上传 (video - 七牛短视频压缩 - 限制 - 筛选) | ||
| 183 | -+ (void)uploadRequestWhithPLShortVideoType:(CNLiveUploadType)type outputPath:(NSString *)outputPath url:(NSString *)url dic:(NSDictionary *)dic asset:(id)asset limitType:(AppPhototLimitType)limitType progress:(progressHandlerBlock)progress success:(successModelBlock)success failure:(failureModelBlock)failure; | 182 | +///// 请求token 单个视频上传 (video - 七牛短视频压缩 - 限制 - 筛选) |
| 183 | +//+ (void)uploadRequestWhithPLShortVideoType:(CNLiveUploadType)type outputPath:(NSString *)outputPath url:(NSString *)url dic:(NSDictionary *)dic asset:(id)asset limitType:(AppPhototLimitType)limitType progress:(progressHandlerBlock)progress success:(successModelBlock)success failure:(failureModelBlock)failure; | ||
| 184 | 184 | ||
| 185 | 185 | ||
| 186 | #pragma mark - 处理方法 | 186 | #pragma mark - 处理方法 |
| @@ -194,11 +194,11 @@ typedef void (^progressHandlerBlock)(float progress);//进度 | @@ -194,11 +194,11 @@ typedef void (^progressHandlerBlock)(float progress);//进度 | ||
| 194 | 194 | ||
| 195 | #pragma mark - 七牛短视频处理方法 | 195 | #pragma mark - 七牛短视频处理方法 |
| 196 | 196 | ||
| 197 | -/// 根据限制获取视频分辨率 | ||
| 198 | -+ (PLSFilePreset)presetWithVideoLimitType:(AppPhototLimitType)limitType url:(NSURL *)url dataL:(float)dataL; | ||
| 199 | - | ||
| 200 | -///根据分辨力设置码率 | ||
| 201 | -+ (float)bitrateWithPreset:(PLSFilePreset)perset avAsset:(AVAsset *)avAsset url:(NSURL *)url dataL:(float)dataL; | 197 | +///// 根据限制获取视频分辨率 |
| 198 | +//+ (PLSFilePreset)presetWithVideoLimitType:(AppPhototLimitType)limitType url:(NSURL *)url dataL:(float)dataL; | ||
| 199 | +// | ||
| 200 | +/////根据分辨力设置码率 | ||
| 201 | +//+ (float)bitrateWithPreset:(PLSFilePreset)perset avAsset:(AVAsset *)avAsset url:(NSURL *)url dataL:(float)dataL; | ||
| 202 | 202 | ||
| 203 | /** | 203 | /** |
| 204 | 短视频分辨率压缩导出 | 204 | 短视频分辨率压缩导出 |
| @@ -210,7 +210,7 @@ typedef void (^progressHandlerBlock)(float progress);//进度 | @@ -210,7 +210,7 @@ typedef void (^progressHandlerBlock)(float progress);//进度 | ||
| 210 | @param progressCount 进度 | 210 | @param progressCount 进度 |
| 211 | @param failure 是啊比 | 211 | @param failure 是啊比 |
| 212 | */ | 212 | */ |
| 213 | -+ (void)zipVideoWithAsset:(id) asset outputPath:(NSString *)outputPath limitType:(AppPhototLimitType)limitType success:(void(^)(NSURL * url))success progressCount:(void(^)(float progress)) progressCount failure:(void(^)(void))failure; | 213 | +//+ (void)zipVideoWithAsset:(id) asset outputPath:(NSString *)outputPath limitType:(AppPhototLimitType)limitType success:(void(^)(NSURL * url))success progressCount:(void(^)(float progress)) progressCount failure:(void(^)(void))failure; |
| 214 | 214 | ||
| 215 | 215 | ||
| 216 | 216 |
CNLiveUploadManager/CNLiveUploadManager.m renamed to CNLiveUploadManager/上传/CNLiveUploadManager.m
| @@ -1071,51 +1071,51 @@ static CNLiveUploadManager *_uploadManager; | @@ -1071,51 +1071,51 @@ static CNLiveUploadManager *_uploadManager; | ||
| 1071 | } | 1071 | } |
| 1072 | 1072 | ||
| 1073 | 1073 | ||
| 1074 | -///单个视频上传 - 压缩(七牛转码) - 限制 - 筛选) 实现 | ||
| 1075 | -- (void)uploadRequestPLShortVideoLimitWithToken:(NSString*)token asset:(id)asset outputPath:(NSString *)outputPath limitType:(AppPhototLimitType)limitType progress:(progressHandlerBlock)progress success:(successModelBlock)success failure:(failureModelBlock)failure { | ||
| 1076 | - | ||
| 1077 | - //七牛token | ||
| 1078 | - if ([NSString isEmpty:token]) { | ||
| 1079 | - NSError *error = [NSError errorWithDomain:@"七牛token为空" code:100 userInfo:@{NSLocalizedDescriptionKey:@"七牛token为空,请重新获取"}]; | ||
| 1080 | - !failure ? : failure(nil,error); | ||
| 1081 | - return; | ||
| 1082 | - } | ||
| 1083 | - | ||
| 1084 | - //上传路径 | ||
| 1085 | - if (!asset) { | ||
| 1086 | - NSError *error = [NSError errorWithDomain:@"上传路径为空" code:101 userInfo:@{NSLocalizedDescriptionKey:@"上传为空,请重新获取"}]; | ||
| 1087 | - !failure ? : failure(nil,error); | ||
| 1088 | - return; | ||
| 1089 | - } | ||
| 1090 | - | ||
| 1091 | - | ||
| 1092 | - __weak typeof(self) weakSelf = self; | ||
| 1093 | - | ||
| 1094 | - [CNLiveUploadManager zipVideoWithAsset:asset outputPath:outputPath limitType:limitType success:^(NSURL *url) { | ||
| 1095 | - __strong typeof(weakSelf) strongSelf = weakSelf; | ||
| 1096 | - AVAsset *avAsset = [AVAsset assetWithURL:url]; | ||
| 1097 | - NSLog(@"转码后时长%f",[[NSNumber numberWithFloat:CMTimeGetSeconds(avAsset.duration)] floatValue]); | ||
| 1098 | - NSLog(@"转码后数据大小%ldmb",[NSData dataWithContentsOfURL:url].length / (1024*1024)); | ||
| 1099 | - //不限制大小 | ||
| 1100 | - [strongSelf qnUploadVideoWithToken:token file:url.path progress:progress success:success failure:failure]; | ||
| 1101 | - | ||
| 1102 | - } progressCount:^(float progress) { | ||
| 1103 | - | ||
| 1104 | - // 更新压缩进度的 UI | ||
| 1105 | - NSLog(@"transCoding progress: %f", progress); | ||
| 1106 | - | ||
| 1107 | - } failure:^{ | ||
| 1108 | - | ||
| 1109 | - dispatch_async(dispatch_get_main_queue(), ^{ | ||
| 1110 | - NSError *returnError = [NSError errorWithDomain:@"压缩失败" code:105 userInfo:@{NSLocalizedDescriptionKey:@"压缩失败,请重新获取"}]; | ||
| 1111 | - !failure ? : failure(nil,returnError); | ||
| 1112 | - return; | ||
| 1113 | - | ||
| 1114 | - }); | ||
| 1115 | - | ||
| 1116 | - }]; | ||
| 1117 | - | ||
| 1118 | -} | 1074 | +/////单个视频上传 - 压缩(七牛转码) - 限制 - 筛选) 实现 |
| 1075 | +//- (void)uploadRequestPLShortVideoLimitWithToken:(NSString*)token asset:(id)asset outputPath:(NSString *)outputPath limitType:(AppPhototLimitType)limitType progress:(progressHandlerBlock)progress success:(successModelBlock)success failure:(failureModelBlock)failure { | ||
| 1076 | +// | ||
| 1077 | +// //七牛token | ||
| 1078 | +// if ([NSString isEmpty:token]) { | ||
| 1079 | +// NSError *error = [NSError errorWithDomain:@"七牛token为空" code:100 userInfo:@{NSLocalizedDescriptionKey:@"七牛token为空,请重新获取"}]; | ||
| 1080 | +// !failure ? : failure(nil,error); | ||
| 1081 | +// return; | ||
| 1082 | +// } | ||
| 1083 | +// | ||
| 1084 | +// //上传路径 | ||
| 1085 | +// if (!asset) { | ||
| 1086 | +// NSError *error = [NSError errorWithDomain:@"上传路径为空" code:101 userInfo:@{NSLocalizedDescriptionKey:@"上传为空,请重新获取"}]; | ||
| 1087 | +// !failure ? : failure(nil,error); | ||
| 1088 | +// return; | ||
| 1089 | +// } | ||
| 1090 | +// | ||
| 1091 | +// | ||
| 1092 | +// __weak typeof(self) weakSelf = self; | ||
| 1093 | +// | ||
| 1094 | +// [CNLiveUploadManager zipVideoWithAsset:asset outputPath:outputPath limitType:limitType success:^(NSURL *url) { | ||
| 1095 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | ||
| 1096 | +// AVAsset *avAsset = [AVAsset assetWithURL:url]; | ||
| 1097 | +// NSLog(@"转码后时长%f",[[NSNumber numberWithFloat:CMTimeGetSeconds(avAsset.duration)] floatValue]); | ||
| 1098 | +// NSLog(@"转码后数据大小%ldmb",[NSData dataWithContentsOfURL:url].length / (1024*1024)); | ||
| 1099 | +// //不限制大小 | ||
| 1100 | +// [strongSelf qnUploadVideoWithToken:token file:url.path progress:progress success:success failure:failure]; | ||
| 1101 | +// | ||
| 1102 | +// } progressCount:^(float progress) { | ||
| 1103 | +// | ||
| 1104 | +// // 更新压缩进度的 UI | ||
| 1105 | +// NSLog(@"transCoding progress: %f", progress); | ||
| 1106 | +// | ||
| 1107 | +// } failure:^{ | ||
| 1108 | +// | ||
| 1109 | +// dispatch_async(dispatch_get_main_queue(), ^{ | ||
| 1110 | +// NSError *returnError = [NSError errorWithDomain:@"压缩失败" code:105 userInfo:@{NSLocalizedDescriptionKey:@"压缩失败,请重新获取"}]; | ||
| 1111 | +// !failure ? : failure(nil,returnError); | ||
| 1112 | +// return; | ||
| 1113 | +// | ||
| 1114 | +// }); | ||
| 1115 | +// | ||
| 1116 | +// }]; | ||
| 1117 | +// | ||
| 1118 | +//} | ||
| 1119 | 1119 | ||
| 1120 | 1120 | ||
| 1121 | 1121 | ||
| @@ -1760,32 +1760,32 @@ static CNLiveUploadManager *_uploadManager; | @@ -1760,32 +1760,32 @@ static CNLiveUploadManager *_uploadManager; | ||
| 1760 | 1760 | ||
| 1761 | } | 1761 | } |
| 1762 | 1762 | ||
| 1763 | -/// 请求token 单个视频上传 (video - 七牛短视频压缩 - 限制 - 筛选) | ||
| 1764 | -+ (void)uploadRequestWhithPLShortVideoType:(CNLiveUploadType)type outputPath:(NSString *)outputPath url:(NSString *)url dic:(NSDictionary *)dic asset:(id)asset limitType:(AppPhototLimitType)limitType progress:(progressHandlerBlock)progress success:(successModelBlock)success failure:(failureModelBlock)failure { | ||
| 1765 | - | ||
| 1766 | - if (type == CNLiveUploadTypeQN) { //七牛上传 | ||
| 1767 | - [[HttpService service] sendRequestWithHttpMethod:E_HTTP_REQUEST_METHOD_POST URLPath:url parameters:dic isCache:NO CheckParam:nil completionHandler:^(id data, NSError *error) { | ||
| 1768 | - | ||
| 1769 | - NSDictionary *dic = (NSDictionary *)data; | ||
| 1770 | - if (!error && [dic containsObjectForKey:@"token"]) { | ||
| 1771 | - NSString *token = dic[@"token"]; | ||
| 1772 | - [[CNLiveUploadManager shareInsance] uploadRequestPLShortVideoLimitWithToken:token asset:asset outputPath:outputPath limitType:limitType progress:progress success:success failure:failure]; | ||
| 1773 | - | ||
| 1774 | - } else {//请求token失败 | ||
| 1775 | - NSError *error = [NSError errorWithDomain:@"请求token失败" code:100 userInfo:@{NSLocalizedDescriptionKey:@"请求token失败,请重新获取"}]; | ||
| 1776 | - !failure ? : failure(nil,error); | ||
| 1777 | - return; | ||
| 1778 | - } | ||
| 1779 | - | ||
| 1780 | - }]; | ||
| 1781 | - | ||
| 1782 | - }else if (type == CNLiveUploadTypeKS) { | ||
| 1783 | - | ||
| 1784 | - }else{ | ||
| 1785 | - | ||
| 1786 | - } | ||
| 1787 | - | ||
| 1788 | -} | 1763 | +///// 请求token 单个视频上传 (video - 七牛短视频压缩 - 限制 - 筛选) |
| 1764 | +//+ (void)uploadRequestWhithPLShortVideoType:(CNLiveUploadType)type outputPath:(NSString *)outputPath url:(NSString *)url dic:(NSDictionary *)dic asset:(id)asset limitType:(AppPhototLimitType)limitType progress:(progressHandlerBlock)progress success:(successModelBlock)success failure:(failureModelBlock)failure { | ||
| 1765 | +// | ||
| 1766 | +// if (type == CNLiveUploadTypeQN) { //七牛上传 | ||
| 1767 | +// [[HttpService service] sendRequestWithHttpMethod:E_HTTP_REQUEST_METHOD_POST URLPath:url parameters:dic isCache:NO CheckParam:nil completionHandler:^(id data, NSError *error) { | ||
| 1768 | +// | ||
| 1769 | +// NSDictionary *dic = (NSDictionary *)data; | ||
| 1770 | +// if (!error && [dic containsObjectForKey:@"token"]) { | ||
| 1771 | +// NSString *token = dic[@"token"]; | ||
| 1772 | +// [[CNLiveUploadManager shareInsance] uploadRequestPLShortVideoLimitWithToken:token asset:asset outputPath:outputPath limitType:limitType progress:progress success:success failure:failure]; | ||
| 1773 | +// | ||
| 1774 | +// } else {//请求token失败 | ||
| 1775 | +// NSError *error = [NSError errorWithDomain:@"请求token失败" code:100 userInfo:@{NSLocalizedDescriptionKey:@"请求token失败,请重新获取"}]; | ||
| 1776 | +// !failure ? : failure(nil,error); | ||
| 1777 | +// return; | ||
| 1778 | +// } | ||
| 1779 | +// | ||
| 1780 | +// }]; | ||
| 1781 | +// | ||
| 1782 | +// }else if (type == CNLiveUploadTypeKS) { | ||
| 1783 | +// | ||
| 1784 | +// }else{ | ||
| 1785 | +// | ||
| 1786 | +// } | ||
| 1787 | +// | ||
| 1788 | +//} | ||
| 1789 | 1789 | ||
| 1790 | 1790 | ||
| 1791 | #pragma mark - 私有方法 | 1791 | #pragma mark - 私有方法 |
| @@ -1865,173 +1865,173 @@ static CNLiveUploadManager *_uploadManager; | @@ -1865,173 +1865,173 @@ static CNLiveUploadManager *_uploadManager; | ||
| 1865 | 1865 | ||
| 1866 | #pragma mark - 七牛短视频设置方法 | 1866 | #pragma mark - 七牛短视频设置方法 |
| 1867 | 1867 | ||
| 1868 | -/// 短视频分辨率转码导出 | ||
| 1869 | -+ (void)zipVideoWithAsset:(id) asset outputPath:(NSString *)outputPath limitType:(AppPhototLimitType)limitType success:(void(^)(NSURL * url))success progressCount:(void(^)(float progress)) progressCount failure:(void(^)(void))failure { | ||
| 1870 | - | ||
| 1871 | - //取得url | ||
| 1872 | - NSURL *url = [PHAsset movieURLWithAsset:asset]; | ||
| 1873 | - NSInteger dataLInt = [NSData dataWithContentsOfURL:url].length; | ||
| 1874 | - NSNumber *dataNumber = [NSNumber numberWithInteger:dataLInt]; | ||
| 1875 | - float dataL = [dataNumber floatValue]; | ||
| 1876 | - NSLog(@"转码前数据大小%f",dataL / (1024.0*1024.0)); | ||
| 1877 | - //编辑原始数据 | ||
| 1878 | - NSMutableDictionary *movieSettings = [[NSMutableDictionary alloc]init]; | ||
| 1879 | - AVAsset *avAsset = [AVAsset assetWithURL:url]; | ||
| 1880 | - movieSettings[PLSURLKey] = url; | ||
| 1881 | - movieSettings[PLSAssetKey] = avAsset; | ||
| 1882 | - movieSettings[PLSStartTimeKey] = [NSNumber numberWithFloat:0.f];//开始时间 | ||
| 1883 | - movieSettings[PLSDurationKey] = [NSNumber numberWithFloat:CMTimeGetSeconds(avAsset.duration)];//时长 | ||
| 1884 | - //设置进行压缩 | ||
| 1885 | - CGFloat start = [movieSettings[PLSStartTimeKey] floatValue]; | ||
| 1886 | - CGFloat duration = [movieSettings[PLSDurationKey] floatValue]; | ||
| 1887 | - NSLog(@"转码前输出时长:%f.2",duration); | ||
| 1888 | - CMTimeRange timeRange = CMTimeRangeMake(CMTimeMake(start * 1000, 1000), CMTimeMake(duration * 1000, 1000)); | ||
| 1889 | - PLShortVideoTranscoder *shortVideoTranscoder = [[PLShortVideoTranscoder alloc] initWithURL:url]; | ||
| 1890 | - | ||
| 1891 | - NSString *path = [NSString string]; | ||
| 1892 | - if (outputPath.length <= 0 || outputPath) { | ||
| 1893 | - NSDateFormatter *formater = [[NSDateFormatter alloc] init]; | ||
| 1894 | - [formater setDateFormat:@"yyyy-MM-dd-HH:mm:ss-SSS"]; | ||
| 1895 | - path = [NSHomeDirectory() stringByAppendingFormat:@"/tmp/output-%@.mp4", [formater stringFromDate:[NSDate date]]]; | ||
| 1896 | - | ||
| 1897 | - }else { | ||
| 1898 | - path = outputPath; | ||
| 1899 | - } | ||
| 1900 | - | ||
| 1901 | - NSLog(@"输出转码前视频路径%@",path); | ||
| 1902 | - shortVideoTranscoder.outputURL = [NSURL fileURLWithPath:path]; | ||
| 1903 | - shortVideoTranscoder.outputFileType = PLSFileTypeMPEG4; | ||
| 1904 | - shortVideoTranscoder.outputFilePreset = [CNLiveUploadManager presetWithVideoLimitType:limitType url:url dataL:dataL];//分辨率 | ||
| 1905 | - shortVideoTranscoder.bitrate = [CNLiveUploadManager bitrateWithPreset:shortVideoTranscoder.outputFilePreset avAsset:avAsset url:url dataL:dataL]; | ||
| 1906 | - shortVideoTranscoder.timeRange = timeRange; | ||
| 1907 | - shortVideoTranscoder.rotateOrientation = PLSPreviewOrientationPortrait; //视频显示 | ||
| 1908 | - shortVideoTranscoder.videoSelectedRect = CGRectZero; //视频剪裁区域 | ||
| 1909 | - shortVideoTranscoder.videoFrameRate = 0; //帧率 | ||
| 1910 | - //成功 | ||
| 1911 | - [shortVideoTranscoder setCompletionBlock:^(NSURL *url){ | ||
| 1912 | - NSLog(@"输出转码后视频路径%@",url.path); | ||
| 1913 | - NSLog(@"输出转码后数据大小%ld",[NSData dataWithContentsOfURL:url].length / (1024*1024)); | ||
| 1914 | - dispatch_async(dispatch_get_main_queue(), ^{ | ||
| 1915 | - !success ? : success(url); | ||
| 1916 | - }); | ||
| 1917 | - | ||
| 1918 | - }]; | ||
| 1919 | - | ||
| 1920 | - //失败 | ||
| 1921 | - [shortVideoTranscoder setFailureBlock:^(NSError *error){ | ||
| 1922 | - NSLog(@"输出错误%@",error); | ||
| 1923 | - dispatch_async(dispatch_get_main_queue(), ^{ | ||
| 1924 | - !failure ? : failure(); | ||
| 1925 | - }); | ||
| 1926 | - | ||
| 1927 | - }]; | ||
| 1928 | - | ||
| 1929 | - [shortVideoTranscoder setProcessingBlock:^(float progress){ | ||
| 1930 | - // 更新压缩进度的 UI | ||
| 1931 | - | ||
| 1932 | - NSLog(@"transCoding progress: %f", progress); | ||
| 1933 | - !progressCount ? : progressCount(progress); | ||
| 1934 | - }]; | ||
| 1935 | - | ||
| 1936 | - [shortVideoTranscoder startTranscoding]; | ||
| 1937 | - | ||
| 1938 | - | ||
| 1939 | -} | ||
| 1940 | - | ||
| 1941 | -/// 根据限制获取视频分辨率 | ||
| 1942 | -+ (PLSFilePreset)presetWithVideoLimitType:(AppPhototLimitType)limitType url:(NSURL *)url dataL:(float)dataL{ | ||
| 1943 | - | ||
| 1944 | - NSLog(@"1输出转码前数据长度%f",(dataL/(1024.0*1024))); | ||
| 1945 | - if (limitType == AppPhototLimitTypeChat) {//聊天 | ||
| 1946 | - if (dataL > kCNUploadSize30MB) { | ||
| 1947 | - return PLSFilePreset640x480; | ||
| 1948 | - }else { | ||
| 1949 | - return PLSFilePreset960x540; | ||
| 1950 | - } | ||
| 1951 | - | ||
| 1952 | - }else if (limitType == AppPhototLimitTypeFriendsCircle) {//朋友圈 | ||
| 1953 | - if (dataL > kCNUploadSize30MB) { | ||
| 1954 | - return PLSFilePreset640x480; | ||
| 1955 | - }else { | ||
| 1956 | - return PLSFilePreset960x540; | ||
| 1957 | - } | ||
| 1958 | - | ||
| 1959 | - }else if (limitType == AppPhototLimitTypeSweepCode) {//扫码 | ||
| 1960 | - if (dataL > kCNUploadSize30MB) { | ||
| 1961 | - return PLSFilePreset640x480; | ||
| 1962 | - }else { | ||
| 1963 | - return PLSFilePreset960x540; | ||
| 1964 | - } | ||
| 1965 | - }else if (limitType == AppPhototLimitTypeTarentoComment) {//评论 | ||
| 1966 | - if (dataL > kCNUploadSize30MB) { | ||
| 1967 | - return PLSFilePreset640x480; | ||
| 1968 | - }else { | ||
| 1969 | - return PLSFilePreset960x540; | ||
| 1970 | - } | ||
| 1971 | - | ||
| 1972 | - }else { | ||
| 1973 | - if (dataL > kCNUploadSize30MB) {//其他 | ||
| 1974 | - return PLSFilePreset640x480; | ||
| 1975 | - }else { | ||
| 1976 | - return PLSFilePreset960x540; | ||
| 1977 | - } | ||
| 1978 | - } | ||
| 1979 | - | ||
| 1980 | -} | ||
| 1981 | - | ||
| 1982 | -///根据分辨力设置码率 | ||
| 1983 | -+ (float)bitrateWithPreset:(PLSFilePreset)perset avAsset:(AVAsset *)avAsset url:(NSURL *)url dataL:(float)dataL{ | ||
| 1984 | - | ||
| 1985 | - float bitrate = avAsset.pls_bitrate; | ||
| 1986 | - | ||
| 1987 | - if (perset == PLSFilePresetLowQuality) { | ||
| 1988 | - return 700 * 1000; | ||
| 1989 | - }else if (perset == PLSFilePresetMediumQuality) { | ||
| 1990 | - return 3000 * 1000; | ||
| 1991 | - }else if (perset == PLSFilePresetHighestQuality) { | ||
| 1992 | - return 6000 * 1000; | ||
| 1993 | - }else { | ||
| 1994 | - if (dataL > 150*1024*1024) { | ||
| 1995 | - float scale = (20*1024*1024)/dataL; | ||
| 1996 | - if (bitrate *scale > 300 * 1000) { | ||
| 1997 | - return 300 *1000; | ||
| 1998 | - }else { | ||
| 1999 | - return bitrate *scale; | ||
| 2000 | - } | ||
| 2001 | - }else if (dataL > 50*1024*1024) { | ||
| 2002 | - float scale = (25*1024*1024)/dataL; | ||
| 2003 | - if (bitrate *scale > 400 * 1000) { | ||
| 2004 | - return 400 *1000; | ||
| 2005 | - }else { | ||
| 2006 | - return bitrate *scale; | ||
| 2007 | - } | ||
| 2008 | - | ||
| 2009 | - }else if (dataL > 40*1024*1024) { | ||
| 2010 | - if (bitrate *0.4 > 550 * 1000) { | ||
| 2011 | - return 550 *1000; | ||
| 2012 | - }else { | ||
| 2013 | - return bitrate *0.40; | ||
| 2014 | - } | ||
| 2015 | - | ||
| 2016 | - }else if (dataL > 30*1024*1024) { | ||
| 2017 | - | ||
| 2018 | - if (bitrate *0.60 > 700 * 1000) { | ||
| 2019 | - return 700 *1000; | ||
| 2020 | - }else { | ||
| 2021 | - return bitrate *0.60; | ||
| 2022 | - } | ||
| 2023 | - }else if (dataL > 20*1024*1024) { | ||
| 2024 | - | ||
| 2025 | - return bitrate *0.80; | ||
| 2026 | - }else if (dataL > 10*1024*1024) { | 1868 | +///// 短视频分辨率转码导出 |
| 1869 | +//+ (void)zipVideoWithAsset:(id) asset outputPath:(NSString *)outputPath limitType:(AppPhototLimitType)limitType success:(void(^)(NSURL * url))success progressCount:(void(^)(float progress)) progressCount failure:(void(^)(void))failure { | ||
| 1870 | +// | ||
| 1871 | +// //取得url | ||
| 1872 | +// NSURL *url = [PHAsset movieURLWithAsset:asset]; | ||
| 1873 | +// NSInteger dataLInt = [NSData dataWithContentsOfURL:url].length; | ||
| 1874 | +// NSNumber *dataNumber = [NSNumber numberWithInteger:dataLInt]; | ||
| 1875 | +// float dataL = [dataNumber floatValue]; | ||
| 1876 | +// NSLog(@"转码前数据大小%f",dataL / (1024.0*1024.0)); | ||
| 1877 | +// //编辑原始数据 | ||
| 1878 | +// NSMutableDictionary *movieSettings = [[NSMutableDictionary alloc]init]; | ||
| 1879 | +// AVAsset *avAsset = [AVAsset assetWithURL:url]; | ||
| 1880 | +// movieSettings[PLSURLKey] = url; | ||
| 1881 | +// movieSettings[PLSAssetKey] = avAsset; | ||
| 1882 | +// movieSettings[PLSStartTimeKey] = [NSNumber numberWithFloat:0.f];//开始时间 | ||
| 1883 | +// movieSettings[PLSDurationKey] = [NSNumber numberWithFloat:CMTimeGetSeconds(avAsset.duration)];//时长 | ||
| 1884 | +// //设置进行压缩 | ||
| 1885 | +// CGFloat start = [movieSettings[PLSStartTimeKey] floatValue]; | ||
| 1886 | +// CGFloat duration = [movieSettings[PLSDurationKey] floatValue]; | ||
| 1887 | +// NSLog(@"转码前输出时长:%f.2",duration); | ||
| 1888 | +// CMTimeRange timeRange = CMTimeRangeMake(CMTimeMake(start * 1000, 1000), CMTimeMake(duration * 1000, 1000)); | ||
| 1889 | +// PLShortVideoTranscoder *shortVideoTranscoder = [[PLShortVideoTranscoder alloc] initWithURL:url]; | ||
| 1890 | +// | ||
| 1891 | +// NSString *path = [NSString string]; | ||
| 1892 | +// if (outputPath.length <= 0 || outputPath) { | ||
| 1893 | +// NSDateFormatter *formater = [[NSDateFormatter alloc] init]; | ||
| 1894 | +// [formater setDateFormat:@"yyyy-MM-dd-HH:mm:ss-SSS"]; | ||
| 1895 | +// path = [NSHomeDirectory() stringByAppendingFormat:@"/tmp/output-%@.mp4", [formater stringFromDate:[NSDate date]]]; | ||
| 1896 | +// | ||
| 1897 | +// }else { | ||
| 1898 | +// path = outputPath; | ||
| 1899 | +// } | ||
| 1900 | +// | ||
| 1901 | +// NSLog(@"输出转码前视频路径%@",path); | ||
| 1902 | +// shortVideoTranscoder.outputURL = [NSURL fileURLWithPath:path]; | ||
| 1903 | +// shortVideoTranscoder.outputFileType = PLSFileTypeMPEG4; | ||
| 1904 | +// shortVideoTranscoder.outputFilePreset = [CNLiveUploadManager presetWithVideoLimitType:limitType url:url dataL:dataL];//分辨率 | ||
| 1905 | +// shortVideoTranscoder.bitrate = [CNLiveUploadManager bitrateWithPreset:shortVideoTranscoder.outputFilePreset avAsset:avAsset url:url dataL:dataL]; | ||
| 1906 | +// shortVideoTranscoder.timeRange = timeRange; | ||
| 1907 | +// shortVideoTranscoder.rotateOrientation = PLSPreviewOrientationPortrait; //视频显示 | ||
| 1908 | +// shortVideoTranscoder.videoSelectedRect = CGRectZero; //视频剪裁区域 | ||
| 1909 | +// shortVideoTranscoder.videoFrameRate = 0; //帧率 | ||
| 1910 | +// //成功 | ||
| 1911 | +// [shortVideoTranscoder setCompletionBlock:^(NSURL *url){ | ||
| 1912 | +// NSLog(@"输出转码后视频路径%@",url.path); | ||
| 1913 | +// NSLog(@"输出转码后数据大小%ld",[NSData dataWithContentsOfURL:url].length / (1024*1024)); | ||
| 1914 | +// dispatch_async(dispatch_get_main_queue(), ^{ | ||
| 1915 | +// !success ? : success(url); | ||
| 1916 | +// }); | ||
| 1917 | +// | ||
| 1918 | +// }]; | ||
| 1919 | +// | ||
| 1920 | +// //失败 | ||
| 1921 | +// [shortVideoTranscoder setFailureBlock:^(NSError *error){ | ||
| 1922 | +// NSLog(@"输出错误%@",error); | ||
| 1923 | +// dispatch_async(dispatch_get_main_queue(), ^{ | ||
| 1924 | +// !failure ? : failure(); | ||
| 1925 | +// }); | ||
| 1926 | +// | ||
| 1927 | +// }]; | ||
| 1928 | +// | ||
| 1929 | +// [shortVideoTranscoder setProcessingBlock:^(float progress){ | ||
| 1930 | +// // 更新压缩进度的 UI | ||
| 1931 | +// | ||
| 1932 | +// NSLog(@"transCoding progress: %f", progress); | ||
| 1933 | +// !progressCount ? : progressCount(progress); | ||
| 1934 | +// }]; | ||
| 1935 | +// | ||
| 1936 | +// [shortVideoTranscoder startTranscoding]; | ||
| 1937 | +// | ||
| 1938 | +// | ||
| 1939 | +//} | ||
| 2027 | 1940 | ||
| 2028 | - return bitrate *0.9; | ||
| 2029 | - }else { | ||
| 2030 | - return bitrate; | ||
| 2031 | - } | ||
| 2032 | - } | 1941 | +///// 根据限制获取视频分辨率 |
| 1942 | +//+ (PLSFilePreset)presetWithVideoLimitType:(AppPhototLimitType)limitType url:(NSURL *)url dataL:(float)dataL{ | ||
| 1943 | +// | ||
| 1944 | +// NSLog(@"1输出转码前数据长度%f",(dataL/(1024.0*1024))); | ||
| 1945 | +// if (limitType == AppPhototLimitTypeChat) {//聊天 | ||
| 1946 | +// if (dataL > kCNUploadSize30MB) { | ||
| 1947 | +// return PLSFilePreset640x480; | ||
| 1948 | +// }else { | ||
| 1949 | +// return PLSFilePreset960x540; | ||
| 1950 | +// } | ||
| 1951 | +// | ||
| 1952 | +// }else if (limitType == AppPhototLimitTypeFriendsCircle) {//朋友圈 | ||
| 1953 | +// if (dataL > kCNUploadSize30MB) { | ||
| 1954 | +// return PLSFilePreset640x480; | ||
| 1955 | +// }else { | ||
| 1956 | +// return PLSFilePreset960x540; | ||
| 1957 | +// } | ||
| 1958 | +// | ||
| 1959 | +// }else if (limitType == AppPhototLimitTypeSweepCode) {//扫码 | ||
| 1960 | +// if (dataL > kCNUploadSize30MB) { | ||
| 1961 | +// return PLSFilePreset640x480; | ||
| 1962 | +// }else { | ||
| 1963 | +// return PLSFilePreset960x540; | ||
| 1964 | +// } | ||
| 1965 | +// }else if (limitType == AppPhototLimitTypeTarentoComment) {//评论 | ||
| 1966 | +// if (dataL > kCNUploadSize30MB) { | ||
| 1967 | +// return PLSFilePreset640x480; | ||
| 1968 | +// }else { | ||
| 1969 | +// return PLSFilePreset960x540; | ||
| 1970 | +// } | ||
| 1971 | +// | ||
| 1972 | +// }else { | ||
| 1973 | +// if (dataL > kCNUploadSize30MB) {//其他 | ||
| 1974 | +// return PLSFilePreset640x480; | ||
| 1975 | +// }else { | ||
| 1976 | +// return PLSFilePreset960x540; | ||
| 1977 | +// } | ||
| 1978 | +// } | ||
| 1979 | +// | ||
| 1980 | +//} | ||
| 2033 | 1981 | ||
| 2034 | -} | 1982 | +/////根据分辨力设置码率 |
| 1983 | +//+ (float)bitrateWithPreset:(PLSFilePreset)perset avAsset:(AVAsset *)avAsset url:(NSURL *)url dataL:(float)dataL{ | ||
| 1984 | +// | ||
| 1985 | +// float bitrate = avAsset.pls_bitrate; | ||
| 1986 | +// | ||
| 1987 | +// if (perset == PLSFilePresetLowQuality) { | ||
| 1988 | +// return 700 * 1000; | ||
| 1989 | +// }else if (perset == PLSFilePresetMediumQuality) { | ||
| 1990 | +// return 3000 * 1000; | ||
| 1991 | +// }else if (perset == PLSFilePresetHighestQuality) { | ||
| 1992 | +// return 6000 * 1000; | ||
| 1993 | +// }else { | ||
| 1994 | +// if (dataL > 150*1024*1024) { | ||
| 1995 | +// float scale = (20*1024*1024)/dataL; | ||
| 1996 | +// if (bitrate *scale > 300 * 1000) { | ||
| 1997 | +// return 300 *1000; | ||
| 1998 | +// }else { | ||
| 1999 | +// return bitrate *scale; | ||
| 2000 | +// } | ||
| 2001 | +// }else if (dataL > 50*1024*1024) { | ||
| 2002 | +// float scale = (25*1024*1024)/dataL; | ||
| 2003 | +// if (bitrate *scale > 400 * 1000) { | ||
| 2004 | +// return 400 *1000; | ||
| 2005 | +// }else { | ||
| 2006 | +// return bitrate *scale; | ||
| 2007 | +// } | ||
| 2008 | +// | ||
| 2009 | +// }else if (dataL > 40*1024*1024) { | ||
| 2010 | +// if (bitrate *0.4 > 550 * 1000) { | ||
| 2011 | +// return 550 *1000; | ||
| 2012 | +// }else { | ||
| 2013 | +// return bitrate *0.40; | ||
| 2014 | +// } | ||
| 2015 | +// | ||
| 2016 | +// }else if (dataL > 30*1024*1024) { | ||
| 2017 | +// | ||
| 2018 | +// if (bitrate *0.60 > 700 * 1000) { | ||
| 2019 | +// return 700 *1000; | ||
| 2020 | +// }else { | ||
| 2021 | +// return bitrate *0.60; | ||
| 2022 | +// } | ||
| 2023 | +// }else if (dataL > 20*1024*1024) { | ||
| 2024 | +// | ||
| 2025 | +// return bitrate *0.80; | ||
| 2026 | +// }else if (dataL > 10*1024*1024) { | ||
| 2027 | +// | ||
| 2028 | +// return bitrate *0.9; | ||
| 2029 | +// }else { | ||
| 2030 | +// return bitrate; | ||
| 2031 | +// } | ||
| 2032 | +// } | ||
| 2033 | +// | ||
| 2034 | +//} | ||
| 2035 | 2035 | ||
| 2036 | 2036 | ||
| 2037 | #pragma mark - 金山 | 2037 | #pragma mark - 金山 |
CNLiveUploadManager/PHAsset+zipData.h renamed to CNLiveUploadManager/压缩图片/PHAsset+zipData.h
CNLiveUploadManager/PHAsset+zipData.m renamed to CNLiveUploadManager/压缩图片/PHAsset+zipData.m
CNLiveUploadManager/UIImage+Luban_iOS_Extension.h renamed to CNLiveUploadManager/压缩图片/UIImage+Luban_iOS_Extension.h
CNLiveUploadManager/UIImage+Luban_iOS_Extension.m renamed to CNLiveUploadManager/压缩图片/UIImage+Luban_iOS_Extension.m
CNLiveUploadManager/UIImage+zipData.h renamed to CNLiveUploadManager/压缩图片/UIImage+zipData.h
CNLiveUploadManager/UIImage+zipData.m renamed to CNLiveUploadManager/压缩图片/UIImage+zipData.m