-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Can't overlay gizeh animation onto video with transparency/mask #898
Comments
Two things you did wrong:
So something like this (not entirely sure about syntax): def make_frame(t):
surface = gizeh.Surface(width=720, height=1280, bg_color=(0.5, 0.5, 0))
line = gizeh.polyline(points=[(0, 1180), (720, 1180)], stroke_width=3, stroke=(1, 0, 0))
line.draw(surface)
return surface.get_npimage(transparent=True)
graphics_clip_mask = VideoClip(lambda t: make_frame[t][3] / 255.0, is_mask=True)
graphics_clip = VideoClip(lambda t: make_frame(t)[:3],
duration=original_clip.duration,
mask=graphics_clip_mask) |
Hi @Zulko thanks for getting back to me so quickly. I've tried to implement the solution you provided but I can't quite make it work. This code, which is very close to what you've suggested, won't run: import gizeh
from moviepy.editor import *
def make_frame(t):
surface = gizeh.Surface(width=720, height=1280)
line = gizeh.polyline(points=[(0, 1180), (720, 1180)], stroke_width=3, stroke=(1, 0, 0))
line.draw(surface)
return surface.get_npimage(transparent=True)
original_clip = VideoFileClip("test_original_video.mp4")
graphics_clip_mask = VideoClip(lambda t: make_frame(t)[3] / 255.0,
duration=original_clip.duration,
ismask=True)
graphics_clip = VideoClip(lambda t: make_frame(t)[:3],
duration=original_clip.duration)
.set_mask(graphics_clip_mask)
final_clip = CompositeVideoClip(
[original_clip,
graphics_clip],
size=(720, 1280))
final_clip.write_videofile("test_output_video.mp4", fps=30) I get the error ...
File "/Users/danny/.local/share/virtualenvs/poc-Fdmdzxs7/lib/python3.7/site-packages/numpy/core/shape_base.py", line 234, in vstack
return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
ValueError: all the input array dimensions except for the concatenation axis must match exactly If I modify I feel like I'm very close but clearly I'm still doing something wrong. |
maybe the indices are wrong in my example, they should be |
Fantastic, that works! The final working code is: import gizeh
from moviepy.editor import *
def make_frame(t):
surface = gizeh.Surface(width=720, height=1280)
line = gizeh.polyline(points=[(0, 1180), (720, 1180)], stroke_width=10, stroke=(1, 0, 0))
line.draw(surface)
return surface.get_npimage(transparent=True)
original_clip = VideoFileClip("test_original_video.mp4")
graphics_clip_mask = VideoClip(lambda t: make_frame(t)[:, :, 3] / 255.0, duration=original_clip.duration, ismask=True)
graphics_clip = VideoClip(lambda t: make_frame(t)[:, :, :3], duration=original_clip.duration).set_mask(graphics_clip_mask)
final_clip = CompositeVideoClip(
[original_clip,
graphics_clip],
size=(720, 1280)
)
final_clip.write_videofile("test_output_video.mp4", fps=30) Thanks very much for your help. |
Getting a single gray/black pixel around the text when placed on a video following this mask approach. Any solution for this?
|
This is a trivial and simplistic use case : showing static text on a video. Is this Gizeh + Moviepy not a right solution? Moviepy + textclip have aliasing issues when text is scaled. Are there better combos/alternatives? |
I can't work out how to overlay a gizeh animation onto a video so that the vector graphics are visible but the background is transparent so the video is visible underneath the animation. I've tried lots of different ways and nothing seems to work. All I ever get is the gizeh animation completely hiding the underlying video.
This was my latest effort, just simply trying to draw a red line over the video, I've tried using the
mask_color
vfx method to create a mask that uses the Surface bg_color, but it doesn't have any effect.The text was updated successfully, but these errors were encountered: