Guest User

Untitled

a guest
Jul 2nd, 2020
3,060
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. import moviepy.editor as mp
  2. import moviepy.video.fx.all as vfx
  3. import os
  4.  
  5. import mido
  6. import numpy as np
  7.  
  8. notes_raw=[]
  9. notes=[]
  10. beats=[]
  11. clips=[]
  12. subclips = []
  13.  
  14. bpm=90 #song bpm
  15.  
  16. path='C:/ytpmv/rockstar/' #filepath pt.1
  17. sourcepath='C:/ytpmv/source vid/' #source path pt.1
  18. midiname='smoke' #midi filename pt.2
  19. mp4name='rocks ' #mp4 filename pt.2
  20.  
  21. midinames=['gabe','krabs','smoke','oof','sax']
  22.  
  23. sourcenames=['gabe','bap','smoke','oof','sax']
  24.  
  25. for number, item in enumerate(midinames):
  26.  
  27. #if number != 4:
  28. #continue
  29.  
  30. source_clip=0
  31. concat_clip =0
  32. notes_raw=[]
  33. notes=[]
  34. beats=[]
  35. clips=[]
  36. subclips = []
  37.  
  38. #these lines reset everything
  39.  
  40. mid = mido.MidiFile(path+item+'.mid', clip=True) #mido reads midi file from filepath
  41. for msg in mid.tracks[2]:
  42. if (msg.bytes()[0] == 144 or msg.bytes()[0] == 128):
  43. notes_raw.append(msg.time) #mido appends each note to the array
  44.  
  45. notes_raw.pop(0) #the first note and the last note are irregular so we pop them
  46. notes_raw.pop(-1) #the first note and the last note are irregular so we pop them
  47.  
  48.  
  49. for i in range(0,len(notes_raw)//2):
  50. notes.append((notes_raw[2*i]+notes_raw[2*i+1]))
  51. # this loop combines each note and the blank after it into 1 single note.
  52.  
  53. beats=list(np.array(notes)/bpm*15/24)
  54. #math formula for calculating what frame the note should be in.
  55. #(this line code assumes 24 frames per second)
  56.  
  57. beats.append(5) # append 5 because the loop behaves kinda weird if you don't
  58.  
  59. #print(notes_raw) #used for debugging
  60. #print(notes) #used for debugging
  61. #print(beats) #used for debugging
  62.  
  63. source_clip = mp.VideoFileClip(sourcepath+sourcenames[number]+'.mp4') #source clip
  64.  
  65. subclips = [source_clip.subclip(0,arr) for arr in beats] #create an array of subclips from the array
  66.  
  67.  
  68. for number2, vids in enumerate(subclips):
  69. #if number2 % 2 == 0 or number2 < 8:
  70. if number2 % 2 == 0:
  71. clips.append(vids)
  72. else:
  73. #clips.append(vids.fx(vfx.mirror_x))
  74. clips.append(vids)
  75. # this for loop flips every second clip
  76.  
  77. concat_clip = mp.concatenate_videoclips(clips, method="compose")
  78. print(path+mp4name+item+'.mp4')
  79. concat_clip.write_videofile(path+mp4name+item+'.mp4')
  80. # concatenate every clip and output it
Advertisement
Add Comment
Please, Sign In to add comment