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

AttributeError: 'NoneType' object has no attribute 'stdout' #938

Closed
Technerder opened this issue Apr 5, 2019 · 42 comments
Closed

AttributeError: 'NoneType' object has no attribute 'stdout' #938

Technerder opened this issue Apr 5, 2019 · 42 comments
Labels
video Related to VideoClip and related classes, or handling of video in general.

Comments

@Technerder
Copy link

Technerder commented Apr 5, 2019

Notice

If you have arrived here from google, you will probably find that updating your moviepy version to v1.0.3 or higher will fix the issue (pip install moviepy --upgrade). See #1185.


Expected Behavior

Expected to get an edited version of the inputted video.

Actual Behavior

Produces this error:

Moviepy - Building video test.webm.
MoviePy - Writing audio in testTEMP_MPY_wvf_snd.ogg
chunk:   0%|          | 0/552 [00:00<?, ?it/s, now=None]Traceback (most recent call last):
  File "/home/tech/Developement/CrabRaveGenerator/Test.py", line 8, in <module>
    ]).write_videofile("test.webm", fps = 30)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-51>", line 2, in write_videofile
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-50>", line 2, in write_videofile
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 137, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-49>", line 2, in write_videofile
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/video/VideoClip.py", line 317, in write_videofile
    logger=logger)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-73>", line 2, in write_audiofile
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/AudioClip.py", line 209, in write_audiofile
    logger=logger)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-70>", line 2, in ffmpeg_audiowrite
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/io/ffmpeg_audiowriter.py", line 169, in ffmpeg_audiowrite
    logger=logger):
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/AudioClip.py", line 85, in iter_chunks
    fps=fps, buffersize=chunksize)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-72>", line 2, in to_soundarray
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/AudioClip.py", line 126, in to_soundarray
    snd_array = self.get_frame(tt)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-10>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/AudioClip.py", line 296, in make_frame
    for c, part in zip(self.clips, played_parts)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/AudioClip.py", line 297, in <listcomp>
    if (part is not False)]
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-10>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/Clip.py", line 138, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/Clip.py", line 190, in <lambda>
    return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-10>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/io/AudioFileClip.py", line 78, in <lambda>
    self.make_frame = lambda t: self.reader.get_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/io/readers.py", line 180, in get_frame
    self.buffer_around(fr_min)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/io/readers.py", line 238, in buffer_around
    array = self.read_chunk(chunksize)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/io/readers.py", line 112, in read_chunk
    s = self.proc.stdout.read(L)
AttributeError: 'NoneType' object has no attribute 'stdout'
                                                        

Steps to Reproduce the Problem

Run the following code:

from moviepy.editor import CompositeVideoClip, VideoFileClip, TextClip

CompositeVideoClip([

    VideoFileClip("template.webm").subclip(5, 30), 
    TextClip("Test Text", fontsize = 70, color = 'white').set_position('center').set_duration(10)
    
]).write_videofile("test.webm", fps = 30)

Specifications

  • Python Version: 3.5.3
  • Moviepy Version: 1.0.0
  • Platform Name: Debian
  • Platform Version: 9.8
@ghost
Copy link

ghost commented Apr 27, 2019

I am facing the same issue

@Zulko
Copy link
Owner

Zulko commented Apr 27, 2019

@kamalchaturvedi15 same versions same script ?

@ghost
Copy link

ghost commented Apr 27, 2019

@Zulko Yes, same version (1.0.0)

I am trying to subclip a video, and then writing into a file. It works like for 70% of the clips, but not for the rest 30%, even though all parameters I am passing are correct. Below is my code snippet
`new_clip = self.videoEditor.subclip(startTime, endTime)

new_clip_name = 'clipped.mp4'

new_clip.write_videofile(new_clip_name, codec="libx264", temp_audiofile='temp-audio.m4a', remove_temp=True, audio_codec='aac')

new_clip.close()`

This error occurs while generating the audio file I believe, as it breaks at this point :
`MoviePy - Writing audio in %s

chunk: 0%| | 0/1015 [00:00<?, ?it/s, now=None]

'NoneType' object has no attribute 'stdout'`

@keikoro keikoro added the video Related to VideoClip and related classes, or handling of video in general. label May 4, 2019
@kaiqueocanha
Copy link

kaiqueocanha commented May 6, 2019

I'm facing the same issue when trying to concatenate two video clips with the kwarg method="compose".

it's a simple code:

from moviepy.editor import *
clip1 = VideoFileClip("video1.avi")
clip2 = VideoFileClip("video2.avi")
final_clip = concatenate_videoclips( [clip1,clip2], method='compose')
final_clip.write_videofile("video3.mp4", fps=30)

gives the result as follow:

Moviepy - Building video my_concatenation.mp4.
MoviePy - Writing audio in my_concatenationTEMP_MPY_wvf_snd.mp3
chunk:   5%|██████▋                                                                                                                                    | 32/663 [00:00<00:02, 311.69it/s, now=None]Traceback (most recent call last):
  File "teste1.py", line 6, in <module>
    final_clip.write_videofile("my_concatenation.mp4", fps=30)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-51>", line 2, in write_videofile
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-50>", line 2, in write_videofile
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 137, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-49>", line 2, in write_videofile
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/video/VideoClip.py", line 317, in write_videofile
    logger=logger)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-73>", line 2, in write_audiofile
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/AudioClip.py", line 209, in write_audiofile
    logger=logger)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-70>", line 2, in ffmpeg_audiowrite
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/io/ffmpeg_audiowriter.py", line 169, in ffmpeg_audiowrite
    logger=logger):
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/AudioClip.py", line 85, in iter_chunks
    fps=fps, buffersize=chunksize)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-72>", line 2, in to_soundarray
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/AudioClip.py", line 126, in to_soundarray
    snd_array = self.get_frame(tt)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-10>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/AudioClip.py", line 296, in make_frame
    for c, part in zip(self.clips, played_parts)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/AudioClip.py", line 297, in <listcomp>
    if (part is not False)]
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-10>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/io/AudioFileClip.py", line 78, in <lambda>
    self.make_frame = lambda t: self.reader.get_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/io/readers.py", line 184, in get_frame
    self.buffer_around(fr_max)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/io/readers.py", line 238, in buffer_around
    array = self.read_chunk(chunksize)
  File "/usr/local/lib/python3.5/dist-packages/moviepy-1.0.0-py3.5.egg/moviepy/audio/io/readers.py", line 112, in read_chunk
    s = self.proc.stdout.read(L)
AttributeError: 'NoneType' object has no attribute 'stdout'

Python version: 3.5.2
Moviepy: Installed direct from git
Plataform: Ubuntu 16.04.6 LTS in Windows WSL

Hope it helps!

@kaiqueocanha
Copy link

Update:

Same happens when I try to use other kwargs, like in:

txt_clip = ( TextClip("Test",fontsize=70,color='white')
             .set_position('center')
             .set_duration(10) )

Not sure anymore if it is related, or my environment it's just messed up, but I guess everything is ok...

@mraduldubey
Copy link

mraduldubey commented Sep 5, 2019

Ok. I encountered the same error, and I was trying to concatenate videos, just like @kaiqueocanha. My debugging led me to a place that whenever I tried to incorporate the initial 30 seconds of the two videos I tested on, I got the same error. Hoping that helps in debugging.

@Technerder
Copy link
Author

@mraduldubey I believe you meant to tag @kaiqueocanha. I was trying to overlay text, not concatenate multiple videos into one.

dcaravana added a commit to dcaravana/heatmappy that referenced this issue Oct 3, 2019
@dcaravana
Copy link

I've got the same problem (macOS Mojave, python 3.6.x) with moviepy 1.0.1 but I've managed to work around it downgrading it to 1.0.0.

Hope it helps.

@tburrows13
Copy link
Collaborator

@dcaravana Thanks for letting us know. There seems to be a lot of errors and PRs about this proc that is causing all the problems. Part of the problem seems to be fixing errors on windows which then breaks it on Linux, and vice versa. The only change to it in v1.0.1 vs v1.0.0 is 350571a. Would you mind manually reverting that change to check that the old version still works? Perhaps PR #1016 helps your bug?

@labolado
Copy link

labolado commented Oct 3, 2019

I changed to v1.0.0, and it works well.

@dcaravana
Copy link

@tburrows13 sadly none of them worked.

If it can be of any help here follows the last part of the stack trace:

...
  File "</Users/diego/work/mvp/explainapi/.venv/lib/python3.6/site-packages/decorator.py:decorator-gen-10>", line 2, in get_frame
  File "/Users/diego/work/mvp/explainapi/.venv/lib/python3.6/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/Users/diego/work/mvp/explainapi/.venv/lib/python3.6/site-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/Users/diego/work/mvp/explainapi/.venv/lib/python3.6/site-packages/moviepy/audio/io/AudioFileClip.py", line 78, in <lambda>
    self.make_frame = lambda t: self.reader.get_frame(t)
  File "/Users/diego/work/mvp/explainapi/.venv/lib/python3.6/site-packages/moviepy/audio/io/readers.py", line 191, in get_frame
    self.buffer_around(fr_max)
  File "/Users/diego/work/mvp/explainapi/.venv/lib/python3.6/site-packages/moviepy/audio/io/readers.py", line 245, in buffer_around
    array = self.read_chunk(chunksize)
  File "/Users/diego/work/mvp/explainapi/.venv/lib/python3.6/site-packages/moviepy/audio/io/readers.py", line 112, in read_chunk
    s = self.proc.stdout.read(L)
AttributeError: 'NoneType' object has no attribute 'stdout'

@dcaravana
Copy link

@tburrows13 I spent some time on the issue, but basically it's more complicated than expected to understand for the time I've got, with all those interactions between different parts of moviepy.

Anyway the main issue seems to be how the data is read from ffmpeg through the process created by Popen and assigned to self.proc in audio/io/readers.py: after 100 read_chunk calls, self.proc becomes None.

I've also tried with two different video files.

It could also be that the original code was flawed and the new version of moviepy just let the problem emerge.

Hope it helps!

@Furanyl
Copy link

Furanyl commented Oct 9, 2019

Changed to v1.0.0 and it gives no error. Thanks guys

@osfa
Copy link

osfa commented Oct 9, 2019

Same problem on OSX high sierra, python 3.6. Downgrade to 1.0.0 fixes issue.

@shivang2joshi
Copy link

I've got the same problem (macOS Mojave, python 3.6.x) with moviepy 1.0.1 but I've managed to work around it downgrading it to 1.0.0.

Hope it helps.

This one surprisingly working solution to the issue. Thanks @dcaravana ✌. It's really under my estimation to think of downgrading can be a solution!

@tburrows13
Copy link
Collaborator

Would those of you for whom downgrading to moviepy 1.0.0 fixed the issue mind helping us out a little bit?

The only commit that I can see would cause this to happen is 350571a

Would you mind upgrading to v1.0.1, finding the files referenced in the above commit and undo the changes it references and report back. I’m pretty sure that should fix your problem but @dcaravana said that it didn’t help him...

@sebasi
Copy link

sebasi commented Oct 23, 2019

@tburrows13 I've encountered the same issue, downgrading "solved" it so I tried reverting the indicated code from 350571a: this didn't work out.

Looked a bit further at the changes between v1.0.0 and v1.0.1 I think I narrowed it down to these lines coming from #931, commit: Overdrivr@f4a5625#diff-2b5c494ba3a48ff925aca6438d9847a7R92-R94

I don't (and didn't try to) understand all internals, but it would make sense as an AudioClip.audio_normalize() triggered the issue for me and AudioClip is involved in all posted stack traces in this ticket.

Upgrading to v1.0.1 and just commenting these lines fixed the issue (for me).

Hope this helps! Keep up the great work!

@mattdeba
Copy link

pip install moviepy==1.0.0

bug fixed!

@Ethan0429
Copy link

@sebasi Hi, can you specify which lines exactly that you commented out? I'm having trouble finding the ones you mentioned.

@sebasi
Copy link

sebasi commented Nov 1, 2019

@Ethan0429 So here are the steps:

  1. Make sure you upgrade to version 1.0.1
  2. go to the moviepy directory (you need to adjust for your python version):
    cd /usr/local/lib/python3.7/dist-packages/moviepy/
  3. edit the AudioFileClip class at line 93, e.g. with vim: vim audio/io/AudioFileClip.py +93
  4. comment these lines (add an # in front of them):
    # def __del__(self):
    # self.close()
  5. save and exit the editor

And you should be done.

Could you please confirm if this works for you?
Cheers

PS: I've put it quite detailed to potentially assist other people. :)

@Ethan0429
Copy link

@sebasi Wow thanks! This did seem to fix the issue, however this only worked once I downgraded to from Python 8 to Python 7, and even then I'm not positive whether or not it was changing the script or downgrading python.

This still does not fix the main issue of write_videofiles() producing videos which are frozen on the first frame.

@sebasi
Copy link

sebasi commented Nov 1, 2019

Not sure if I understood you correctly, but I meant that you have to adjust the path to your python version.
Unfortunately I cannot tell you anything about the other issue you are having.

@Ethan0429
Copy link

@sebasi Would you mind telling me what exact version of python you are using?

dannyshisler added a commit to tagmix/moviepy that referenced this issue Nov 4, 2019
@edumachah
Copy link

@Ethan0429 So here are the steps:

  1. Make sure you upgrade to version 1.0.1
  2. go to the moviepy directory (you need to adjust for your python version):
    cd /usr/local/lib/python3.7/dist-packages/moviepy/
  3. edit the AudioFileClip class at line 93, e.g. with vim: vim audio/io/AudioFileClip.py +93
  4. comment these lines (add an # in front of them):
    # def __del__(self):
    # self.close()
  5. save and exit the editor

And you should be done.

Could you please confirm if this works for you?
Cheers

PS: I've put it quite detailed to potentially assist other people. :)

This fixed it for me. Tnaks

@boidushya
Copy link

@Ethan0429 So here are the steps:

  1. Make sure you upgrade to version 1.0.1
  2. go to the moviepy directory (you need to adjust for your python version):
    cd /usr/local/lib/python3.7/dist-packages/moviepy/
  3. edit the AudioFileClip class at line 93, e.g. with vim: vim audio/io/AudioFileClip.py +93
  4. comment these lines (add an # in front of them):
    # def __del__(self):
    # self.close()
  5. save and exit the editor

And you should be done.

Could you please confirm if this works for you?
Cheers

PS: I've put it quite detailed to potentially assist other people. :)

@Zulko please remove the destructor in the last line, as this works perfectly!

@chadlimedamine
Copy link

@Ethan0429 So here are the steps:

  1. Make sure you upgrade to version 1.0.1
  2. go to the moviepy directory (you need to adjust for your python version):
    cd /usr/local/lib/python3.7/dist-packages/moviepy/
  3. edit the AudioFileClip class at line 93, e.g. with vim: vim audio/io/AudioFileClip.py +93
  4. comment these lines (add an # in front of them):
    # def __del__(self):
    # self.close()
  5. save and exit the editor

And you should be done.

Could you please confirm if this works for you?
Cheers

PS: I've put it quite detailed to potentially assist other people. :)

Thank you @sebasi it worked for me perfectly.

@pkarp0
Copy link

pkarp0 commented Dec 20, 2019

This works for me on macOS 10.14 with moviepy 1.0.1

@Ethan0429 So here are the steps:

  1. Make sure you upgrade to version 1.0.1
  2. go to the moviepy directory (you need to adjust for your python version):
    cd /usr/local/lib/python3.7/dist-packages/moviepy/
  3. edit the AudioFileClip class at line 93, e.g. with vim: vim audio/io/AudioFileClip.py +93
  4. comment these lines (add an # in front of them):
    # def __del__(self):
    # self.close()
  5. save and exit the editor

@tburrows13
Copy link
Collaborator

Hey all! This is obviously a problem that needs sorting. It has built up over time with people making quick fixes to small parts of the code without taking into consideration that the same methods should be applied consistently to all of moviepy, and also that different operating systems handle resources differently. Around eastertime I intend to have a proper look at it across different OSs and hopefully come up with a solution that works for everyone.

@falhenaki
Copy link

falhenaki commented Mar 8, 2020

@Ethan0429 So here are the steps:

  1. Make sure you upgrade to version 1.0.1
  2. go to the moviepy directory (you need to adjust for your python version):
    cd /usr/local/lib/python3.7/dist-packages/moviepy/
  3. edit the AudioFileClip class at line 93, e.g. with vim: vim audio/io/AudioFileClip.py +93
  4. comment these lines (add an # in front of them):
    # def __del__(self):
    # self.close()
  5. save and exit the editor

And you should be done.

Could you please confirm if this works for you?
Cheers

PS: I've put it quite detailed to potentially assist other people. :)

It looks like i have the same problem and the fix you listed did not fix it. Attaching my stack trace.

  File "mytest.py", line 49, in <module>
    final_video.write_videofile('mytest.mp4', fps=60)
  File "<decorator-gen-51>", line 2, in write_videofile
  File "/usr/local/lib/python3.7/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "<decorator-gen-50>", line 2, in write_videofile
  File "/usr/local/lib/python3.7/site-packages/moviepy/decorators.py", line 137, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "<decorator-gen-49>", line 2, in write_videofile
  File "/usr/local/lib/python3.7/site-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.7/site-packages/moviepy/video/VideoClip.py", line 317, in write_videofile
    logger=logger)
  File "<decorator-gen-73>", line 2, in write_audiofile
  File "/usr/local/lib/python3.7/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 209, in write_audiofile
    logger=logger)
  File "<decorator-gen-70>", line 2, in ffmpeg_audiowrite
  File "/usr/local/lib/python3.7/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/io/ffmpeg_audiowriter.py", line 169, in ffmpeg_audiowrite
    logger=logger):
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 85, in iter_chunks
    fps=fps, buffersize=chunksize)
  File "<decorator-gen-72>", line 2, in to_soundarray
  File "/usr/local/lib/python3.7/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 126, in to_soundarray
    snd_array = self.get_frame(tt)
  File "<decorator-gen-10>", line 2, in get_frame
  File "/usr/local/lib/python3.7/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.7/site-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 296, in make_frame
    for c, part in zip(self.clips, played_parts)
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 297, in <listcomp>
    if (part is not False)]
  File "<decorator-gen-10>", line 2, in get_frame
  File "/usr/local/lib/python3.7/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.7/site-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 296, in make_frame
    for c, part in zip(self.clips, played_parts)
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 297, in <listcomp>
    if (part is not False)]
  File "<decorator-gen-10>", line 2, in get_frame
  File "/usr/local/lib/python3.7/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.7/site-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 296, in make_frame
    for c, part in zip(self.clips, played_parts)
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 297, in <listcomp>
    if (part is not False)]
  File "<decorator-gen-10>", line 2, in get_frame
  File "/usr/local/lib/python3.7/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.7/site-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 296, in make_frame
    for c, part in zip(self.clips, played_parts)
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 297, in <listcomp>
    if (part is not False)]
  File "<decorator-gen-10>", line 2, in get_frame
  File "/usr/local/lib/python3.7/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.7/site-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.7/site-packages/moviepy/audio/io/AudioFileClip.py", line 78, in <lambda>
    self.make_frame = lambda t: self.reader.get_frame(t)
AttributeError: 'NoneType' object has no attribute 'get_frame'

@adam-grant-hendry
Copy link

I confirm @sebasi fix works for me on moviepy version 1.0.1.

@Zulko
Copy link
Owner

Zulko commented Mar 20, 2020

When clips of different lengths are composited, the composite clip has the duration of the longest clip, assuming all clips have a duration (at the end of the video, only the last clip is playing).

@adam-grant-hendry
Copy link

@Zulko Yes, you are correct. Sorry, I was wrong. I deleted my post. Different length clips can be composited without issue.

@pixelicous
Copy link

pixelicous commented Mar 21, 2020

I think i am getting the same issue with CompositeAudioClip that is made out of a concatenate_audioclips object and video audio track:
relevant parts of the code:

music_background = concatenate_audioclips(bg_music_playlist)

composited_audio = CompositeAudioClip([final_video.audio, music_background]).set_duration(speech_audio_duration)

last bits of error message:

venv/lib/python3.7/site-packages/moviepy/audio/io/readers.py", line 112, in read_chunk
s = self.proc.stdout.read(L)
AttributeError: 'NoneType' object has no attribute 'stdout'

Reverting to version 1.0.0 have fixed things for me..

@lincolnaleixo
Copy link

lincolnaleixo commented Mar 21, 2020

