I create Video Effect by GPUImage like this
self.overlayerView = [[GPUImageView alloc] init];
self.overlayerView.frame = self.view.frame;
dispatch_queue_t queue = dispatch_queue_create("queue", NULL);
dispatch_async(queue, ^{
NSURL *sourceURL = [[NSBundle mainBundle] URLForResource:@"212121" withExtension:@"mp4"];
GPUImageMovie *sourceMovie = [[GPUImageMovie alloc] initWithURL:sourceURL];
sourceMovie.playAtActualSpeed = YES;
sourceMovie.shouldRepeat = YES;
sourceMovie.shouldIgnoreUpdatesToThisTarget = YES;
NSURL *maskURL = [[NSBundle mainBundle] URLForResource:@"rose" withExtension:@"mp4"];
GPUImageMovie *maskMovie = [[GPUImageMovie alloc] initWithURL:maskURL];
maskMovie.playAtActualSpeed = YES;
maskMovie.shouldRepeat = YES;
NSURL *alphaURL = [[NSBundle mainBundle] URLForResource:@"rose_alpha" withExtension:@"mp4"];
GPUImageMovie *alphaMovie = [[GPUImageMovie alloc] initWithURL:alphaURL];
alphaMovie.playAtActualSpeed = YES;
alphaMovie.shouldRepeat = YES;
NSURL *topURL = [[NSBundle mainBundle] URLForResource:@"screen" withExtension:@"mp4"];
GPUImageMovie *topMovie = [[GPUImageMovie alloc] initWithURL:topURL];
topMovie.playAtActualSpeed = YES;
topMovie.shouldRepeat = YES;
filter0 = [[GPUImageThreeInputFilter alloc] initWithFragmentShaderFromString:@"precision highp float;uniform sampler2D inputImageTexture;uniform sampler2D inputImageTexture2;uniform sampler2D inputImageTexture3;varying vec2 textureCoordinate;void main(){vec4 video=texture2D(inputImageTexture,textureCoordinate);vec4 mv=texture2D(inputImageTexture2, textureCoordinate);vec4 alpha = texture2D(inputImageTexture3, textureCoordinate);gl_FragColor = video * (1.0 - alpha.r) + mv;}"];
filter1 = [[GPUImageTwoInputFilter alloc] initWithFragmentShaderFromString:@"
precision highp float;
uniform sampler2D inputImageTexture; //video
uniform sampler2D inputImageTexture2; //screen
varying vec2 textureCoordinate;
void main()
{
vec4 video = texture2D(inputImageTexture, textureCoordinate);
vec4 screen = texture2D(inputImageTexture2, textureCoordinate);
mediump vec4 whiteColor = vec4(1.0);
gl_FragColor = whiteColor - ((whiteColor - screen) * (whiteColor - video));
}"];
[sourceMovie addTarget:filter0];
[maskMovie addTarget:filter0];
[alphaMovie addTarget:filter0];
[filter0 addTarget:filter1];
[topMovie addTarget:filter1];
[sourceMovie startProcessing];
[alphaMovie startProcessing];
[maskMovie startProcessing];
[topMovie startProcessing];
[filter0 forceProcessingAtSize:CGSizeMake(480,480)];
[filter1 forceProcessingAtSize:CGSizeMake(480,480)];
dispatch_async(dispatch_get_main_queue(), ^{
[filter1 addTarget:self.overlayerView];
});
});
Code can run and i got the video effect like this
The video has a black background that is because the alphaMovie not play the same time with the maskMovie?
This is what i want to create
The effect video no black background
Question:
1: How can i remove the black background ?
2: Why i the effect video have black background ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…