BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.23k stars 4.61k forks source link

Incorrect background color after applying GPUImageTransformFilter #2453

Open karpetzag opened 7 years ago

karpetzag commented 7 years ago

I use GPUImage to play video with green screen over camera view. I use GPUImageChromaKeyBlendFilter to remove green background and it works correctly. But I also want to translate video and I'm using GPUImageTransformFilter for that. Code:

- (void)start {
    self.filter = [[GPUImageChromaKeyBlendFilter alloc] init];
    [self.filter setColorToReplaceRed:0.0 green:1.0 blue:0.0];
    [self.filter setThresholdSensitivity:0.4f];

    GPUImageView *filterView = (GPUImageView *)self.view;

    GPUImageVideoCamera *videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
    videoCamera.outputImageOrientation = UIDeviceOrientationLandscapeRight;
    videoCamera.runBenchmark = YES;
    [videoCamera startCameraCapture];

    self.camera = videoCamera;

    NSString *str = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
    NSURL *url = [NSURL fileURLWithPath:str];
    GPUImageMovie *imageMovie = [[GPUImageMovie alloc] initWithURL:url];
    imageMovie.playAtActualSpeed = YES;

    GPUImageTransformFilter *transformFilter = [[GPUImageTransformFilter alloc] init];
    transformFilter.affineTransform = CGAffineTransformMakeTranslation(0.5, 0.5);

    [imageMovie addTarget:transformFilter];

    [transformFilter addTarget:self.filter];
    [videoCamera addTarget:self.filter];

    [self.filter addTarget:filterView];

    [imageMovie startProcessing];

    self.imageMovie = imageMovie;
}

It does translate video but also cuts off part of camera view. https://gyazo.com/cf335979913c69c34b6534fde54dd697

Why does it happen? Is this a bug? How can I move video correctly?

karpetzag commented 7 years ago

I've figured out that the problem connected to alpha of transform filter. I tried to set [transformFilter setBackgroundColorRed:0.0 green:0.0 blue:0.0 alpha:0.0]; But video still has black background