The second way is masking, and it is often applied when the background you want to remove is not a one-tone smooth solid green wall.
It’s a tool that automatically detects a solidly colored background and instantly removes it from the video. The first and the most popular “background remover” is Chroma Key. People often need to remove a background from a video and replace it with a nice picture or another video.