AVAssetExportSession在IOS 13上失败,将音频和视频混合在一起 [英] AVAssetExportSession fails on IOS 13, muxing together audio and video
问题描述
此代码在所有IOS 13之前的设备上均有效(并且仍然有效).目前,在 exportAsynchronously 调用运行后出现此错误:
This code works (and still does) on all pre-IOS 13 devices. Currently howerver, am getting this error after the exportAsynchronously call runs:
Error Domain = AVFoundationErrorDomain代码= -11800该操作可能 未完成" UserInfo = {NSLocalizedFailureReason =未知错误 发生(-12735),NSLocalizedDescription =无法执行该操作 已完成,NSUnderlyingError = 0x282e194a0 {Error Domain = NSOSStatusErrorDomain Code = -12735(null)"}}
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12735), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x282e194a0 {Error Domain=NSOSStatusErrorDomain Code=-12735 "(null)"}}
不确定IOS 13是否在 AVAssetExportSession 对象的基本设置中添加或更改了某些要求?可能是IOS错误吗?
Unsure if IOS 13 adds/changes some requirements in the basic setup of the AVAssetExportSession object or what? Could be an IOS bug?
这是代码:
func compileAudioAndVideoToMovie(audioInputURL:URL, videoInputURL:URL) {
let docPath:String = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
let videoOutputURL:URL = URL(fileURLWithPath: docPath).appendingPathComponent("video.mp4");
do
{
try FileManager.default.removeItem(at: videoOutputURL);
}
catch {}
let mixComposition = AVMutableComposition();
let videoTrack = mixComposition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: kCMPersistentTrackID_Invalid);
let videoInputAsset = AVURLAsset(url: videoInputURL);
let audioTrack = mixComposition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: kCMPersistentTrackID_Invalid);
let audioInputAsset = AVURLAsset(url: audioInputURL);
do
{
try videoTrack?.insertTimeRange(CMTimeRangeMake(start: CMTimeMake(value: 0, timescale: 1000), duration: CMTimeMake(value: 3000, timescale: 1000)), of: videoInputAsset.tracks(withMediaType: AVMediaType.video)[0], at: CMTimeMake(value: 0, timescale: 1000));// Insert an 3-second video clip into the video track
try audioTrack?.insertTimeRange(CMTimeRangeMake(start: CMTimeMake(value: 0, timescale: 1000), duration: CMTimeMake(value: 3000, timescale: 1000)), of: audioInputAsset.tracks(withMediaType: AVMediaType.audio)[0], at: CMTimeMake(value: 0, timescale: 1000));// Insert an 3-second audio clip into the audio track
let assetExporter = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetPassthrough);
assetExporter?.outputFileType = AVFileType.mp4;
assetExporter?.outputURL = videoOutputURL;
assetExporter?.shouldOptimizeForNetworkUse = false;
assetExporter?.exportAsynchronously {
switch (assetExporter?.status)
{
case .cancelled:
print("Exporting cancelled");
case .completed:
print("Exporting completed");
case .exporting:
print("Exporting ...");
case .failed:
print("Exporting failed");
default:
print("Exporting with other result");
}
if let error = assetExporter?.error
{
print("Error:\n\(error)");
}
}
}
catch
{
print("Exception when compiling movie");
}
}
推荐答案
问题似乎与AVAssetExportPresetPassthrough(可能是与处理AAC的组合)有关
Issue seems to be related to AVAssetExportPresetPassthrough (and a combination of dealing with an AAC, maybe)
更改为AVAssetExportPresetLowQuality或AVAssetExportPresetHighestQuality,并将视频/音频正确混合为一个.同样,这只是IOS 13问题,并且很可能是错误.
Changing to AVAssetExportPresetLowQuality or AVAssetExportPresetHighestQuality and the video/audio are properly muxed into one. Again, this is just an IOS 13 issue, and likely a bug.
这篇关于AVAssetExportSession在IOS 13上失败,将音频和视频混合在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!