AVAssetWriter在使用HEVC和Alpha时崩溃-寻找解决方法
创始人
2024-11-12 20:30:28
0

这是一个已知的问题,出现在使用HEVC视频编码器和Alpha通道(透明度)的情况下。目前还没有找到完美的解决方案,但是我们可以尝试以下几种方法:

方法1:使用HEVC而不含Alpha 这解决了HEVC与Alpha通道产生的冲突问题,因为不含Alpha的HEVC编码器不会产生任何问题。下面的是使用AVAssetWriter进行写操作的示例代码,使用HEVC编解码器:

let videoURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("out.hevc") let assetWriter = try! AVAssetWriter(outputURL: videoURL, fileType: .mp4) let videoOutputSettings = [ AVVideoCodecKey : AVVideoCodecType.hevc, AVVideoWidthKey : 640, AVVideoHeightKey : 480, ] as [String : Any] let assetWriterVideoInput = AVAssetWriterInput(mediaType: .video, outputSettings: videoOutputSettings) assetWriter.add(assetWriterVideoInput)

方法2:将视频帧压缩为单独的Alpha和HEVC视频 这种方法需要将每个相邻的视频帧分离,并在HEVC和Alpha视频之间交替切换。由于这种方法需要额外的时间和空间,因此不适合所有情况。

方法3:使用其他编解码器 这种方法需要使用其他可用的编解码器,例如h.264,其可以同时使用HEVC和Alpha通道。下面的代码示例演示了如何在写入时使用h.264编解码器:

let assetWriter = try! AVAssetWriter(outputURL: videoURL, fileType: .mp4) let videoOutputSettings = [ AVVideoCodecKey : AVVideoCodecType.h264, AVVideoWidthKey : 640, AVVideoHeightKey : 480, ] as [String : Any] let assetWriterVideoInput = AVAssetWriterInput(mediaType: .video, outputSettings: videoOutputSettings) assetWriter.add(assetWriterVideoInput)

总之,我们需要在HEVC编码器和Alpha通道之间权衡,根据需要选择最适合应用程序的方法。

相关内容

热门资讯

透视神器!pokemmo手机辅... 透视神器!pokemmo手机辅助软件(透视)第三方教程(2022已更新)(哔哩哔哩)1、透视神器!p...
透视软件!aapoker透视方... 透视软件!aapoker透视方法(透视)透视软件(真是是真的有挂)1、这是跨平台的aapoker透视...
透视攻略!epoker有透视吗... 透视攻略!epoker有透视吗(透视)2025新版总结(2025已更新)(哔哩哔哩);1、实时epo...
透视了解!aapoker辅助器... 透视了解!aapoker辅助器是真的吗(透视)发牌逻辑(好像存在有挂)1、每一步都需要思考,不同水平...
透视线上!pokeplus脚本... 透视线上!pokeplus脚本(透视)解密教程(2022已更新)(哔哩哔哩)1、全新机制【pokep...
透视好牌!aapoker ai... 透视好牌!aapoker ai插件(透视)插件(一贯真的有挂);1、完成aapoker ai插件的残...
透视模拟器!德州真人透视脚本(... 透视模拟器!德州真人透视脚本(透视)必胜教程(2021已更新)(哔哩哔哩);1、金币登录送、破产送、...
透视有挂!aapoker公共底... 透视有挂!aapoker公共底牌(透视)辅助插件工具(都是真的有挂);1、游戏颠覆性的策略玩法,独创...
透视存在!德州真人透视脚本(透... 透视存在!德州真人透视脚本(透视)靠谱教程(2024已更新)(哔哩哔哩);1、打开软件启动之后找到中...
透视有挂!aapoker插件下... 透视有挂!aapoker插件下载(透视)真的假的(本来是真的有挂);1.aapoker插件下载 ai...