iOS开发之MOV视频文件转mp4视频文件

iOS开发将MOV格式的视频文件转换成mp4格式的视频文件相关代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
NSString *url = [NSTemporaryDirectory() stringByAppendingPathComponent:@"sourceVideo.mov"];
NSURL *sourceUrl = [NSURL fileURLWithPath:url];
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:sourceUrl options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
if ([compatiblePresets containsObject:AVAssetExportPreset640x480]) {
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPreset640x480];
// 转换后的视频本地路径
exportSession.outputURL = [NSURL fileURLWithPath:outputPath];
// 转换的目的视频格式
exportSession.outputFileType = AVFileTypeMPEG4;
// 网络使用时最优化
exportSession.shouldOptimizeForNetworkUse = YES;
// 开始异步转换视频
[exportSession exportAsynchronouslyWithCompletionHandler:^(void) {
switch (exportSession.status) {
case AVAssetExportSessionStatusUnknown:
break;
case AVAssetExportSessionStatusWaiting:
break;
case AVAssetExportSessionStatusExporting:
break;
case AVAssetExportSessionStatusCompleted:
// 转换成功
break;
case AVAssetExportSessionStatusFailed:
break;
case AVAssetExportSessionStatusCancelled:
break;
}
}];
}

© 2021 cyruschang All Rights Reserved.
Theme by hiero