Skip to content

Instantly share code, notes, and snippets.

@cblument
Created December 29, 2015 03:00
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 cblument/a8b424d81aa261a84fa5 to your computer and use it in GitHub Desktop.
Save cblument/a8b424d81aa261a84fa5 to your computer and use it in GitHub Desktop.
example of on_color method not working
from moviepy.editor import *
import gizeh
def make_redframe(t):
'''Creates a red 1280x720 frame with hello world centered. Background
color is set to red.
'''
surface = gizeh.Surface(width=1280, height=720)
rect = gizeh.rectangle(lx=1280, ly=720, xy=[1280/2,720/2], fill=(1,0,0))
text = gizeh.text("hello world", fontfamily="Impact", fontsize=216,
fill=(1,1,1), xy=[1280/2,720/2])
rect.draw(surface)
text.draw(surface)
return surface.get_npimage()
def make_frame(t):
'''Creates 1280x720 from with hellow world not centered. Background
color not specified.
'''
surface = gizeh.Surface(width=1280, height=720)
rect = gizeh.rectangle(lx=1280, ly=720, xy=[1280/2,720/2], fill=(0,0,1,0))
text = gizeh.text("hello world", fontfamily="Impact", fontsize=216,
fill=(1,1,1), xy=[1280/2,720/2])
rect.draw(surface)
text.draw(surface)
return surface.get_npimage()
def make_transparent_frame(t):
'''Creates 1280x720 from with hellow world not centered. Background
color is blue but set to fully transparent
'''
surface = gizeh.Surface(width=1280, height=720)
rect = gizeh.rectangle(lx=1280, ly=720, xy=[1280/2,720/2], fill=(0,0,1,0))
text = gizeh.text("hello world", fontfamily="Impact", fontsize=216,
fill=(1,1,1), xy=[1280/2,720/2])
rect.draw(surface)
text.draw(surface)
return surface.get_npimage()
if __name__ == '__main__':
red_clip = VideoClip(make_redframe, duration=10)
# Creates a 10s video with red background.
red_clip.write_videofile("video_test_red.mp4", fps=24)
green_clip_1 = VideoClip(make_frame, duration=10)
green_clip_1 = green_clip_1.on_color(color=(0,1,0))
# Expecting a 10s video with green background but the background is black
green_clip_1.write_videofile("video_test_green_1.mp4", fps=24)
green_clip_2 = VideoClip(make_transparent_frame, duration=10)
green_clip_2 = green_clip_2.on_color(color=(0,1,0))
# Expecting a 10s video with green background but the background is black
green_clip_2.write_videofile("video_test_green_2.mp4", fps=24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment