1

iPhone Photo Library から AVMutableComposition にアセットを追加してエクスポートするのに苦労しています。これが私が得たものです:

アセットの検索: (ここでは AVURLAsset を取得します)

-(void) findAssets {

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

    // Within the group enumeration block, filter to enumerate just videos.
    [group setAssetsFilter:[ALAssetsFilter allVideos]];
    [group enumerateAssetsUsingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop){

        // The end of the enumeration is signaled by asset == nil.
        if (alAsset) {
            ALAssetRepresentation *representation = [alAsset defaultRepresentation];
            NSURL *url = [representation url];
             AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
            // Do something interesting with the AV asset.

            [thumbs addObject:alAsset];
            [assets addObject:avAsset];
        }else if(alAsset == nil){
            [self createScroll];
        }
    }];
}
                     failureBlock: ^(NSError *error) {
                         // Typically you should handle an error more gracefully than this.
                         NSLog(@"No groups");
                     }];
[library release];

}

ここでは、コンポジションにアセットを追加します (配列内の最初のオブジェクトはテストのみに使用します。

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

最後に、コンプをエクスポートすると、ここでクラッシュします

-(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];

そして、さまざまなプリセットと outputFileTypes を試しました。

ありがとう

*解決済み*

4

1 に答える 1

2

解決したら、自分の質問に答えなければなりません。私がこれに丸一日苦労していて、質問を投稿した直後に修正したことは驚くべきことです:)

私は変更して移動しました:

コンポジション = [AVMutableComposition コンポジション];

に:

コンポジション = [[AVMutableComposition alloc] init];

昨日これに取り組んでいたとき、私はあまりにも疲れていたと思います。みんなありがとう!

于 2011-07-05T08:08:56.823 に答える