【问题标题】:AVAssetExportSession : The operation could not be completedAVAssetExportSession :操作无法完成
【发布时间】:2013-07-25 01:38:09
【问题描述】:

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

转码失败:操作无法完成

代码如下:

-(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");
    }
}

我错过了什么?

这是控制台的输出:

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

【问题讨论】:

  • 没有。问题没有解决。

标签: iphone avassetexportsession


【解决方案1】:

您想使用fileURLWithPath 而不是URLWithString

exportSession.outputURL = [NSURL fileURLWithPath:destinationPath];

请参阅this explanation 了解更多信息。

【讨论】:

  • 感谢您回答这个老问题。原项目已删除,请等我验证fileURLWithPath有帮助。再次感谢。
猜你喜欢
  • 2019-11-17
  • 2019-05-27
  • 2013-10-31
  • 2012-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多