Video with GPUImageChromaKeyFilter has tint when played in transparent GPUImageView?

时间秒杀一切 提交于 2019-11-28 11:47:52

I got this working. The solution is to use GPUImageChromaKeyBlendFilter. It blends two sources by replacing the pixels of the colour specified in setColorToReplaceRed in the first source with the pixels in the second source.

So I made a GPUImagePicture with a transparent UIImage and added the filter as a target to it. You can use a transparent PNG or build an UIImage and fill it with transparent in code (empty UIImage won't work!)

Now everything works beautifully!

The code is

let filter = GPUImageChromaKeyBlendFilter()
filter.setColorToReplaceRed(0, green: 1, blue: 0)

let movieFile = GPUImageMovie(URL: url)
movieFile.addTarget(filter)

let backgroundImage = UIImage(named: "MTransparent")
let sourcePicture = GPUImagePicture(image: backgroundImage, smoothlyScaleOutput: true)
sourcePicture.addTarget(filter)
sourcePicture.processImage()

let playerView = GPUImageView()
playerView.backgroundColor = UIColor.clearColor()
filter.addTarget(playerView)

movieFile.startProcessing()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!