// 视频转码
- (void) convertVideoWithModel:(NSString *) localVideoPath {
TYWeakify(self, weakSelf);
//转码配置
NSURL *inputURL = [NSURL fileURLWithPath:localVideoPath];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
AVAssetExportSession *exportSession= [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPreset960x540];
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@.mp4",localVideoPath]]; //转码后的视频保存目录
self.liveShareView.localVideoURL = [NSString stringWithFormat:@"%@.mp4",localVideoPath];
exportSession.outputFileType = AVFileTypeMPEG4;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
int exportStatus = exportSession.status;
switch (exportStatus) {
case AVAssetExportSessionStatusFailed: {
NSError *exportError = exportSession.error;
NSLog (@"AVAssetExportSessionStatusFailed: %@", exportError);
break;
}
case AVAssetExportSessionStatusCompleted: {
NSLog(@"视频转码成功");
[weakSelf uploadVideo];
}
}
}];
}
- (void) convertVideoWithModel:(NSString *) localVideoPath {
TYWeakify(self, weakSelf);
//转码配置
NSURL *inputURL = [NSURL fileURLWithPath:localVideoPath];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
AVAssetExportSession *exportSession= [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPreset960x540];
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@.mp4",localVideoPath]]; //转码后的视频保存目录
self.liveShareView.localVideoURL = [NSString stringWithFormat:@"%@.mp4",localVideoPath];
exportSession.outputFileType = AVFileTypeMPEG4;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
int exportStatus = exportSession.status;
switch (exportStatus) {
case AVAssetExportSessionStatusFailed: {
NSError *exportError = exportSession.error;
NSLog (@"AVAssetExportSessionStatusFailed: %@", exportError);
break;
}
case AVAssetExportSessionStatusCompleted: {
NSLog(@"视频转码成功");
[weakSelf uploadVideo];
}
}
}];
}