[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$fWofPyLIJI19itEfIz5xjzort6uCnEmZcNlomrM-HyTE":3},{"code":4,"message":5,"data":6},200,"成功",{"id":7,"createdAt":8,"title":9,"content":10,"summary":11,"image":12,"uid":13,"user":14,"categoryId":21,"category":22,"subCategoryId":24,"subCategory":25,"comments":27,"status":17,"reason":12,"notice":12,"visitCount":28,"commentCount":29,"keywords":30},76,"2024-02-02T11:22:52.778Z","iOS中对视频进行压缩","iOS中如何压缩视频，这里给出一个选择，仅供参考。\n\n代码如下：\n```\n+ (void)compressVideoWithSourceVideoPathString:(NSString *)sourceVideoPathString\n                                  CompressType:(NSString *)compressType\n                          CompressSuccessBlock:(SuccessBlock)compressSuccessBlock\n                           CompressFailedBlock:(FailedBlock)compressFailedBlock\n                       CompressNotSupportBlock:(NotSupportBlock)compressNotSupportBlock {\n    \n    // 源视频路径\n    NSURL *sourceVideoPathUrl = [NSURL fileURLWithPath:sourceVideoPathString];\n    // 利用源视频路径将源视频转化为 AVAsset 多媒体载体对象\n    AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:sourceVideoPathUrl options:nil];\n    \n    // 源视频载体对象支持的压缩格式\n    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];\n    // 源视频载体对象支持的压缩格式中是否包含我们选择的压缩格式\n    if ([compatiblePresets containsObject:compressType]) {\n        \n        // 存放压缩视频的文件夹\n        NSFileManager *fileManager = [NSFileManager defaultManager];\n        NSString *compressVideoFolder = [NSHomeDirectory() stringByAppendingPathComponent:@\"/Documents/compressVideoFolder\"];\n        if (![fileManager fileExistsAtPath:compressVideoFolder]) {\n            \n            [fileManager createDirectoryAtPath:compressVideoFolder withIntermediateDirectories:YES attributes:nil error:nil];\n        }\n        // 用当前系统时间给文件命名, 避免因名字重复而覆盖存储\n        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];\n        [formatter setDateFormat:@\"yyyy-MM-dd-HH:mm:ss\"];\n        NSString *currentDateString = [formatter stringFromDate:[NSDate date]];\n        \n        /**\n         *  第一个参数 : 要压缩的 AVAsset 对象\n            第二个参数 : 我们选择的压缩方式\n         */\n        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:compressType];\n        // 压缩视频的输出路径\n        NSString *compressVideoPathString = [compressVideoFolder stringByAppendingPathComponent:[NSString stringWithFormat:@\"compressVideo-%@.mp4\", currentDateString]];\n        NSURL *compressFilePathUrl = [NSURL fileURLWithPath:compressVideoPathString];\n        exportSession.outputURL = compressFilePathUrl;\n        // 压缩文件的输出格式\n        exportSession.outputFileType = AVFileTypeMPEG4;\n        // 压缩文件应保证优化网络使用\n        exportSession.shouldOptimizeForNetworkUse = YES;\n        // 开始压缩\n        [exportSession exportAsynchronouslyWithCompletionHandler:^(void) {\n            \n            if (exportSession.status == AVAssetExportSessionStatusCompleted) {\n                \n                compressSuccessBlock(compressVideoPathString);\n            }else {\n                \n                compressFailedBlock();\n            }\n        }];\n    }else {\n        \n        compressNotSupportBlock();\n    }\n}\n```","iOS中如何压缩视频，这里给出一个选择，仅供参考。","",499668042977349,{"phone":15,"userId":13,"nickName":16,"vipType":17,"avatar":18,"sign":19,"createdAt":20},"13121171998","全栈老韩",1,"https://image.xinwei.ltd/images/IMG_5430.JPG","全栈工程师，擅长iOS App开发、前端（vue、react、nuxt、小程序&Taro）开发、Flutter、React Native、后端（midwayjs、golang、express、koa）开发、docker容器、seo优化等。","2024-01-01T16:14:30.305Z",2,{"id":21,"name":23},"IT技术",3,{"id":24,"name":26,"parentId":21},"iOS",[],26,0,"ios,ios compress,ios video,ios compress video,ios压缩视频,ios视频"]