使用GPUImage进行色度过滤视频? [英] Chroma-Filtering video using GPUImage?

查看:141
本文介绍了使用GPUImage进行色度过滤视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用透明度键( RGB:0x00FF00 或全绿色)在我的应用程序中显示一个透明的视频文件,使用@ BradLarson真棒 GPUImage 工具包。但是,我在使用 GPUImageChromaKeyFilter 过滤器时遇到了一些困难,我不太明白为什么。

I am attempting to display a video file with transparency inside my application using a transparency key (RGB: 0x00FF00, or full green) using @BradLarson's awesome GPUImage toolkit. However, I am experiencing some difficulties with the GPUImageChromaKeyFilter filter, and I don't quite understand why.

My源视频文件位于我的Dropbox 此处(12 KB,3秒长,全绿背景,屏幕上只有一个正方形),

My source video file is available in my dropbox here (12 KB, 3 seconds long, full green background, just a square on the screen),

我使用了标题为 SimpleVideoFilter 。

这是我试图使用的代码(我只是替换了 -viewDidLoad ):

This is the code I attempted to use (I simply replaced -viewDidLoad):

NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:@"sample" withExtension:@"m4v"];
movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL];

filter = [[GPUImageChromaKeyFilter alloc] init];
[filter setColorToReplaceRed:0 green:1 blue:0];
[filter setEnabled:YES];

[movieFile addTarget:filter];

GPUImageView *filterView = (GPUImageView *)self.view;
[filter addTarget:filterView];

[movieFile startProcessing];

根据文档(稀疏),这个 应该替换视频中所有绿色的效果。相反,我把它作为输出:

According to the documentation (which is sparse), this should have the effect of replacing all of the green in the video. Instead, I get this as an output:

这告诉我视频正在播放(因此它正在复制到应用程序中),但它似乎没有进行任何色度键控。为什么会这样?我需要手动设置平滑值吗?门槛?我不应该,因为源只包含两种颜色( 0x00FF00 0x000000 )。

Which tells me that the video is playing (and thus it's copying to the application), but it doesn't seem to be doing any chroma keying. Why would this be? Do I need to manually set smoothing values & thresholds? I shouldn't, because the source only contains two colors (0x00FF00 and 0x000000).

我在设备上测试了这个,但无济于事。我试图使用的几乎所有其他过滤器都工作,例如 GPUImageRGBFilter GPUImageSepiaFilter 等。可以 GPUImageChromaKeyFilter 刚被打破?

I have tested this on the device as well, to no avail. Almost all other filters I attempt to use work, such as GPUImageRGBFilter, GPUImageSepiaFilter, etc. Could GPUImageChromaKeyFilter just be broken?

任何对此的帮助都会受到赞赏,因为此时我正在刮掉底部的桶视频的透明度。

Any help with this would be appreciated, as at this point I'm scraping the bottom of the barrel for transparency on a video.

推荐答案

与原始问题类似,我想在自定义的顶部放置绿屏视频视图层次结构直播视频。事实证明,使用标准GPUImage ChromaKey过滤器是不可能的。它不是使用alpha混合,而是将绿色像素与背景像素混合在一起。例如,红色背景变为黄色,蓝色变为青色。

Similar to the original question, I wanted to put a green-screen video on top of a custom view hierarchy incl. live video. Turned out this was not possible with the standard GPUImage ChromaKey filter(s). Instead of alpha blending, it blended the green pixels with the background pixels. For example a red background became yellow and blue became cyan.

使其工作的方法包括两个步骤:

The way to get it working involves two steps:

1)确保filterview具有透明背景:

filterView.backgroundColor=[UIColor clearColor];

2)修改GPUImageChromaKeyFilter.m

old: gl_FragColor = vec4(textureColor.rgb, textureColor.a * blendValue);
new: gl_FragColor = vec4(textureColor.rgb * blendValue, 1.0 * blendValue);

现在,视频中的所有键控(例如绿色)像素变得透明,并且可以发现过滤器视图下方的任何内容,包括(live-)视频。

Now all keyed (for example green) pixels in the video become transparent and uncover whatever is below the filterview, incl. (live-)video.

这篇关于使用GPUImage进行色度过滤视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