same here, annoying error.
MacOS Catalina 10.15.3 with Python 3.8.1
fixed downgrading to 1.0.0

@yuanyanhui
Copy link

yuanyanhui commented Mar 27, 2020

Same issue. Python 3.7. None of the solutions above worked.

After trying multiple times, I can confirm that the solution also works for 1.0.2.

@Ethan0429 So here are the steps:

1. Make sure you upgrade to version 1.0.1

2. go to the moviepy directory (you need to adjust for your python version):
   `cd /usr/local/lib/python3.7/dist-packages/moviepy/`

3. edit the AudioFileClip class at line 93, e.g. with vim: `vim audio/io/AudioFileClip.py +93`

4. comment these lines (add an `#` in front of them):
   `#    def __del__(self):`
   `#        self.close()`

5. save and exit the editor

And you should be done.

Could you please confirm if this works for you?
Cheers

PS: I've put it quite detailed to potentially assist other people. :)

However I am getting "OSError: [WinError 6] The handle is invalid" errors. I added "clip.reader.close()", but this did not solve the problem. After a couple of runs, the error would occur again, and I had to restart my IDE. I suppose this is an unrelated issue.

@JonathanAlis
Copy link

I have the same issue when using write_videofile.
I am using linux mint 19.2, python 3.7 and moviepy 1.0.2.
Downgrading to 1.0.0 didnt work.
Using the 1.0.1 version and commenting the the lines of the function def del(self): in the file /audio/io/readers.py also didnt work
In every case, always the same issue:
AttributeError: 'NoneType' object has no attribute 'stdout'

@houshunwei
Copy link

I have the same issue when using write_videofile.
I am using linux mint 19.2, python 3.7 and moviepy 1.0.2.
Downgrading to 1.0.0 didnt work.
Using the 1.0.1 version and commenting the the lines of the function def del(self): in the file /audio/io/readers.py also didnt work
In every case, always the same issue:
AttributeError: 'NoneType' object has no attribute 'stdout'

The python what you changed maybe not the python when you run. Or the plugin you changed is not the plugin when you run.

@tburrows13
Copy link
Collaborator

Fixed in #1185 and version 1.0.3. Thank you everyone for your patience! Use `pip install moviepy --upgrade`` to update to the latest version.

@HC-47
Copy link

HC-47 commented Mar 14, 2021

unfortunately I'm still facing the issue with the new version :(. I'm attaching the error trace:

