Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to replace a colour with a different or transparent colour? #100

Open
teejayhh opened this issue Dec 13, 2021 · 0 comments
Open

Comments

@teejayhh
Copy link

teejayhh commented Dec 13, 2021

I am playing around with this awesome library and I am wondering if it is possible the remove solid colour background from a video and replace it with another solid colour. Sorta like a green screen effect. I am also wondering if it is possible to replace that colour with a transparent (colour/image). I am pretty new to Image processing but the chromaKey filter seemed to do what I wanted it to do but I cant get this to work

        let filePath = file("bla.mp4")
        print(filePath.absoluteString)

        let outputUrl = URL(fileURLWithPath: filePath.absoluteString)
        removeFile("bla.mp4")
        videoWriter = BBMetalVideoWriter(url: outputUrl, frameSize: BBMetalIntSize(width: 1920, height: 1080))

        videoSource = BBMetalVideoSource(url: sourceURL)
        videoSource.audioConsumer = videoWriter

        let col = BBMetalColor(red: 93, green: 192, blue: 246)
        let filter = BBMetalChromaKeyFilter(thresholdSensitivity: 0.1, smoothing: 0.1, colorToReplace: col)

        videoSource
            .add(consumer: filter)
            .add(consumer: videoWriter)

        videoWriter.start()

        videoSource.start { [unowned self] _ in
            videoWriter.finish {
                print("Finish")
            }
        } 

The result doesnt seem to have an alpha channel so the background appears to be black. (I have tried this with a video which has an alpha channel and that works)

Is something like this possible ?

Cheers Thomas

@teejayhh teejayhh changed the title Question: Question: How to replace colour with a different or transparent colour Dec 14, 2021
@teejayhh teejayhh changed the title Question: How to replace colour with a different or transparent colour Question: How to replace a colour with a different or transparent colour? Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant