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

on_color fails with TypeError when given a col_opacity parameter #25

Closed
chunder opened this issue Mar 24, 2014 · 6 comments
Closed

on_color fails with TypeError when given a col_opacity parameter #25

chunder opened this issue Mar 24, 2014 · 6 comments

Comments

@chunder
Copy link
Contributor

chunder commented Mar 24, 2014

Here's a simple python script that shows the issue:

from moviepy.editor import *
txt= TextClip('Hello, world!')
this_works= txt.on_color()
this_fails= txt.on_color(col_opacity= 0.5)

That last statement throws the following error:

Traceback (most recent call last):
  File "./tmp.py", line 8, in <module>
    this_fails= txt.on_color(col_opacity= 0.5)
  File "/Users/chunder/py-projects/moviepy/lib/python2.6/site-packages/moviepy-0.2.1.6.93-py2.6.egg/moviepy/video/VideoClip.py", line 497, in on_color
    colorclip = colorclip.set_opacity(col_opacity)
  File "/Users/chunder/py-projects/moviepy/lib/python2.6/site-packages/moviepy-0.2.1.6.93-py2.6.egg/moviepy/video/VideoClip.py", line 533, in set_opacity
    newclip = newclip.add_mask()
  File "/Users/chunder/py-projects/moviepy/lib/python2.6/site-packages/moviepy-0.2.1.6.93-py2.6.egg/moviepy/video/VideoClip.py", line 472, in add_mask
    return self.set_mask( mask.set_duration(self.duration))
  File "<string>", line 2, in set_duration
  File "/Users/chunder/py-projects/moviepy/lib/python2.6/site-packages/moviepy-0.2.1.6.93-py2.6.egg/moviepy/decorators.py", line 12, in apply_to_mask
    newclip = f(clip, *a, **k)
  File "<string>", line 2, in set_duration
  File "/Users/chunder/py-projects/moviepy/lib/python2.6/site-packages/moviepy-0.2.1.6.93-py2.6.egg/moviepy/decorators.py", line 22, in apply_to_audio
    newclip = f(clip, *a, **k)
  File "<string>", line 2, in set_duration
  File "/Users/chunder/py-projects/moviepy/lib/python2.6/site-packages/moviepy-0.2.1.6.93-py2.6.egg/moviepy/decorators.py", line 71, in time_can_be_tuple
    return f(clip, *a, **k)
  File "/Users/chunder/py-projects/moviepy/lib/python2.6/site-packages/moviepy-0.2.1.6.93-py2.6.egg/moviepy/Clip.py", line 195, in set_duration
    newclip.end = newclip.start + t
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

Here's my environment:

$ pip freeze
PIL==1.1.7
decorator==3.4.0
moviepy==0.2.1.6.93
numpy==1.8.0
wsgiref==0.1.2
@Zulko
Copy link
Owner

Zulko commented Mar 24, 2014

Thanks for the feedback ! Have you tried with a newer version ? Like the one currently on Github or PyPI ? I can't garantee anything, but this example works on my computer.

Tell me if it works (and if the newer version works on your computer :) )

@chunder
Copy link
Contributor Author

chunder commented Mar 24, 2014

I just installed the version from github, and the code now runs without throwing an error.

But now I don't get a background color at all if I supply any value of col_opacity. If it omit the col_opacity parameter I get a black box, as expected. If I add the col_opacity parameter I get no background color at all, regardless of what value I support. I tried col_opacity= 1, col_opacity= 0, col_opacity= 0.5, and others.

BTW, thanks for this great tool. I've been hand coding ffmpeg command lines, and moviepy is so much better!

@chunder
Copy link
Contributor Author

chunder commented Mar 25, 2014

Here's some code that shows the background disappearing if I use a col_opacity argument:

from moviepy.editor import *

green= ColorClip((200,200), (0,255,0)).set_duration(5)
txt= TextClip('Hello, world!', color= 'white')

txt= txt.on_color(
    size= (100,100),
    #col_opacity= 0.5,  ## the black bg goes away if I uncomment this      
    ).set_duration(5)

video= CompositeVideoClip([green, txt])

video.to_videofile(
    'demos.mp4',
    fps= 25,
    codec= 'mpeg4',
)

And here's a couple of images showing a screen capture of the resulting video with and without col_opacity parameter.

Without col_opacity, I get a nice black background behind the text:

without_col_opacity

With col_opacity, it's gone:

with_col_opacity

@Zulko
Copy link
Owner

Zulko commented Mar 25, 2014

Thanks for the bug report, I just fixed it (I think).

@chunder
Copy link
Contributor Author

chunder commented Mar 25, 2014

Confirmed, it works for me now. Thanks!

@Zulko Zulko closed this as completed Mar 25, 2014
@jitendra-koodo
Copy link

jitendra-koodo commented Aug 6, 2024

Not a bug, but I've a related question : How to make "black" background disappear in the case above? How can I get full white text and remaining area should have full opacity green background? Not able to get this effect, maybe some specific type of blending is needed?

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

No branches or pull requests

3 participants