首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVAssetExportSession :操作无法完成

AVAssetExportSession :操作无法完成
EN

Stack Overflow用户
提问于 2013-07-25 08:52:47
回答 1查看 2.6K关注 0票数 2

我使用UIImagePickerController将视频从MOV转换为MP4,但结果是:

代码转换失败:操作无法完成

以下是代码:

代码语言:javascript
复制
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    NSLog(@"UIImagePickerController mediaType: %@", mediaType);
    if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
        NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
        AVAsset *asset = [AVAsset assetWithURL:videoURL];
        NSLog(@"Video Link:%@", [videoURL absoluteString]);
        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetPassthrough];
        if (nil == exportSession) {
            @throw [NSException exceptionWithName:@"Unknown Error" reason:@"Couldn't create AVAssetExportSession" userInfo:nil];
        }
        NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
        NSString *destinationPath = [documentsDirectory stringByAppendingString:@"/output123.mp4"];

        NSLog(@"Dest: %@", destinationPath);

        NSLog(@"Supported File Types: %@", [exportSession supportedFileTypes]);
        exportSession.outputURL = [NSURL URLWithString:destinationPath];
        exportSession.outputFileType = AVFileTypeMPEG4;
        exportSession.shouldOptimizeForNetworkUse = YES;

        [exportSession exportAsynchronouslyWithCompletionHandler:^{
            switch ([exportSession status]) {
                case AVAssetExportSessionStatusFailed:
                    NSLog(@"Transcode Failure: %@", [[exportSession error] localizedDescription]);
                    break;
                case AVAssetExportSessionStatusCancelled:
                    NSLog(@"Transcode Cancelled: %@", [[exportSession error] localizedDescription]);
                    break;
                default:
                    NSLog(@"Transcode Success, What's Next?");
                    break;
            }
        }];
    } else {
        NSLog(@"Not a Movie");
    }
}

我错过了什么?

以下是控制台的输出:

代码语言:javascript
复制
UIImagePickerController mediaType: public.movie
Video Link:file://localhost/private/var/mobile/Applications/EAE27E83-0C27-4725-B606-13C9353B0FCB/tmp/capture-T0x1f56bf10.tmp.2mT0pL/capturedvideo.MOV
Dest: /var/mobile/Applications/EAE27E83-0C27-4725-B606-13C9353B0FCB/Documents/output123.mp4
Supported File Types: (
    "com.apple.quicktime-movie",
    "com.apple.m4a-audio",
    "public.mpeg-4",
    "com.apple.m4v-video",
    "public.3gpp",
    "org.3gpp.adaptive-multi-rate-audio",
    "com.microsoft.waveform-audio",
    "public.aiff-audio",
    "public.aifc-audio",
    "com.apple.coreaudio-format"
)
Transcode Failure: The operation could not be completed
EN

回答 1

Stack Overflow用户

发布于 2014-05-13 10:31:16

您希望使用fileURLWithPath而不是URLWithString

代码语言:javascript
复制
exportSession.outputURL = [NSURL fileURLWithPath:destinationPath];

有关更多信息,请参见this explanation

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17853310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档