Thursday, March 3, 2016

moviepy, library to editor video file

moviepy can help you with automatize tedious tasks, like title insertions tracking objects, cuting scenes, making end credits, subtitles. and it also can create animations from images generated by another python library (Matplotlib, Mayavi, Gizeh, scikit-images

1- example to add text to video

from moviepy.editor import *

video = VideoFileClip("inputvideo.mp4").subclip(50,60)
# Make the text. Many more options are available.
txt_clip = ( TextClip("Starting text",fontsize=70,color='white')
             .margin(top=15, opacity=0) )

txt_clip2 = ( TextClip("Proceeding text",fontsize=70,color='white')
             .margin(top=15, opacity=0)
         .set_start(10) )

result = CompositeVideoClip([video, txt_clip, txt_clip2])

2- example to add random box in random position to video

from moviepy.editor import *
import random

video = VideoFileClip("inputvideo.mp4").subclip(50,60)
def randomBox(startTime):
    randW = random.randint(50,200)
    randH = random.randint(50,200)
    posW = random.randint(1,700)
    posH = random.randint(1,700)
    clip =  (ColorClip(size=(randW,randH), ismask=False)
             .set_pos((posW, posH))
    return clip

clipadd = []

for x in range(243):
    clip = randomBox(x + 1)

result = CompositeVideoClip(clipadd)

No comments:

Post a Comment