Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.1k stars 1.51k forks source link

Green Screen Video #964

Open Miserness974 opened 5 years ago

Miserness974 commented 5 years ago

Hello, I have succeed the fact to remove green on a image and to add a video in the background, but it doesn't work with a green screen video. How can I achieve that ?

Here is the code that works:

ai=ImageClip("afterimage.png")
masked_clip = vfx.mask_color(ai, color=[0,255,1]) # for green

some_background_clip = VideoFileClip("random_stuff.mp4")

final_clip = CompositeVideoClip([some_background_clip, new],
                                    use_bgclip=True)
final_clip.duration=5
final_clip.write_videofile("afterimage.mp4", fps=30)

I want ai that is a ImageClip to be a VideoFileClip like a mp4 that as a green screen

Miserness974 commented 5 years ago

Anyone ?

mowshon commented 4 years ago

I did not find much information in the official documentation. Only from sourcecode: https://zulko.github.io/moviepy/_modules/moviepy/video/fx/mask_color.html#mask_color

import moviepy.editor as mp

clip = mp.VideoFileClip('/home/me/path/to/green-screen-video.mp4')
# Mountains background
background = mp.ImageClip('https://www.worldatlas.com/r/w728-h425-c728x425/upload/66/14/d8/kangchenjunga.jpg')

masked_clip = clip.fx(mp.vfx.mask_color, color=[0, 255, 8], thr=100, s=5)
# You can remove this resize, it's just for test...
masked_clip = masked_clip.resize(0.3).set_pos(('center', 'bottom'))

final_clip = mp.CompositeVideoClip([
    background,
    masked_clip
]).set_duration(1)

final_clip.write_videofile('test.mp4')

For each video I selected individually the parameters.

clip.fx(mp.vfx.mask_color, color=[0, 255, 8], thr=100, s=5)

I left the "s" parameter unchanged. I only changed "thr" from 1 to 150 ... The higher the value of the parmatter, the better it removes the edges. But if it is too large, then the code starts to remove other colors besides green.

img2

mgaitan commented 4 years ago

@mowshon would you like to propose a PR with your answer as a doc example?

mowshon commented 4 years ago

@mgaitan yeah sure!

BenLore commented 3 years ago

To be honest, I don't know how to solve your problem, but I want to recommend a website with green screen, maybe something would be interesting for you, and you will make something like that https://greenscreenstock.com/