Skip to content

Instantly share code, notes, and snippets.

@codeAshu
Created October 21, 2017 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeAshu/b5b2d3948721183b03cd5d72b2531c57 to your computer and use it in GitHub Desktop.
Save codeAshu/b5b2d3948721183b03cd5d72b2531c57 to your computer and use it in GitHub Desktop.
from moviepy.editor import *
from moviepy.video.tools.subtitles import SubtitlesClip
audio_path = "/path/to/audio/05022357-a41f-11e7-b42c-f45c89a1211f.mp4"
srt_path = "path/to/srt/06665ef8-a41f-11e7-b3eb-f45c89a1211f.srt"
image_path = '/path/to/image/DSC_0265.JPG'
#generate srt
generator = lambda txt: TextClip(txt, font='Arial', fontsize=16, color='white')
subtitles = SubtitlesClip(srt_path, generator)
# create static image with 30 sec video
clip = ImageClip(image_path)
clip = clip.set_duration(30)
#combine video and subtitle
video = mp.CompositeVideoClip([clip, subtitles.set_pos(('center','bottom'))])
#write to output
# increasing fps reduces the speed of building video
video.write_videofile("output.mp4", audio=audio_path, fps=5, codec='libx264')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment