Skip to content

Instantly share code, notes, and snippets.

@fduxiao
Created December 14, 2017 09:23
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 fduxiao/e570abf47a168b92ffe54b684b91ca30 to your computer and use it in GitHub Desktop.
Save fduxiao/e570abf47a168b92ffe54b684b91ca30 to your computer and use it in GitHub Desktop.
movie add logo
#!/usr/bin/env python3
import moviepy.editor as mp
import os
import argparse
def process_one(video_path, logo_path, output_path):
video = mp.VideoFileClip(video_path)
logo_h = logo_w = video.h // 8
logo_margin_x = logo_margin_y = logo_h // 3
logo = (mp.ImageClip(logo_path)
.set_duration(video.duration)
.resize(width=logo_w, height=logo_h)
.margin(right=logo_margin_x, top=logo_margin_x, opacity=0)
.set_pos(("right","top")))
final = mp.CompositeVideoClip([video, logo])
final.write_videofile(output_path)
def output_file_name(file_path, output_path):
return os.path.join(output_path, os.path.basename(file_path))
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--logo", '-l', help='logo path')
parser.add_argument("--output", '-o', help='output path', default='.')
parser.add_argument("movies", nargs='+', help='move path')
args = parser.parse_args()
n = len(args.movies)
for i, one in enumerate(args.movies):
print("%d, %.2f%%" % (i+1, i/n*100), one)
process_one(one, args.logo, output_file_name(one, args.output))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment