Closed tobiasBora closed 12 months ago
So after a bit of investigation, it seems like the issue occurs only with some kinds of video (here a video exported via kdenlive), more precisely when moviepy tries to deal with the audio. The reason is that the file descriptor of self.proc
(that contains a file descriptor to ffmpeg) is closed by calling this function:
that destroys the proc to ffmpeg. Commenting these lines actually solve the problem, but this is a dirty solution since the proc will never be closed.
Now, why is it closed? A traceback gives:
File "moviepy/Clip.py", line 639, in __del__
self.close()
File "moviepy/moviepy/video/io/VideoFileClip.py", line 167, in close
self.audio.close()
File "moviepy/audio/io/AudioFileClip.py", line 83, in close
raise NameError("don't close me") <--- I added this line to debug
So it seems like at some point the clip is destroyed automatically by the garbage collector, that calls:
but this arrives before the make_frame
defined here is called (which internally needs proc):
So proc does not exists when it is called later. I guess the garbage collector is not clever enough to determine that a function copy is still in use… This seems to be a well known issue however:
but I have no idea what is the clean way to solve it. Actually this line sayes that close
should NOT be closed by __del__
(that makes sense now), and in the code, it is explicitely called by __del__
a few lines below. So I guess this should not be done?
@keikoro might have an idea?
Ok, a quick git blame pointed to a recent commit from https://github.com/Zulko/moviepy/commit/57c279a30f7be6a20d2fe24e71b6d11039cbe0cd : @mgaitan , you confirm that it was not a good idea to call close in del (as suggested in the comment of close) and that it can therefore be undone?
I just reverted the problematic modification of @mgaitan in this PR https://github.com/Zulko/moviepy/pull/1995
Expected Behavior
I expect this code to work:
Actual Behavior
I get this error on master:
Steps to Reproduce the Problem
First, get the latest version on master. If you want to get the same environment as mine and you have nix, you can just run:
to enter a shell with the expected dependencies.
Then, write in a file
test.py
:create the 2 files using these two files (hopefully github will not alter them):
classe_inversee.mp4
:https://github.com/Zulko/moviepy/assets/2164118/c5a08e4d-1962-4af5-be61-c010fe26a2cd
and run
You should observe:
Specifications