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通道之间权衡,根据需要选择最适合应用程序的方法。

相关内容

热门资讯

透视透视!aapoker透视方... 透视透视!aapoker透视方法,微乐贵阳捉鸡麻将辅助,详情透视(有挂存在)-哔哩哔哩aapoker...
脚本教你!aapoker透视怎... 脚本教你!aapoker透视怎么用,aapoker怎么设置提高好牌几率(透视)其实真的是有工具(哔哩...
最终!约局吧能不能开挂,微乐小... 最终!约局吧能不能开挂,微乐小程序礼包码,详细透视(确实有挂)-哔哩哔哩1、任何约局吧能不能开挂透视...
透视解迷!德普软件,德普之星有... 透视解迷!德普软件,德普之星有辅助软件吗(透视)原来有教程(哔哩哔哩)破解侠是真的助透视。每个模型中...
截至目前!wepoker透视有... 截至目前!wepoker透视有用吗,微乐降序自建房辅助app,专业透视(有挂细节)-哔哩哔哩一、we...
脚本必备!aa poker透视... 脚本必备!aa poker透视软件,aapoker透视脚本下载(透视)都是是真的app(哔哩哔哩)1...
突发!红龙poker作必弊指令... 突发!红龙poker作必弊指令,在哪里下载微乐自建房辅助软件,辅助脚本(有挂细节)-哔哩哔哩1、全新...
透视分享!hhpoker可以控... 透视分享!hhpoker可以控制吗,hhpoker是正品吗(透视)一贯是真的器(哔哩哔哩)1、这是跨...
围绕透视问题!wepoker黑... 围绕透视问题!wepoker黑侠破解,微信小程序微乐安徽辅助苹果,科普脚本(有挂猫腻)-哔哩哔哩1、...
透视分享!wepoker公共底... 透视分享!wepoker公共底牌,wepoker辅助器官方(透视)确实是有方法(哔哩哔哩)运辅助工具...