Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.58k stars 1.58k forks source link

circle drawing function doesn't work and the end effect example also is likely to not work. ( possible fix inside ) #1662

Open LBdN opened 3 years ago

LBdN commented 3 years ago

Expected Behavior

getting a numpy array.

Actual Behavior

exception on line 144 in the drawing module.

Possible Fix.

change the test on vector variable.

    if vector is None:
        if p2:
            p2 = np.array(p2[::-1])
            vector = p2-p1
    else:
        vector = np.array(vector[::-1])
        p2 = p1 + vector

Steps to Reproduce the Problem

from moviepy.video.tools.drawing        import circle

w,h = global_bbox.width, global_bbox.height
t = 0.25
c= circle(
    screensize=(w,h),
    center=(w/2,h/4),
    radius=max(0,int(800-200*t)),
    col1=1,
    col2=0,
    blur=4
)

Specifications

javier2409 commented 3 years ago

As a workaround, you can use color_gradient() just like circle() does under the hood, but passing some value to vector

clip.mask.get_frame = lambda t: color_gradient(
    size=(clip.w,clip.h),
    p1=(clip.w/2,clip.h/4),
    vector=[1], # this is ignored if 'r' is present and shape is 'radial'
    r=max(0,int(800-200*t)),
    shape='radial',
    col1=1, col2=0, offset=0.9
)

Note: there is another bug related to the vector argument because the function tries to check if it exists using if vector: ... and throws: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() So I think the only constraint for this use case is that it must have only one element.