-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
MoviePy2: TextClip transperancy glitch with multiple CompositeVideoClip #2269
Comments
I'm having a similar issue. Not entirely sure it's related, but I'll share here rather than open a new issue. I have an ImageClip with a composited TextClip. It looks fine if I save it to a file. However, if I concatenate that CompositeVideoClip to a VideoFileClip, the text loses its transparency. (The text is also cut off on the bottom, but that's not my primary concern at the moment.)
|
Well, this seems like two pretty complementary problems ! You should render each other clip and everything will work as intended ^^ ! |
I've run into (what I assume) is the same issue with transparency when using ImageClip rather than TextClip. It seems in this case somehow related to having a background with transparency.
|
I was pretty sure I already see something like that, and apparently I did and posted about it back when working on the V2 migration #2012 (comment) I will take a deep dive and try to remember what my understanding of the problem was at the time. If anybody want to take a shot at this one maybe take a look at my comment back in the day as a start point. |
Things are progressing, I'm working on a fix and I think that I'm close to a solution. I still need to fix a problem with first clip transparency, but I'm making good progress. Not only will the changes fix this particular issue for CompositeVideoClip, but it should actually fix the entire transparent video generation bug that crippled moviepy for years. |
I think I ran into a rather similar issue with nested composite video clips, as well. Maybe this will also be fixed by the work of @OsaAjani. Will try posting some small example, anyway (hopefully will have time for that) for verification. |
@OsaAjani sorry, took a while to have a look again and compose the test code: from moviepy import VideoClip, TextClip, ColorClip, CompositeVideoClip
def test_transparency_bug(output_file="test_output.mp4", fps=24, duration=5):
bg = ColorClip(size=(640, 360), color=(0, 0, 0)).with_duration(duration)
white_text = TextClip(text="Hello World!", font="C:/Windows/Fonts/Arial.ttf",
font_size=60, color="white").with_duration(duration).with_position("center")
def reveal_mask_frame(t, w, h):
# 0 at start, 1 at end
fraction = max(0, min((t / duration), 1))
import numpy as np
arr = np.zeros((h, w))
arr[:, : int(w * fraction)] = 1
return arr
w, h = white_text.size
mask_clip = VideoClip(
frame_function=lambda t: reveal_mask_frame(t, w, h),
is_mask=True,
duration=duration
)
color_text = TextClip(text="Hello World!", font="C:/Windows/Fonts/Arial.ttf",
font_size=60, color="red").with_duration(duration).with_position("center")
masked_text = color_text.with_mask(mask_clip)
final_clip = CompositeVideoClip(
[bg, white_text, masked_text], size=(640, 360))
final_clip.write_videofile(output_file, fps=fps)
# Compose again to highlight the second-clip issue
second_clip = CompositeVideoClip([bg, final_clip], size=(640, 360))
second_clip.write_videofile("test_composed_again.mp4", fps=fps)
if __name__ == "__main__":
test_transparency_bug() This code first highlights what I believe to be #195 (first video has nice, antialiazed borders for white text, but weird borders for the red overlaid text): test_output.mp4Then, the code produces another video using nested test_composed_again.mp4I hope that your PR #2307 can fix both, fingers crossed. In any way, many thanks for you working on this. Hopefully, my testing code can give another example to check for robustness. |
Well this is my results, it does fix the second problem but not the first one, I will try to take at look at issue #195 when I can ! test_output.mp4test_composed_again.mp4 |
Great! Many thanks for testing. Now, I am really looking forward to seeing the release with the transparency fix. 🙂 Also, thanks for trying to look into #195! |
Fixed with v2.1.2 |
Expected Behavior
When layering a CompositeVideoClip with a ColorClip and TextClip onto a new CompositeVideoClip with a VideoClip.
The expected result should look like this: (Works in MoviePy version < 2)
Actual Behavior
The transperancy of the text shines through the ColorClip
Steps to Reproduce the Problem
Specifications
The text was updated successfully, but these errors were encountered: