ios6avfoundationgrand-central-dispatchavassetwriter

AVAssetWriter finishWritingWithCompletionHandler error with unknown error


I have been struggling with this problem for over a week. I hope someone sees what I'm doing wrong. I am attempting to use the finishWritingWithCompletionHandler: method since the finishWriting method is now deprecated. I have not had any success using the new method. It fails with an unknown error -11800. I can save my MOV file using the deprecated method fine, but when I create the equivalent with the new method it fails every time.

Here is my original code:

dispatch_async(movieWritingQueue, ^{
    if ([self.assetWriter finishWriting]) {
        self.assetWriterAudioIn = nil;
        self.assetWriterVideoIn = nil;
        //[assetWriter release];  ARC will not allow this line.
        self.assetWriter = nil;

        self.readyToRecordVideo = NO;
        self.readyToRecordAudio = NO;

        [self.delegate movieReadyToSaveForMovieProcessor:self];
    }
    else {
        [self displayError:[assetWriter error]];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self resumeCaptureSession];
        });
    }
}];

My new method is as follows:

dispatch_async(movieWritingQueue, ^{
    [self.assetWriter finishWritingWithCompletionHandler:^{
        if (self.assetWriter.status != AVAssetWriterStatusFailed && self.assetWriter.status == AVAssetWriterStatusCompleted) {
            self.assetWriterAudioIn = nil;
            self.assetWriterVideoIn = nil;
            self.assetWriter = nil;

            self.readyToRecordAudio = NO;
            self.readyToRecordVideo = NO;

            [self.delegate movieReadyToSaveForMovieProcessor:self];
        } else {
            [self displayError:self.assetWriter.error];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self resumeCaptureSession];
            });
        }
    }];
}];

I don't think I missed anything and I'm not getting much from the error it throws. Any help will be greatly appreciated.

Thanks, Rob


Solution

  • I finally found the answer. The finishWritingWithCompletionHandler: was failing because I did not run the markAsFinished on the AVAssetWriterInput objects. Once I ran the markAsFinished methods before the finishWritingWithCompletionHandler:, the process was able to complete without errors.