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

“The End” effect example scripts get fault -- TypeError: 'NoneType' object is not subscriptable #1256

Closed
shawnxiaoxiong opened this issue Jul 4, 2020 · 11 comments · Fixed by #1467
Labels
bug Issues that report (apparent) bugs. examples Related to the code examples included in the documentation (examples dir).

Comments

@shawnxiaoxiong
Copy link

shawnxiaoxiong commented Jul 4, 2020

I run the example scripts “The End” effect after complete the installation,the code is:

from moviepy.editor import *
from moviepy.video.tools.drawing import circle

clip = VideoFileClip("myvideo.mp4", audio=False).\
           subclip(26,31).\
           add_mask()
           
w,h = clip.size

# The mask is a circle with vanishing radius r(t) = 800-200*t               
clip.mask.get_frame = lambda t: circle(screensize=(clip.w,clip.h),
                                       center=(clip.w/2,clip.h/4),
                                       radius=max(0,int(800-200*t)),
                                       col1=1, col2=0, blur=4)


the_end = TextClip("The End", font="Amiri-bold", color="white",
                   fontsize=70).set_duration(clip.duration)

final = CompositeVideoClip([the_end.set_pos('center'),clip],
                           size =clip.size)
                           
final.write_videofile("theEnd.mp4")

Expected Behavior

Return correct

Actual Behavior

Traceback (most recent call last):
  File "theend.py", line 34, in <module>
    video.write_videofile("theEnd.mp4")
  File "<decorator-gen-61>", line 2, in write_videofile
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/decorators.py", line 56, in requires_duration
    return f(clip, *a, **k)
  File "<decorator-gen-60>", line 2, in write_videofile
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/decorators.py", line 135, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "<decorator-gen-59>", line 2, in write_videofile
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/decorators.py", line 24, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "<decorator-gen-58>", line 2, in write_videofile
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/video/VideoClip.py", line 350, in write_videofile
    logger=logger,
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/video/io/ffmpeg_writer.py", line 245, in ffmpeg_write_video
    logger=logger, with_times=True, fps=fps, dtype="uint8"
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/Clip.py", line 473, in iter_frames
    frame = self.get_frame(t)
  File "<decorator-gen-11>", line 2, in get_frame
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/Clip.py", line 98, in get_frame
    return self.make_frame(t)
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/video/compositing/CompositeVideoClip.py", line 123, in make_frame
    f = c.blit_on(f, t)
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/video/VideoClip.py", line 599, in blit_on
    mask = self.mask.get_frame(ct) if self.mask else None
  File "movie.py", line 15, in <lambda>
    col1=1, col2=0,blur=4,)
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/video/tools/drawing.py", line 280, in circle
    offset=offset,
  File "/home/pandahub/.local/lib/python3.6/site-packages/moviepy/video/tools/drawing.py", line 146, in color_gradient
    vector = np.array(vector[::-1])
TypeError: 'NoneType' object is not subscriptable

Steps to Reproduce the Problem

  1. install the moviepy ( I have tried both 1.0.3 & v2.0.0.dev1 version, and both are fault)
    pip install moviepy
  2. install the ffmpeg, or it will be fault with "ffmpeg not installed" when run the script
    sudo apt update
    sudo add-apt-repository ppa:jonathonf/ffmpeg-4
    sudo apt install ffmpeg
  3. update the /etc/ImageMagick-6/policy.xml, or it will be fault with "ImageMagick not installed" when run the script
changed to 4. finally I run the script, and it get thta error message: TypeError: 'NoneType' object is not subscriptable python theend.py

Specifications

  • Python Version: python3.6
  • Moviepy Version: both 1.0.3 & v2.0.0.dev1
  • Platform Name: ubuntu 18.04
  • Platform Version: 18.04
@shawnxiaoxiong shawnxiaoxiong added the bug Issues that report (apparent) bugs. label Jul 4, 2020
@tburrows13
Copy link
Collaborator

Thanks for the report. It looks like a problem in drawing.circle (or drawing.color_gradient). I don't have time at the moment to investigate, but checking and fixing all the example scripts is high up on my todo list.

@tburrows13 tburrows13 added the examples Related to the code examples included in the documentation (examples dir). label Jul 5, 2020
@0xe590b4
Copy link

0xe590b4 commented Jul 6, 2020

 You should be able to fix it by editing these line    

 in. moviepy/video/tools/drawing.py
    # if vector is None and p2:
    #     p2 = np.array(p2[::-1])
    #     vector = p2-p1
    # else:
    #     vector = np.array(vector[::-1])
    #     p2 = p1 + vector
    #
    # if vector:
    #     norm = np.linalg.norm(vector)

    p1 = np.array(p1[::-1]).astype(float)

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

    if vector is not None:
        norm = np.linalg.norm(vector)

@tburrows13
Copy link
Collaborator

tburrows13 commented Jul 7, 2020

Thanks for the suggested fix. This was actually just a very simple regression that I messed up when fixing. See #1259. It is fixed now in master.

@Heedster
Copy link

@tburrows13 @0xe590b4 I dont think that is true, the error is in the lines above it, and it still exists. When color_gradient is invoked from circle, neither vector or p2 is passed. So the if does not satisfy, and the else fails, as shown in the stacktrace.

@tburrows13 tburrows13 reopened this Oct 12, 2020
@jdern
Copy link

jdern commented Jan 18, 2021

@tburrows13 @0xe590b4 I propose the correction:

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

=> This make the circle "The End' example to work perfectly

@mondeja
Copy link
Collaborator

mondeja commented Jan 18, 2021

@tburrows13 @0xe590b4 I propose the correction:

Commenting the whole block also works, or skipping it for radial shape:

if shape != "radial":
    if vector is None and p2:
        p2 = np.array(p2[::-1])
        vector = p2 - p1
    else:
        vector = np.array(vector[::-1])
        p2 = p1 + vector

I think that is a problem of inconsistency between implementations for different shape argument values.

@mondeja
Copy link
Collaborator

mondeja commented Jan 18, 2021

The solution proposed by @0xe590b4 seems the correct to me because either p0 or vector should be provided. Thank you all for the attempts, I will upload a pull soon.

@debdip
Copy link

debdip commented Dec 13, 2021

This issue stills exists with same exceptions.

Traceback (most recent call last):
File "G:\Pycharm\Moviepy\new.py", line 23, in
final.write_videofile('G:\Pycharm\Moviepy\coolText.avi',codec='mpeg4')
File "", line 2, in write_videofile
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "", line 2, in write_videofile
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\moviepy\decorators.py", line 135, in use_clip_fps_by_default
return f(clip, *new_a, **new_kw)
File "", line 2, in write_videofile
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\moviepy\decorators.py", line 22, in convert_masks_to_RGB
return f(clip, *a, **k)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\moviepy\video\VideoClip.py", line 300, in write_videofile
ffmpeg_write_video(self, filename, fps, codec,
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\moviepy\video\io\ffmpeg_writer.py", line 220, in ffmpeg_write_video
for t,frame in clip.iter_frames(logger=logger, with_times=True,
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\moviepy\Clip.py", line 472, in iter_frames
frame = self.get_frame(t)
File "", line 2, in get_frame
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\moviepy\decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\moviepy\Clip.py", line 93, in get_frame
return self.make_frame(t)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\moviepy\video\compositing\CompositeVideoClip.py", line 111, in make_frame
f = c.blit_on(f, t)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\moviepy\video\VideoClip.py", line 528, in blit_on
mask = self.mask.get_frame(ct) if self.mask else None
File "G:\Pycharm\Moviepy\new.py", line 11, in
clip.mask.get_frame = lambda t: circle(screensize=(clip.w,clip.h),
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\moviepy\video\tools\drawing.py", line 268, in circle
return color_gradient(screensize,p1=center,r=radius, col1=col1,
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\moviepy\video\tools\drawing.py", line 144, in color_gradient
vector = np.array(vector[::-1])
TypeError: 'NoneType' object is not subscriptable

anyone help.

@mondeja
Copy link
Collaborator

mondeja commented Dec 13, 2021

This issue stills exists with same exceptions.

A new version with the patch has not been released. Are you using the master Github branch?

@debdip
Copy link

debdip commented Dec 14, 2021

NO. I'm using from pip. so that's why occured maybe.
Actually many example is not working with the pip version.

@AhmedElwerdany
Copy link
Contributor

Actually many examples are not working with the pip version.

@debdip did you know how to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs. examples Related to the code examples included in the documentation (examples dir).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants