-
-
Notifications
You must be signed in to change notification settings - Fork 1k
[Bug Report] VideoRecorder breaks with older version of MoviePy #1322
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
Comments
Very helpful @chrisnota |
Probably, but I'm not sure. Very busy with some deadlines currently, but I could take a deeper look later next week? Just wanted to make sure this got logged. |
This is really a separate issue, and is really a bug on moviepy, but it seems like there are some interesting memory leaks with moviepy. I ran this code, and got the following plot:
Using However, regardless of whether you have closed the clip, calling gc.collect() after each iteration totally solves this issue: So I'm going to suggest calling gc.collect() on stop_recording(). Still hoping to put together a PR for this. |
Thanks @chrisnota, that sounds like a good plan for now. |
@chrisnota Running your script on my MacOS with Default without Memory Analysis:
Starting memory: 51.94 MB
Final memory: 70.50 MB
Difference: 18.56 MB
Average memory growth per iteration: 0.0926 MB
Memory leak detected: No Could you clarify what OS and MoviePy version your using? |
I'm on ubuntu 22.04, moviepy==2.1.2 |
Hi, I am coming from IsaacLab were the leak was noticed too, see isaac-sim/IsaacLab#1996. I traced back the issue to Gymnasium then MoviePy. I found an easy solution in Gymnasium that doesn't require to call the garbage collector. After checking MoviePy source code, it appears that not much of VideoRecorder is used and the lower level class FFMPEG_VideoWriter could be used directly: def stop_recording(self):
"""Stop current recording and saves the video."""
assert self.recording, "stop_recording was called, but no recording was started"
if len(self.recorded_frames) == 0:
logger.warn("Ignored saving a video as there were zero frames to save.")
else:
try:
from moviepy.video.io.ffmpeg_writer import FFMPEG_VideoWriter
except ImportError as e:
raise error.DependencyNotInstalled(
'MoviePy is not installed, run `pip install "gymnasium[other]"`'
) from e
path = os.path.join(self.video_folder, f"{self._video_name}.mp4")
with FFMPEG_VideoWriter(
filename=path,
size=self.recorded_frames[0].shape[:2][::-1],
fps=self.frames_per_sec
) as writer:
for frame in self.recorded_frames:
writer.write_frame(frame)
self.recorded_frames = []
self.recording = False
self._video_name = None I tested it and it completely fixed the issue. Before the patch: After using FFMPEG_VideoWriter: Also, I may have found the issue in MoviePy and have a potential solution too, though updating it would be complicated as the dependencies are already conflicting thus, the version used is outdated. I will still report the issue to them. |
@timote-MOREAUX Investigating this on Ubuntu in #1377 with Just adding |
@pseudo-rnd-thoughts I dug deeper in MoviePy to be certain of the cause, you can check the report I made there with the bug report mentioned above. The numpy array isn't freed because of circular referencing in I think that using |
Describe the bug
I was hitting the following error with VideoRecorder:
I noticed my moviepy was on an older 1.0 version. Upgrading to latest fixed the issue.
I think VideoRecorder may not be compatible with some or all moviepy 1.0 versions. We should bump the minimum version number in the pyproject.yaml.
Code example
System info
Name: gymnasium
Version: 1.0.0
Ubuntu 22.04
Additional context
This is probably what caused #882, which was closed because the user wasn't able to reproduce (possibly after inadvertently upgrading?)
Checklist
The text was updated successfully, but these errors were encountered: