Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import moviepy.editor as mp
- import moviepy.video.fx.all as vfx
- import os
- import mido
- import numpy as np
- notes_raw=[]
- notes=[]
- beats=[]
- clips=[]
- subclips = []
- bpm=90 #song bpm
- path='C:/ytpmv/rockstar/' #filepath pt.1
- sourcepath='C:/ytpmv/source vid/' #source path pt.1
- midiname='smoke' #midi filename pt.2
- mp4name='rocks ' #mp4 filename pt.2
- midinames=['gabe','krabs','smoke','oof','sax']
- sourcenames=['gabe','bap','smoke','oof','sax']
- for number, item in enumerate(midinames):
- #if number != 4:
- #continue
- source_clip=0
- concat_clip =0
- notes_raw=[]
- notes=[]
- beats=[]
- clips=[]
- subclips = []
- #these lines reset everything
- mid = mido.MidiFile(path+item+'.mid', clip=True) #mido reads midi file from filepath
- for msg in mid.tracks[2]:
- if (msg.bytes()[0] == 144 or msg.bytes()[0] == 128):
- notes_raw.append(msg.time) #mido appends each note to the array
- notes_raw.pop(0) #the first note and the last note are irregular so we pop them
- notes_raw.pop(-1) #the first note and the last note are irregular so we pop them
- for i in range(0,len(notes_raw)//2):
- notes.append((notes_raw[2*i]+notes_raw[2*i+1]))
- # this loop combines each note and the blank after it into 1 single note.
- beats=list(np.array(notes)/bpm*15/24)
- #math formula for calculating what frame the note should be in.
- #(this line code assumes 24 frames per second)
- beats.append(5) # append 5 because the loop behaves kinda weird if you don't
- #print(notes_raw) #used for debugging
- #print(notes) #used for debugging
- #print(beats) #used for debugging
- source_clip = mp.VideoFileClip(sourcepath+sourcenames[number]+'.mp4') #source clip
- subclips = [source_clip.subclip(0,arr) for arr in beats] #create an array of subclips from the array
- for number2, vids in enumerate(subclips):
- #if number2 % 2 == 0 or number2 < 8:
- if number2 % 2 == 0:
- clips.append(vids)
- else:
- #clips.append(vids.fx(vfx.mirror_x))
- clips.append(vids)
- # this for loop flips every second clip
- concat_clip = mp.concatenate_videoclips(clips, method="compose")
- print(path+mp4name+item+'.mp4')
- concat_clip.write_videofile(path+mp4name+item+'.mp4')
- # concatenate every clip and output it
Advertisement
Add Comment
Please, Sign In to add comment