Open DannyK123456 opened 7 years ago
this would make a great how-to example.. Adding the example label.
There is a Moviepy fx that does that here, from what I remember you use it like this:
import moviepy.editor as mpe
clip = VideoFileClip('somefile.mp4')
masked_clip = mpe.vfx.mask_color(clip, color=[0,255,0]) # for green
final_clip = mpe.CompositeVideoClip([masked_clip, some_background_clip])
You may need to tweak the strength and sensibility of the masking though.
Awesome!, I'll have it give it a try.
@Zulko , I've used your code as an example, but my version doesn't work..
ai=ImageClip("media/afterimage.png")
masked_clip = vfx.mask_color(ai, color=[0,255,1]) # for green
some_background_clip = ColorClip((800,600), color=(255,255,255))
final_clip = CompositeVideoClip([masked_clip, some_background_clip])
final_clip.duration=5
final_clip.write_videofile("/tmp/afterimage.mp4", fps=30)
the afterimage.png file can be found at: https://upload.wikimedia.org/wikipedia/commons/thumb/f/f7/Afterimagenpov.svg/1200px-Afterimagenpov.svg.png
I know I'll have to resize the some_background_clip to equal ai.size, but why isn't the word afterimage showing over the white background?
@bhrzk .. here is an example that works..
ai=ImageClip("media/afterimage.png")
masked_clip = vfx.mask_color(ai, color=[0,255,1]) # for green
some_background_clip = ColorClip((800,600), color=(255,255,255))
final_clip = CompositeVideoClip([some_background_clip, masked_clip],
use_bgclip=True)
final_clip.duration=5
final_clip.write_videofile("/tmp/afterimage.mp4", fps=30)
see tests/test_Videos.py in the repo to see this in action.
You may need to tweak the strength and sensibility of the masking though.
@Zulko Hey! How can I tweak the strength and sensibility of the masking? Because when I export the clip without additional settings, I have a lot of residual color around the mask...
Btw, Here's my code:
from moviepy.editor import *
testext = TextClip('hello world',
fontsize=50,
font="Ubuntu-Regular",
color = 'white')\
.set_pos(lambda t:(min(100,-450+500*(t-1)),0))
video0 = VideoFileClip("Media/Logo/logo.mp4").set_pos(lambda t:(min(0,-150+500*(t-1)),0))
video1 = VideoFileClip("Media/Development/Back-end.mp4").subclip(0,2)
final = CompositeVideoClip([video1, video0.set_start(2.7), testext]).set_duration(3)
final.write_videofile("Tests/movingtest4.mp4", codec="libx264")
Thanks for your help!
@zephirFR hey! you ca use thr parameter like this: test_clip.fx(vfx.mask_color, color=(0, 0, 0), thr=20, s=3)
is there any way to make it pixel perfect? even with this (test_clip.fx(vfx.mask_color, color=(0, 0, 0), thr=20, s=3)) , I get one pixel black and gray border for "white" font text. How can I make it crisp?
Hi, I was wondering how I can mask and remove a certain color code. The real case is, I have a clip with the green background so I want to mask and transparent the green background and composite on another movie clip.
Didn't find any solution, and appreciate some help.
Thanks.