-
Notifications
You must be signed in to change notification settings - Fork 6
/
Beat_Compiler.py
61 lines (38 loc) · 2.24 KB
/
Beat_Compiler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import librosa
import IPython.display as ipd
import subprocess
from scipy.io.wavfile import write
print(format('.............This is a program used for beat detection................','^40'))
print(" ")
#reading of video and taking some temmporary variables
pathl = input("enter the path of the location of a file where the action is stored and executed\nLike C:\\\\users\\\\rajesh\\\\file_name \nIt should always be in the above format:")
print(" ")
path_video = input("enter the location of the video file which has to be processed \nNote that the file ends with .mp4\nEXAMPLE C:\\\\users\\\\rajesh\\\\file_name\\\\video_name.mp4 :")
print(" ")
path_audio = pathl + '\\audio.wav'
path_videot = pathl + '\\muted_video.mov'
subprocess.call(['ffmpeg','-i',path_video,'-c:v','copy','-an',path_videot])
subprocess.call(['ffmpeg','-i',path_video,'-c:v','copy',path_audio])
path = path_audio
#reading the audio
array, sample_rate = librosa.load(path)
#finding the beat location
bpm , beat_locations = librosa.beat.beat_track(y = array , sr = sample_rate)
#print(bpm)
#print(beat_locations)
#applying clicks in the beat locations
clicks = librosa.clicks(frames = beat_locations, sr=sample_rate, length=len(array))
#producing the clicks_applyed audio (this works in jupyter notebook)
ipd.Audio(array+clicks,rate=sample_rate)
#if not jupyter notebook this will give output
write(path,sample_rate,array+clicks)
print()
#reading the input video path
path_v = path_videot
path_v1 = pathl + '\\tempo_video.mov'
subprocess.call(['ffmpeg','-i',path_v,'-c:v','copy','-an',path_v1])
pathf = pathl + '\\final_output1.mov'
subprocess.call(['ffmpeg', '-i' ,path_v1, '-i' , path , '-c:v', 'copy', '-c:a', 'copy', pathf])
print(" ")
print(" ")
print ('process done you will find the video in the location that you gave by the name final_output1.mov')