Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ctypes
- ctypes.windll.user32.SetProcessDPIAware()
- from moviepy.editor import *
- import moviepy.video.fx.all as vfx
- def show(clip, time):
- temp_clip = clip.resize(width=600)
- temp_clip.show(time, interactive=True)
- def get_mask(file_name, duration): # b/w image to 0-1 float mask
- mask = ImageClip(file_name, ismask=True)
- img = mask.get_frame(0)
- img = img.astype('float')
- img /= 255
- mask = VideoClip(lambda a: img, duration=duration, ismask=True)
- return mask
- clip = VideoFileClip('vid.mp4', audio=False)
- bgm = AudioFileClip("bgm.mp3")#.set_duration(5)
- duration = bgm.duration
- bg = ImageClip('bg.png', duration=duration)
- mask = get_mask('mask.png', duration=duration)
- # select 7 bar section and crop
- start, end = 36+57/60, 50+56/60
- x, y, w, h = 889, 650, 140, 139
- loading = clip.subclip(start, end) # t1 is included, t2 is not included
- loading = vfx.crop(loading, x1=x, y1=y, x2=x+w, y2=y+h)
- loading = loading.set_position((x, y))
- # set playspeed in sync with 7 bars
- bpm = 132
- offset = -32/1000
- anim_time = loading.duration
- loading = loading.fl_time(lambda t: ((t-offset)/(60/bpm) / (4*7)) % 1 * anim_time).set_duration(duration)
- # # sync flash with crash
- # def timed_flash(t):
- # bars = (0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 256, 264, 272, 280, 288, 296, 304, 312, 320)
- # types = ('s', 's', '', '', 'k', 's', '', 's', '', 'kk', '', '', '', 'k', 's', 'BO', 's', '', 'kk', 's', '', '', 'k', '', 's', '', 's', 'kk', '', '', '', 'k', 's', 'BO', 's', '', 'kk', '', '', 's', 'k')
- #
- # bar_float = (t - offset) / (60 / bpm) / 4
- # bar_int = int(bar_float)
- # bar_remaining = 1 - (bar_float % 1)
- # lum, con = 0, 0
- # if bar_int in bars:
- # index = bars.index(bar_int)
- # if types[index] == 'BO':
- # if bar_remaining > 3/4:
- # lum = -600 * bar_remaining
- # else:
- # lum = 0
- # else:
- # power = ['', 's', 'k', 'kk'].index(types[index]) + 1
- # lum = power * 100 * (1 - bar_float % 1)
- #
- # flash = clip.set_mask(mask) # crash flash image
- #
- # flash = vfx.lum_contrast(flash, lum=lum, contrast=con, contrast_thr=127)
- # return flash.get_frame(t)
- #
- # flash = VideoClip(timed_flash, duration=duration)
- # compose and save video file
- final = CompositeVideoClip([bg,loading]).set_audio(bgm)
- final.write_videofile("test.mp4", audio_bitrate='320k')
- clip.close()
- bgm.close()
- bg.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement