2
  1. In MoviePy there is an api to create a clip from text as well as to concatenate list of clips.
  2. I am trying to create a list of clips in a loop and then trying to concatenate them.
  3. Problem is every time it creates a video file of 25 seconds only with the last text in a loop.

Here is the code

for text in a list:
    try:
        txt_clip = TextClip(text,fontsize=70,color='white')
        txt_clip = txt_clip.set_duration(2)
        clip_list.append(txt_clip)
    except UnicodeEncodeError:
        txt_clip = TextClip("Issue with text",fontsize=70,color='white')
        txt_clip = txt_clip.set_duration(2) 
        clip_list.append(txt_clip)
final_clip = concatenate_videoclips(clip_list)
final_clip.write_videofile("my_concatenation.mp4",fps=24, codec='mpeg4')
samarth
  • 3,866
  • 7
  • 45
  • 60

1 Answers1

4

I wasn't able to recreate your issue (maybe because the list I used doesn't raise the exception?), but the code chunk below works for me. The most significant difference from what you have above is that I set an option for MoviePy to adjust varying frame sizes.

from moviepy.editor import *

text_list = ["Piggy", "Kermit", "Gonzo", "Fozzie"]
clip_list = []

for text in text_list:
    try:
        txt_clip = TextClip(text, fontsize = 70, color = 'white').set_duration(2)
        clip_list.append(txt_clip)
    except UnicodeEncodeError:
        txt_clip = TextClip("Issue with text", fontsize = 70, color = 'white').set_duration(2) 
        clip_list.append(txt_clip)

final_clip = concatenate(clip_list, method = "compose")
final_clip.write_videofile("my_concatenation.mp4", fps = 24, codec = 'mpeg4')

If you had an example that raises the unicode encode error, maybe I would be able to reproduce your issue. You may find this other question useful: How to concatenate videos in moviepy?

Community
  • 1
  • 1
vikjam
  • 525
  • 3
  • 9
  • I have a similar but slightly different issue with `concatenate`, can you take a look https://github.com/Zulko/moviepy/issues/904 – ishandutta2007 Jan 21 '19 at 20:54