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}
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.
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 URL
is created like this:
URL(fileURLWithPath: "")
so for example:
let temp_output = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("temp_exported.mov")
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With