moviepy
moviepy copied to clipboard
write_videofile only writes gif files if the path ends with .gif
Using write_videofile(path, codec='gif')
works correctly if path
ends with .gif
. This piece of code works:
import numpy as np
from pathlib import Path
from moviepy.editor import VideoClip
PATH = r'D:\users\aran-fey\desktop\moviepy.gif' # <- it's a .gif
def get_frame_at_time(t):
return np.frombuffer(b'\xff\0\0', dtype=np.uint8).reshape((1,1,3))
clip = VideoClip(get_frame_at_time, duration=2)
clip.write_videofile(PATH, fps=24, codec='gif')
assert Path(PATH).exists()
But if I change the path to D:\users\aran-fey\desktop\moviepy.something_other_than_gif
the file simply isn't created, even though the console output indicates that it is:
[MoviePy] >>>> Building video D:\users\aran-fey\desktop\moviepy.something_other_than_gif
[MoviePy] Writing video D:\users\aran-fey\desktop\moviepy.something_other_than_gif
98%|██████████████████████████████████████?| 48/49 [00:00<00:00, 48003.48it/s]
[MoviePy] Done.
[MoviePy] >>>> Video ready: D:\users\aran-fey\desktop\moviepy.something_other_than_gif
Traceback (most recent call last):
File "untitled.py", line 16, in <module>
assert Path(PATH).exists()
AssertionError
moviepy version: 0.2.3.5 python version: 3.7.0, 64 bit
Update: The same thing happens with other formats (like mp4
) as well. It looks like write_videofile
silently ignores the codec
argument and only creates the file if the file extension is a supported one.
This is indeed a bug in moviepy. I'm running into this issue too. I'm trying to output a codec="png" videofile, but it dies with:
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\site-packages\moviepy\video\VideoClip.py", line 263, in write_videofile
codec = extensions_dict[ext]['codec'][0]
KeyError: 'codec'
The problem is the "use_clip_fps_by_default" decorator on the write_videofile function. It butchers the keywords, dropping the codec-parameter. Commenting out the decorator and explicitly adding fps=clip.fps to the function call workarounds the problem. (My Python-skills currently aren't good enough to actually write a proper fix for the use_clip_fps_by_default decorator.)
Closing this issue as it's old and based on an old MoviePy version, so impossible to tell if it's still relevant.
Do report back – following our issue template – if the problem persists when you try with the latest master (not the last PyPI release).
This bug is present in the latest released version, 1.0.3. However, I'm pretty sure it's fixed in the repo version (as the affected code was changed in a "support newer versions of Python"-commit), but that hasn't been released that yet. Can you please do a new release, instead of having a known broken version be the latest greatest?
Regarding new releases, please refer to the issue discussing the future of the MoviePy project pinned at the top of the issues tab.