Skip to content
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

Fix issue 2269 - And a lot of other things #2307

Merged
merged 15 commits into from
Jan 5, 2025

Conversation

OsaAjani
Copy link
Collaborator

TL;DR: Transparency was broken all around, I fixed it.

What started as a "quick fix" for issue #2269 rapidly escalated into (re)discovery (see #2012 (comment)) of multiple bugs in regards to transparency handling in moviepy. To summarize, transparency was plain and simple broken :

  • Reading video with transparency didn't work
  • Writing video with background transparency didn't work
  • Calculating final transparency of composite clip when the final clip should be partly transparent didn't work
  • Using composite clip of composite clips whom add some clips with mask didn't work (original MoviePy2: TextClip transperancy glitch with multiple CompositeVideoClip #2269)
  • Compositing and bliting was partially buggy

Basically the only part that was working as intended was composite clip with basic clips inside, and a fully opaque background.

I also added codec extraction to FFMPEGParser when possible, as this info was required for proper transparency handling on ffmpeg.

I think this should fix not only #2269, but also #2109, #2082, #2008, #1978, #1935, #1881, #1821, #1759, #1301, #896, #400, and probably others I just dont know about...

  • I have provided code that clearly demonstrates the bug and that only works correctly when applying this fix
  • I have added suitable tests demonstrating a fixed bug or new/changed feature to the test suite in tests/
  • I have properly documented new or changed features in the documentation or in the docstrings
  • I have properly explained unusual or unexpected code in the comments around it

osaajani added 12 commits December 22, 2024 16:50
…ec on video reading with alpha channel for vp8 and vp9
…ncy support, all transparency was actually buggy, both during rendering and reading. Also complete refactor of CompositeVideoClip compositing to properly support tranparency with CompositeVideoClip including one or more CompositeVideoClip, and transparency in general who was completly buggy
@OsaAjani
Copy link
Collaborator Author

I will give it a few days for other to look at the PR and flag anything they think is wrong, then if not protest will proceed with merging !

@OsaAjani
Copy link
Collaborator Author

OsaAjani commented Jan 3, 2025

Hey @Zulko @keikoro and others, if someone want to take a look at this PR to check I didn't do anything stupid I intend to merge it during the next two days without responses :)

@claell
Copy link

claell commented Jan 4, 2025

@OsaAjani will this also fix #195 (and incorporate some solution as was apparently proposed in #1395)?

@@ -67,6 +67,8 @@ def __init__(
if bg_color is None:
bg_color = 0.0 if is_mask else (0, 0, 0)

print(clips)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print here.

Copy link
Contributor

@Implosiv3 Implosiv3 Jan 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In new line 302, there is a bug. It should be mask = clip.mask or ColorClip(clip.size, color=1, is_mask=True) instead of the [1, 1] mask size.

You can see the issue here (#2247) and my PR here (#2262).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will fix this and include the changes in your PR in this one, as well as adding a unit test

@OsaAjani OsaAjani merged commit b52b487 into Zulko:master Jan 5, 2025
15 checks passed
@OsaAjani
Copy link
Collaborator Author

OsaAjani commented Jan 5, 2025

I'll publish with a new tag 2.1.2 tomorrow

@claell
Copy link

claell commented Jan 8, 2025

@OsaAjani It seems that the release takes a little longer. Can you share a new (rough) ETA?

@OsaAjani
Copy link
Collaborator Author

OsaAjani commented Jan 8, 2025

Sorry, last days where more about home fixing than coding ^^. Definitely in the week.

@claell
Copy link

claell commented Jan 8, 2025

No problem, thanks for the update! Was just checking frequently the past days to see whether it already got released. 😄

@OsaAjani
Copy link
Collaborator Author

OsaAjani commented Jan 9, 2025

Done.

@claell
Copy link

claell commented Jan 10, 2025

Thanks! Looks as if the publish to PyPI failed, though? The logs indicate that the file already existed, or something like that.

@OsaAjani
Copy link
Collaborator Author

I fixed it

@claell
Copy link

claell commented Jan 10, 2025

Awesome! Just updated with pip and can confirm that the transparency problems in #2269 are fixed now, for me!

@OsaAjani
Copy link
Collaborator Author

@claell actually after a few tests I think this PR mostly solved the aliasing problem with text, at least judging by this example:

from moviepy import *
import numpy as np


vclip = VideoFileClip('../resources/bbb.mp4').subclipped(10, 11)

tClip = TextClip(duration=3, font="../resources/font/example.ttf", text="Some string", color="red", font_size=250, bg_color="black")
tClip.show(1)

tClip2 = TextClip(duration=3, font="../resources/font/example.ttf", text="Some string", color="red", font_size=250)
bg = ColorClip(tClip2.size, color=(255, 255, 255))
print(np.unique(tClip2.mask.get_frame(1)))
cClip = CompositeVideoClip([vclip, tClip2, tClip2.with_position(("center", "center"))], use_bgclip=True)
cClip.show(1)

Capture d’écran du 2025-01-10 22-37-07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants