admin管理员组文章数量:1289986
I'm having some trouble using Moviepy library, specially when using SubtitlesClip().
Since I can't provide the whole code, I hope I can provide enough so you can understand my problem. This was my first attempt:
import pysrt
import torch
from moviepy import VideoFileClip
from moviepy.video.tools.subtitles import SubtitlesClip
from moviepy.videopositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.VideoClip import TextClip
generator = lambda txt: TextClip(txt, font='Arial', fontsize=24, color='white', bg_color='black')
subtitles = SubtitlesClip(f"sub_{lang}.srt", make_textclip=generator)
This led to the first error I got:
File "C:\Users\...\my_venv\Lib\site-packages\moviepy\video\VideoClip.py", line 1683, in __init__
raise ValueError(
ValueError: Invalid font <function translate_video.<locals>.<lambda> at 0x0000027A0D394900>, pillow failed to use it with error 'function' object has no attribute 'read'
After searching in many different forums, I found this discussion here on Stackoverflow. This led to a new script:
subtitles = SubtitlesClip(f"sub_{lang}.srt", make_textclip=generator)
That didn't work as well and led to the error below:
File "C:\Users\...\my_venv\Lib\site-packages\decorator.py", line 231, in fun
args, kw = fix(args, kw, sig)
^^^^^^^^^^^^^^^^^^
File "C:\Users\...\my_venv\Lib\site-packages\decorator.py", line 203, in fix
ba = sig.bind(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\inspect.py", line 3195, in bind
return self._bind(args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\inspect.py", line 3134, in _bind
raise TypeError(
TypeError: multiple values for argument 'font'
I found this a bit weird, because the libraries that is showing to have errors are not in the venv I've created. Anyway... Later, I've tried to find the problem by using LLMs. This is what chatGPT recommended:
The error occurs because the subtitle generator function is being passed additional keyword arguments (including one for font) by the SubtitlesClip function. In your lambda, you’re also explicitly specifying font='Arial', which leads to a conflict.
To fix this, modify your generator function so that it accepts any additional keyword arguments and ignores them. For example, change the lambda from:
generator = lambda txt: TextClip( txt, font='Arial', fontsize=24, color='white', bg_color='black' )
to:
generator = lambda txt, **kwargs: TextClip( txt, font='Arial', fontsize=24, color='white', bg_color='black' )
This way, any extra arguments passed by SubtitlesClip (such as another font parameter) won’t cause a conflict.
After making the change suggested, nothing changed. Does anyone know how to fix this issue?
本文标签: pythonMoviepy errors when using TextClipStack Overflow
版权声明:本文标题:python - Moviepy errors when using TextClip - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741433264a2378486.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论