AVAssetExportSession failed with unknown error -12780 for specific video
Asked Answered
B

3

19

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}
Brunelleschi answered 22/3, 2016 at 3:10 Comment(4)
Is this problem solved?Fanfaron
Did you get the solution for this problem?Vortex
Even though it's been a while, I'd recommend accepting Fistman's solution. At the very least, it's worked for me.Mar
@PayalManiyar did you get any solutions. I am getting same problem. my code was working perfectly but after sometime its stopped to work. I did not change in my code. Guys helpBawl
F
8

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")
Feverous answered 2/9, 2019 at 16:7 Comment(2)
This was it! I was using URL(string: ""). Thank you!Kolo
This is the true answer. Should use URL(fileURLWithPath:) instead of URL(string:). Thank you!Wakerly
S
4

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.

Slusher answered 12/9, 2016 at 6:8 Comment(1)
Holy sh.... 5 hours wasted and this was the answer. Thanks!Laaspere
C
4

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.

Celery answered 18/6, 2019 at 10:36 Comment(1)
It's 2019 and finally I got a fix for this issue! Note also that for this solution to work, the presetName needs to be an available preset from exportPresetsCompatibleWithAsset (like AVAssetExportPresetHighestQuality), and not AVAssetExportPresetPassthrough.Uraeus

© 2022 - 2024 — McMap. All rights reserved.