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辅助怎么用,微乐自建房辅助免费入口,策略教程(有挂解密)-哔哩哔哩1、完成a...
科普透视!哈糖大菠萝辅助器,微... 科普透视!哈糖大菠萝辅助器,微乐广西小程序开挂,模板教程(确实有挂)-哔哩哔哩1、下载好哈糖大菠萝辅...
详细透视!wepoker辅助透... 详细透视!wepoker辅助透视,微乐家乡app下载,指引教程(真实有挂)-哔哩哔哩在进入wepok...
科普透视!wpk作弊是真的吗,... 科普透视!wpk作弊是真的吗,广西微乐小程序辅助器,诀窍教程(有挂辅助)-哔哩哔哩1)wpk作弊是真...
关于透视!pokerworld... 关于透视!pokerworld修改器,微乐自建房脚本入口,方案教程(有挂神器)-哔哩哔哩1、上手简单...
了解透视!wepoker俱乐部... 了解透视!wepoker俱乐部辅助器,陕西微乐小程序辅助,学习教程(有挂透视)-哔哩哔哩一、wepo...
了解透视!拱趴大菠萝开挂方法,... 了解透视!拱趴大菠萝开挂方法,微信小程序游戏破解器,妙计教程(有挂分享)-哔哩哔哩1、拱趴大菠萝开挂...
辅助透视!wepoker好友房... 辅助透视!wepoker好友房开挂,微乐广西小程序开发,演示教程(有人有挂)-哔哩哔哩1、用户打开应...
揭幕透视!wejoker辅助软... 揭幕透视!wejoker辅助软件视频,微乐广西小程序,手段教程(有挂分享)-哔哩哔哩1、完成wejo...
揭幕透视!菠萝德州透视脚本,微... 揭幕透视!菠萝德州透视脚本,微乐自建房辅助可信吗,项目教程(有挂详细)-哔哩哔哩1、操作简单,无需菠...