Reputation: 1328
I'm trying to merge a video and an audio together using AVAssetExportSession and AVMutableComposition. My code works for most of the cases(audio and video). But it fails for some videos. The failed videos are working fine with quicktime player and other players. The failed videos are failing when I simply exporting even without any audiomerging option(code given below).
[AVURLAsset assetWithURL:[NSURL fileURLWithPath:videoPath]];
AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:videoAsset presetName:AVAssetExportPresetHighestQuality];
NSURL *exportUrl = [NSURL fileURLWithPath:exportPath];
if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath])
{
[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
}
_assetExport.outputFileType = @"com.apple.quicktime-movie";
_assetExport.outputURL = exportUrl;
_assetExport.shouldOptimizeForNetworkUse = YES;
[_assetExport exportAsynchronouslyWithCompletionHandler:
^(void ) {
if (AVAssetExportSessionStatusCompleted == _assetExport.status) {
} else if (AVAssetExportSessionStatusFailed == _assetExport.status) {
NSLog(@"AVAssetExportSessionStatusFailed with error--%@", _assetExport.error);
}
}
];
And the error I got is the following..
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x600000053aa0 {Error Domain=NSOSStatusErrorDomain Code=-12769 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-12769), NSLocalizedDescription=The operation could not be completed}
I'm not posting the full code for merging here because the above basic code even fails with the mentioned videos.
Any tips or hints with the error codes will be really helpful. Thanks in advance.
Upvotes: 3
Views: 1511
Reputation: 53082
I resolved this problem by using the AVAssetExportPresetPassthrough
export preset…
let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetPassthrough)
This should use the resolution of the imported video in the exported file.
Upvotes: 2
Reputation: 10789
It seems that setting the export preset to "AVAssetExportPreset1280x720" for example, fixes the problem. But in my case I really need to keep the original resolution so that's not an option..
Upvotes: 0