Moviepy - Building video test.mp4.
MoviePy - Writing audio in testTEMP_MPY_wvf_snd.mp3
chunk:   0%|                                                                                                                                                   | 0/59 [00:00<?, ?it/s, now=None]Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 49, in create_new_video
  File "<decorator-gen-55>", line 2, in write_videofile
  File "C:\Python36\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "<decorator-gen-54>", line 2, in write_videofile
  File "C:\Python36\lib\site-packages\moviepy\decorators.py", line 135, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "<decorator-gen-53>", line 2, in write_videofile
  File "C:\Python36\lib\site-packages\moviepy\decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "C:\Python36\lib\site-packages\moviepy\video\VideoClip.py", line 298, in write_videofile
    logger=logger)
  File "<decorator-gen-45>", line 2, in write_audiofile
  File "C:\Python36\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "C:\Python36\lib\site-packages\moviepy\audio\AudioClip.py", line 210, in write_audiofile
    logger=logger)
  File "<decorator-gen-9>", line 2, in ffmpeg_audiowrite
  File "C:\Python36\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "C:\Python36\lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 169, in ffmpeg_audiowrite
    logger=logger):
  File "C:\Python36\lib\site-packages\moviepy\audio\AudioClip.py", line 86, in iter_chunks
    fps=fps, buffersize=chunksize)
  File "<decorator-gen-44>", line 2, in to_soundarray
  File "C:\Python36\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "C:\Python36\lib\site-packages\moviepy\audio\AudioClip.py", line 127, in to_soundarray
    snd_array = self.get_frame(tt)
  File "<decorator-gen-11>", line 2, in get_frame
  File "C:\Python36\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "C:\Python36\lib\site-packages\moviepy\Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "C:\Python36\lib\site-packages\moviepy\audio\AudioClip.py", line 297, in make_frame
    for c, part in zip(self.clips, played_parts)
  File "C:\Python36\lib\site-packages\moviepy\audio\AudioClip.py", line 298, in <listcomp>
    if (part is not False)]
  File "<decorator-gen-11>", line 2, in get_frame
  File "C:\Python36\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "C:\Python36\lib\site-packages\moviepy\Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "C:\Python36\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 77, in <lambda>
    self.make_frame = lambda t: self.reader.get_frame(t)
  File "C:\Python36\lib\site-packages\moviepy\audio\io\readers.py", line 186, in get_frame
    self.buffer_around(fr_max)
  File "C:\Python36\lib\site-packages\moviepy\audio\io\readers.py", line 240, in buffer_around
    array = self.read_chunk(chunksize)
  File "C:\Python36\lib\site-packages\moviepy\audio\io\readers.py", line 113, in read_chunk
    s = self.proc.stdout.read(L)
AttributeError: 'NoneType' object has no attribute 'stdout'

@HC-47
Copy link

HC-47 commented Mar 14, 2021

I was having the same problem as in here: #1185, "closing my files too early".

luckily I've found the issue already solved (thx tburrows13 for your overall assistance)

@baolkvn
Copy link

baolkvn commented Dec 21, 2021

@Ethan0429 So here are the steps:

  1. Make sure you upgrade to version 1.0.1
  2. go to the moviepy directory (you need to adjust for your python version):
    cd /usr/local/lib/python3.7/dist-packages/moviepy/
  3. edit the AudioFileClip class at line 93, e.g. with vim: vim audio/io/AudioFileClip.py +93
  4. comment these lines (add an # in front of them):
    # def __del__(self):
    # self.close()
  5. save and exit the editor

And you should be done.

Could you please confirm if this works for you? Cheers

PS: I've put it quite detailed to potentially assist other people. :)

This worked for me, thank you!!!!

@kaushal101
Copy link

This was working absolutely fine with python 3.10.9 and moviepy 1.0.3 a few days back. Something has changed, and the error is back.

I'm stitching a few video clips together, adding some background music and making a final clip.

processing file: E:\To be backed up\2019.02 Oxford\PANA5378.MP4
processing file: E:\To be backed up\2019.02 Oxford\PANA5379.MP4
Traceback (most recent call last):
File "C:\Kaushal\Stable-Diffusion\vid_stitch.py", line 196, in
main()
File "C:\Kaushal\Stable-Diffusion\vid_stitch.py", line 174, in main
background_music = CompositeAudioClip([final_clip.audio, background_music])
File "C:\Users\KD\AppData\Local\Programs\Python\Python310\lib\site-packages\moviepy\audio\AudioClip.py", line 286, in init
ends = [c.end for c in self.clips]
File "C:\Users\KD\AppData\Local\Programs\Python\Python310\lib\site-packages\moviepy\audio\AudioClip.py", line 286, in
ends = [c.end for c in self.clips]
AttributeError: 'NoneType' object has no attribute 'end'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
video Related to VideoClip and related classes, or handling of video in general.
Development

No branches or pull requests