无法在iOS Objective-C中将.avi转换为.mp4 [英] Failed to convert .avi to .mp4 in iOS objective-c

查看:131
本文介绍了无法在iOS Objective-C中将.avi转换为.mp4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用相机录制视频并将其保存到我的文档文件夹中.我面临的问题是,我从摄像机获得的视频是.avi文件,必须将其转换为.mp4(或任何其他允许的格式).

I am using a camera to record video's and save them into my documents folder. The problem I am facing is that the video's I got from the camera are .avi files and have to be converted to .mp4 (or any other allowed format).

我使用以下代码:
来源: iOS通过编程将AVI转换为MP4格式

I use the code below:
SOURCE: 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时,它确实可以工作.

the exportSession status always fails. But when i try to convert a .mov into a .mp4 is does work.

为什么我不能将.avi文件转换成.mp4文件?

How come I cannot convert .avi files into .mp4 files ?

推荐答案

尝试打印错误消息:

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;
        }

    }];
}

这篇关于无法在iOS Objective-C中将.avi转换为.mp4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