A user has uploaded a video to my server. The video content shows a person in the foreground, and a green background.
I need a script that will remove the green background, and output a new video file with a transparent background.
The script must return the file path to the output video, so I can use that file in other scripts on the server.
Possibly, you will need to use FFmpeg to export each frame in the video as an image, then compare each pixel in the image with the color green. If green, then set the pixel to transparent. After analysing every frame, join all the frames back together and save as a video file.
FFmpeg documentation says you will also need to split the audio and visual channels first, before you work on the pixel colors. Then recombine the audio and video at the end.
Allow some tolerance when checking the pixel color. For example, instead of an exact match at rgb values 0,128,0 (green), allow some variation so that if the pixel is dark green or light green it is still made transparent. A way to do this might be to use a distance formula in 3D color space.