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

相关内容

热门资讯

分享一款!佛手在线是不是有挂,... 分享一款!佛手在线是不是有挂,wepoker辅助器,曝光教程(有挂技巧)1、许多玩家不知道佛手在线是...
必看攻略!hhpoker破解工... 必看攻略!hhpoker破解工具,哈糖大菠萝有挂吗5个常用方法,技巧教程(有挂透明);哈糖大菠萝有挂...
分享一款!佛手在线有挂吗,wp... 分享一款!佛手在线有挂吗,wpk透视工作室,必备教程(有挂神器);大神普及一款德州ai内幕,确定了佛...
实测教程!wepoker透视是... 实测教程!wepoker透视是真的吗,wepoker国外版透视,wpk教程(有挂辅助)1、玩家可以在...
科普分享!约局吧游戏挂,德州真... 科普分享!约局吧游戏挂,德州真人透视脚本,科技教程(有挂教程);玩家必备必赢加哟《136704302...
推荐一款!wejoker辅助软... 推荐一款!wejoker辅助软件,wepoker能不能透视,wepoke教程(有挂方法)关于wepo...
实测交流!HH平台挂,aapo... 实测交流!HH平台挂,aapoker辅助怎么用,解密教程(有挂透视)1、很好的工具软件,可以解锁游戏...
终于知道!拱趴游戏破解器,po... 终于知道!拱趴游戏破解器,pokemmo脚本辅助,教你教程(有挂攻略);原来确实真的有挂(需添加指定...
避坑细节!hhpoker德州挂... 避坑细节!hhpoker德州挂真的有吗,wejoker免费脚本,规律教程(有挂教程);实战中需综合运...
玩家亲测!hhpoker作弊实... 玩家亲测!hhpoker作弊实战视频,wepoker怎么挂飞机,新2025教程(有挂攻略);人气非常...