Created
December 29, 2015 03:00
-
-
Save cblument/a8b424d81aa261a84fa5 to your computer and use it in GitHub Desktop.
example of on_color method not working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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