将.swf转换为.mov或.m4v ios目标c

时间:2013-11-25 05:21:59

标签: iphone objective-c flash ios6 avfoundation

我正在尝试一个演示项目,我将捆绑test.swf文件并使用AVFoundation将其转换为.mov或.m4v。但每次我尝试我得到以下错误失败

导出失败:错误域= AVFoundationErrorDomain代码= -11838“操作已停止”UserInfo = 0x109a9a200 {NSLocalizedDescription =操作已停止,NSLocalizedFailureReason =此媒体不支持此操作。}

以下是我更改格式的代码

 AVURLAsset *videoAssetOriginal = [AVURLAsset assetWithURL:videoURL];
//    NSLog(@"videoAssetOriginal %@",videoAssetOriginal);
    AVMutableComposition *mixComposition = [AVMutableComposition composition];
//    NSString *outputPath;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *documentsDirectory = [paths objectAtIndex:0];
      NSString *outputPath =  [documentsDirectory stringByAppendingPathComponent:
                             [NSString stringWithFormat:@"videoExport.m4v"]];
    AVMutableCompositionTrack *compositionTrackOriginal = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];

    AVAssetTrack *clipVideoTrackB = [[videoAssetOriginal tracksWithMediaType:AVMediaTypeVideo] lastObject];

    [compositionTrackOriginal insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAssetOriginal.duration)  ofTrack:clipVideoTrackB atTime:kCMTimeZero error:nil];

    NSLog(@"mixComposition %@",mixComposition);
    AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetPassthrough]; // if i keep presetName :AVAssetExportPreset1280x720 then it will only original video is rotated and trimmed video is removed from the video... and if i keep AVAssetExportPresetPassthrough then it shows black screen

    exporter.outputFileType = AVFileTypeQuickTimeMovie;
    exporter.outputURL = [NSURL fileURLWithPath:outputPath];
    videoURL = [NSURL fileURLWithPath:outputPath];

    [exporter exportAsynchronouslyWithCompletionHandler:^{
        switch ([exporter status])
        {
            case AVAssetExportSessionStatusFailed:
                NSLog(@"Export Failed: %@", [exporter error]);
                break;
            case AVAssetExportSessionStatusCancelled:
                NSLog(@"Export canceled");
                break;
            case AVAssetExportSessionStatusCompleted:
                NSLog(@"Video Exported !");
                break;
            default:
                break;
        }

    }];

0 个答案:

没有答案