我正在为 iPhone 中的 Play Station 3 开发媒体服务器。
我开始知道 PS3 不支持 .MOV 文件,所以我必须将它转换成 Mp4 或其他 PS3 支持的转码。
这就是我所做的,但是如果我设置的文件类型与其源文件不同,它会崩溃。
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetLowQuality];
exportSession.outputURL = [NSURL fileURLWithPath:videoPath];
exportSession.outputFileType = AVFileTypeMPEG4;
CMTime start = CMTimeMakeWithSeconds(1.0, 600);
CMTime duration = CMTimeMakeWithSeconds(3.0, 600);
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:
NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
default:
break;
}
[exportSession release];
}];
}
如果我在这里设置 AVFileTypeMPEG4 然后它崩溃,说“无效的文件类型”。所以我必须将它设置为 AVFileTypeQuickTimeMovie 并提供 MOV 文件。
在 iOS 中是否可以通过 AVAssetExportSession 将视频从 MOV 转换为 Mp4 ......或者没有任何第三方库?
最佳答案
presetName 使用“AVAssetExportPresetPassthrough”代替“AVAssetExportPresetLowQuality”
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
关于iphone - MOV 以编程方式将 iPhone 转换为 Mp4 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8474517/