Ios4 在库中查找资产-添加到AVMutableComposition-导出=崩溃

Ios4 在库中查找资产-添加到AVMutableComposition-导出=崩溃,ios4,avfoundation,avcomposition,Ios4,Avfoundation,Avcomposition,我一直在努力将iPhone照片库中的资产添加到AVMutableComposition中,然后将其导出。以下是我得到的: 查找资产:(这里我获取avurlast) } 在这里,我将一个资源添加到我的合成中(我使用数组中的第一个对象仅用于测试) -(void) addToCompositionWithAsset:(AVURLAsset*)_asset{ NSError *editError = nil; composition = [AVMutableComposition composition

我一直在努力将iPhone照片库中的资产添加到AVMutableComposition中,然后将其导出。以下是我得到的:

查找资产:(这里我获取avurlast)

}

在这里,我将一个资源添加到我的合成中(我使用数组中的第一个对象仅用于测试)

-(void) addToCompositionWithAsset:(AVURLAsset*)_asset{
NSError *editError = nil;
composition = [AVMutableComposition composition];
AVURLAsset* sourceAsset = [assets objectAtIndex:0];

Float64 inSeconds = 1.0;
Float64 outSeconds = 2.0;
// calculate time
CMTime inTime = CMTimeMakeWithSeconds(inSeconds, 600);
CMTime outTime = CMTimeMakeWithSeconds(outSeconds, 600);
CMTime duration = CMTimeSubtract(outTime, inTime);
CMTimeRange editRange = CMTimeRangeMake(inTime, duration);
[composition insertTimeRange:editRange ofAsset:sourceAsset atTime:composition.duration error:&editError];

if (!editError) {
    CMTimeGetSeconds (composition.duration);
}
} 最后我导出了comp,在这里它崩溃了

-(void)exportComposition {
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetPassthrough];

NSLog (@"can export: %@", exportSession.supportedFileTypes);

NSArray *dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [dirs objectAtIndex:0];
NSString *exportPath = [documentsDirectoryPath stringByAppendingPathComponent:EXPORT_NAME];

[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
NSURL *exportURL = [NSURL fileURLWithPath:exportPath];

exportSession.outputURL = exportURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;//@"com.apple.quicktime-movie";

[exportSession exportAsynchronouslyWithCompletionHandler:^{
    NSLog (@"i is in your block, exportin. status is %d",
           exportSession.status);
    switch (exportSession.status) {
        case AVAssetExportSessionStatusFailed:
        case AVAssetExportSessionStatusCompleted: {
            [self performSelectorOnMainThread:@selector (exportDone:)
                                   withObject:nil
                                waitUntilDone:NO];
            break;
        }
    };
}];
}

有人知道它可能是什么吗?它崩溃了

AVAssetExportSession*exportSession=[[AVAssetExportSession alloc]initWithAsset:composition presetName:AVAssetExportPresetPassthrough]

我尝试了不同的预设和输出文件类型

谢谢


*解决了*

解决了问题后,我现在必须回答自己的问题。令人惊讶的是,我已经为此苦苦挣扎了一整天,然后在发布了一个问题后马上解决了:)

我改变和移动了:

composition=[AVMutableComposition 组成]

致:

组合=[[AVMutableComposition] alloc]init]

我想我昨天做这个的时候太累了。谢谢大家

-(void)exportComposition {
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetPassthrough];

NSLog (@"can export: %@", exportSession.supportedFileTypes);

NSArray *dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [dirs objectAtIndex:0];
NSString *exportPath = [documentsDirectoryPath stringByAppendingPathComponent:EXPORT_NAME];

[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
NSURL *exportURL = [NSURL fileURLWithPath:exportPath];

exportSession.outputURL = exportURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;//@"com.apple.quicktime-movie";

[exportSession exportAsynchronouslyWithCompletionHandler:^{
    NSLog (@"i is in your block, exportin. status is %d",
           exportSession.status);
    switch (exportSession.status) {
        case AVAssetExportSessionStatusFailed:
        case AVAssetExportSessionStatusCompleted: {
            [self performSelectorOnMainThread:@selector (exportDone:)
                                   withObject:nil
                                waitUntilDone:NO];
            break;
        }
    };
}];