无法将iOS中的.avi转换为.mp4目标-c
我正在使用相机记录视频并将它们保存到我的文档文件夹中。我面临的问题是,我从相机获得的视频是.avi文件,必须转换为.mp4(或任何其他允许的格式)。无法将iOS中的.avi转换为.mp4目标-c
我用下面的代码:
来源:iOS Convert AVI to MP4 Format programatically
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"MyVideo.mp4"];
NSURL *outputURL = [NSURL fileURLWithPath:filePath];
[self convertVideoToLowQuailtyWithInputURL:localUrl outputURL:outputURL handler:^(AVAssetExportSession *exportSession)
{
if (exportSession.status == AVAssetExportSessionStatusCompleted) {
// Video conversation completed
}
}];
- (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL outputURL:(NSURL*)outputURL handler:(void (^)(AVAssetExportSession*))handler {
[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetPassthrough];
exportSession.outputURL = outputURL;
exportSession.outputFileType = AVFileTypeMPEG4;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void) {
handler(exportSession);
}];
}
的exportSession状态总是失败。但是,当我尝试将.mov转换为.mp4是行不通的。
我怎样才能将.avi文件转换为.mp4文件?
尝试打印错误消息:
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:
NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
case AVAssetExportSessionStatusCompleted:
NSLog(@"Successfully");
break;
default:
break;
}
}];
}
是的,你是对的,这是我的第一个答案,我已经改变了格式 – CharmingQin
问题是,localizedDescription并不真正有用。 输出为'导出失败:操作无法完成'。 – Milander
@Milander thx为您的建议 – CharmingQin
什么是AVI视频里面的视频编解码器?如果您不知道AVI的详细信息,请使用** MediaInfo **(检查为“文本”模式)等工具。 –
所有信息MediaInfo给了我: 275 kb/s,640x480(4:3),在10.000 FPS,AVS(Baseline @ L3)(1 Ref frame)@ VC.One – Milander
_“** AVS ** @ L3)“_ ??是错字吗?如果实际上你的意思是** AVC **,那么你有一个MP4容器兼容的视频编解码器......是否有正确的编解码器(AAC或MP3)的声音?当你说_“exportSession状态总是失败”_没有其他有用的错误信息?如果问题不是视频编解码器,不是音频编解码器,那么问题必须是AVI文件本身。相机品牌也可能会制造一些奇怪的自定义AVI容器字节。 –