OGeek|极客世界-中国程序员成长平台

标题: ios - 特定视频的 AVAssetExportSession 失败 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:15
标题: ios - 特定视频的 AVAssetExportSession 失败

我正在尝试使用 AVAssetExportSession 和 AVMutableComposition 将视频和音频合并在一起。我的代码适用于大多数情况(音频和视频)。但是对于某些视频它失败了。失败的视频在 quicktime 播放器和其他播放器上运行良好。即使没有任何音频合并选项(下面给出的代码),我也只是简单地导出失败的视频。

[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);
     }
 }
 ];

我得到的错误如下..

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}

我没有在此处发布完整的合并代码,因为上述基本代码甚至在提到的视频中都失败了。

任何带有错误代码的提示或提示都会非常有用。提前致谢。



Best Answer-推荐答案


我通过使用 AVAssetExportPresetPassthrough 导出预设解决了这个问题……

let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetPassthrough)

这应该使用导出文件中导入视频的分辨率。

关于ios - 特定视频的 AVAssetExportSession 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42802839/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4