Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.42k stars 1.55k forks source link

How to solve this error in ImageMagick while trying to add 74 or more subtitles to a video with Moviepy in Python? #1982

Closed TavoAdr closed 1 year ago

TavoAdr commented 1 year ago

I am having the following error in Python, editing a video with Moviepy to add subtitles to the video, in the TextClip part, when I am working with 74 or more subtitles. I have tested it on my computer and on Google Colab, and in both cases, I had the same problem, but it worked with one less subtitle. I know it's not an error in the code, and I think it may be something related to the policy file of ImageMagick, but I don't know how to solve it.

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/moviepy/video/VideoClip.py in __init__(self, txt, filename, size, color, bg_color, fontsize, font, stroke_color, stroke_width, method, kerning, align, interline, tempfilename, temptxt, transparent, remove_temp, print_cmd)
   1136         try:
-> 1137             subprocess_call(cmd, logger=None)
   1138         except (IOError, OSError) as err:

2 frames
/usr/local/lib/python3.10/dist-packages/moviepy/tools.py in subprocess_call(cmd, logger, errorprint)
     53             logger(message='Moviepy - Command returned an error')
---> 54         raise IOError(err.decode('utf8'))
     55     else:

OSError: convert: no images defined `PNG32:/tmp/tmppg58qsiz.png' @ error/convert.c/ConvertImageCommand/3258.

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-14-68a023feb833> in <cell line: 22>()
     31 
     32     lines.append(
---> 33         TextClip(
     34             line['words'],
     35             font='Georgia-Regular',

/usr/local/lib/python3.10/dist-packages/moviepy/video/VideoClip.py in __init__(self, txt, filename, size, color, bg_color, fontsize, font, stroke_color, stroke_width, method, kerning, align, interline, tempfilename, temptxt, transparent, remove_temp, print_cmd)
   1144                         "ImageMagick binary in file conf.py, or that the path "
   1145                         "you specified is incorrect"))
-> 1146             raise IOError(error)
   1147 
   1148         ImageClip.__init__(self, tempfilename, transparent=transparent)

OSError: MoviePy Error: creation of None failed because of the following error:

convert: no images defined `PNG32:/tmp/tmppg58qsiz.png' @ error/convert.c/ConvertImageCommand/3258.
.

.This error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect
TavoAdr commented 1 year ago

I found the problem, it was an empty string that went unnoticed.