Python: moviepy.editor – Combine and cut mp4 or other format clips to make a video clip for publication or distribution using Python MoviePy Editor – Practical Example Case

As I learnt to use Python for the CFDS (Chartered Financial Data Scientist) certificate, I now sometimes also use that coding knowledge for other practical use cases. For example recently I wanted to combine and cut some mobile phone footage I had taken.

Here’s some example code how to do that:

from moviepy.editor import *
import moviepy.editor as mp
# you can also use .avi etc instead of .mp4 (i.e. whatever your source is)
video1 = VideoFileClip("Clip_1.mp4").subclip(15,28)
video2 = VideoFileClip("Clip_2.mp4").subclip(0,7)

# list our clips that we defined above
clips = [video1, video2]

# concat (merge) the files and give the new combined clip a name
concat_clip = mp.concatenate_videoclips(clips)
concat_clip.write_videofile("Clips Combined.mp4")

# Make the text. Many more options are available.
txt_clip = ( TextClip("Your Text",fontsize=40,color='white')
             .set_position('top')
             .set_duration(20) )             

# create the result
result = CompositeVideoClip([concat_clip, txt_clip]) # Overlay text on video
result.write_videofile("Your Final Clip.mp4",fps=30) # Many options...

Questions or feedback?

Feel free to write me at contact@zuberbuehler-associates.ch or add a comment.

Similar Posts:

Be the first to comment on "Python: moviepy.editor – Combine and cut mp4 or other format clips to make a video clip for publication or distribution using Python MoviePy Editor – Practical Example Case"

Leave a comment

Your email address will not be published.


*