How to concatenate videos in moviepy?

前端 未结 1 1198
野趣味
野趣味 2020-12-31 05:41

I am trying to use moviepy to generate video with texts. First, I want to show one messages and then another one. In my case I want to show \"Dog\" for one second and than \

相关标签:
1条回答
  • 2020-12-31 06:42

    To be written to a file, all the frames must have the same size. Here you frames with Dog are smaller that the frames with CatCat, which spoils the video. A first solution is to use the method "compose" in concatenate_videoclips, this will give the same size to all clips:

    import moviepy.editor as mp
    messages = ["Dog", "Cat", "Duck", "Wolf"]
    clips = [ mp.TextClip(txt, fontsize=170, color='green').set_duration(1)
              for txt in messages ]
    concat_clip = mp.concatenate_videoclips(clips, method="compose")
    concat_clip.write_videofile("texts.mp4")
    

    A second solution is to give the same size (width, height) to all of your text clips:

    import moviepy.editor as mp
    messages = ["Dog", "Cat", "Duck", "Wolf"]
    clips = [ mp.TextClip(txt, fontsize=170, color='green', size=(500,300))
                .set_duration(1)
              for txt in  messages]
    concat_clip = mp.concatenate_videoclips(clips)
    concat_clip.write_videofile("texts.mp4")
    
    0 讨论(0)
提交回复
热议问题