Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAssetExportSession failed with unknown error -12780 for specific video

I have a problem tracing the underlying issue behind my asset export session failure. The issue is for one video only, and I believe the problem is in its audio track, since I successfully exported the asset without the audio track (only the video track).

The video track is decoded with AVAssetReader and the sample buffers are processed before being rewritten into a new video track; the audio track is passed with no decoding nor any intermediate processing. However, even without processing the video sample buffers, the same failure occurred.

I also tried doing it the other way round--with audio only and no video track--and still other videos worked just fine and this particular video failed. I suppose there's an inherent problem with the video's audio track, but I can't infer what the problem is, and hence I can't tackle it. Here's my code:

AVAssetExportSession* assetExport = [[AVAssetExportSession alloc] initWithAsset:composition
                                                                      presetName:AVAssetExportPresetHighestQuality];

assetExport.outputFileType = @"com.apple.quicktime-movie";
assetExport.outputURL = [NSURL fileURLWithPath:path];

__weak typeof(self) weakSelf = self;
[assetExport exportAsynchronouslyWithCompletionHandler:^{

    switch (assetExport.status) {
        case AVAssetExportSessionStatusCompleted: NSLog(@"Asset combined");
            break;
        case AVAssetExportSessionStatusFailed: NSLog(@"Asset combination failed");
            break;
        default: NSLog(@"Asset combination completed with unknown status: %@", @(assetExport.status));
            break;
    }
}];

The problem is supposed to be in the asset export session; track insertion to the AVMutableComposition worked just fine. Here's the error message of the AVAssetExportSession:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed"
UserInfo={NSUnderlyingError=0x6040001338d0 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}, 
NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed}
like image 731
stangkudung Avatar asked Mar 22 '16 03:03

stangkudung


3 Answers

I spent about two days with this issue... I didn't figure out the root cause, however, I found setting a audioMix to AVAssetExportSession worked.

AVMutableAudioMix *videoAudioMixTools = [AVMutableAudioMix audioMix];
AVMutableAudioMixInputParameters *firstAudioParam = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:assetAudioTrack];
[firstAudioParam setVolumeRampFromStartVolume:1.0 toEndVolume:1.0 timeRange:CMTimeRangeMake(kCMTimeZero, CMTimeSubtract(endCropTime, startCropTime))];
[firstAudioParam setTrackID:compositionAudioTrack.trackID];
videoAudioMixTools.inputParameters = [NSArray arrayWithObject:firstAudioParam];

exportSession.audioMix = videoAudioMixTools;

It seems like that this forces to decode and re-encode audio track.

like image 115
Robert Avatar answered Oct 16 '22 16:10

Robert


I know this is an old question, but as it's not resolved, I will give the solution to error code 12780.

Most of the time the problem is the output URL. Make sure that the URLis created like this:

URL(fileURLWithPath: "")

so for example:

let temp_output = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("temp_exported.mov")
like image 27
MarcoCarnevali Avatar answered Oct 16 '22 15:10

MarcoCarnevali


Wild guess: the audio track was separated from its owning AVAsset, which then went out of scope. Try keeping a reference to the audio track's AVAsset until you call exportAsynchronouslyWithCompletionHandler.

like image 44
Rhythmic Fistman Avatar answered Oct 16 '22 17:10

Rhythmic Fistman