Moviepy-TextClip的CompositeVideoClip错误

时间:2018-06-24 07:24:36

标签: python text composite clip moviepy

我正在尝试将文本添加到由concatenate_videoclips生成的剪辑中,但是我一直遇到错误。我尝试将文本分别添加到每个剪辑中,然后进行串联,但是出现相同的错误。

这是我的代码:

clip_list = []
for file in movie_maker_directory:
    clip = VideoFileClip('C:\dev\movie_maker\{}'.format(file))
    if clip.rotation != 0:
        clip = clip.rotate(-clip.rotation)
    clip = clip.resize(height=1080)
    clip_list.append(clip)
final_clip = concatenate_videoclips(clip_list, method="compose")
text = TextClip('Documentary Title', fontsize=5).set_position(('top', 'left'))
final_clip = CompositeVideoClip([text, clip])
final_clip.write_videofile("C:\dev\movie_maker\my_concatenation.mp4")

这是错误消息:

File "C:/dev/movie_compilator.py", line 58, in <module>
    final_clip.write_videofile("C:\dev\movie_maker\my_concatenation.mp4")
  File "<decorator-gen-51>", line 2, in write_videofile
  File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "<decorator-gen-50>", line 2, in write_videofile
  File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\decorators.py", line 137, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "<decorator-gen-49>", line 2, in write_videofile
  File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\video\VideoClip.py", line 349, in write_videofile
    progress_bar=progress_bar)
  File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 209, in ffmpeg_write_video
    fps=fps, dtype="uint8"):
  File "C:\Local\Programs\Python\Python35\lib\site-packages\tqdm\_tqdm.py", line 833, in __iter__
    for obj in iterable:
  File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\Clip.py", line 475, in generator
    frame = self.get_frame(t)
  File "<decorator-gen-14>", line 2, in get_frame
  File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\video\compositing\CompositeVideoClip.py", line 110, in make_frame
    f = c.blit_on(f, t)
  File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\video\VideoClip.py", line 603, in blit_on
    pos[0] = D[pos[0]]
KeyError: 'top'

1 个答案:

答案 0 :(得分:0)

我认为您的立场已经相反。尝试以下方法:

text = TextClip('Documentary Title', fontsize=5).set_position(('left', 'top'))