0

I am trying to use moviepy to join some video clips together, I get the output, with the files joined as expected. When watching the final video, clip1 looks as expected but clip2 has an error, see image. enter image description here All resources I have looked at show that the way the code I have written should work, so am unure what I could do to solve the issue. Any suggestion would be amazing!

The code that I used

filenames = ['clip1.mp4', 'clip2.mp4', 'clip3.mp4']

for x in range(len(filenames)):
    filenames[x] = VideoFileClip(filenames[x])

final_video = concatenate_videoclips(filenames)
final_video.to_videofile("final_video.mp4", fps=30, codec="mpeg4")
Daniel Norfolk
  • 13
  • 1
  • 10
  • This is the code to concatenate one set of clips, but you said it fails when you try to do multiple sets. Please [edit] your question and show us that code as well. – MattDMo Oct 26 '20 at 18:59
  • @MattDMo it is only one set, They way I wrote the question makes it sound different – Daniel Norfolk Oct 26 '20 at 19:17
  • OK, so `clip1.mp4` looks fine in the concatenated version, but `clip2.mp4` and `clip3.mp4` do not, correct? Is `concatenate_videoclips()` a function that you wrote yourself, or did you import it from `moviepy`? – MattDMo Oct 26 '20 at 19:20
  • Nevermind, I'm looking at its [source](https://github.com/Zulko/moviepy/blob/master/moviepy/video/compositing/concatenate.py) now. Were all of your clips the same dimensions and did they all have the same masks, if any? – MattDMo Oct 26 '20 at 19:28
  • That is correct, clip1 is fine but clip2 and clip3 are not. concatenate_videoclips() is a function that was imported from the moviepy module. – Daniel Norfolk Oct 26 '20 at 19:31
  • You need to make them all the same size or use `method=“compose”` – Tom Burrows Oct 26 '20 at 19:32
  • Thank you, that has fixed it. The issue was that the video dimensions were different. – Daniel Norfolk Oct 26 '20 at 19:52

1 Answers1

0

Try this instead:

filenames = ['clip1.mp4', 'clip2.mp4', 'clip3.mp4']

clips = []

for file in filenames:
    clips.append(VideoFileClip(file))

final_video = concatenate_videoclips(clips, method=compose)
final_video.write_videofile('final_video.mp4', fps=30)
Coski
  • 43
  • 2
  • 8