forked from thtl1999/BanG-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakevideo.py
More file actions
80 lines (61 loc) · 2.13 KB
/
makevideo.py
File metadata and controls
80 lines (61 loc) · 2.13 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from pydub import AudioSegment
import moviepy.editor as mp
def readone(f):
line = f.readline().replace('\n','')
return line
def get_time(line,bpm,lbb,lbt):
beat = float(line.split('/')[0]) - lbb
return (beat * 60000/bpm) + lbt
def get_notes(musiccode):
f = open('data/score/' + musiccode + 'ex.txt')
notes = []
music_offset = 0
ns = ['1','3','4','5','6','7','8','10','11','9','21','25']
fs = ['2','26','12','13']
ss = ['0','20']
music_offset = int(readone(f))
bpm = float(readone(f))
lbb = 0 #last bpm beat
lbt = 0 #last bpm time
lines = f.readlines()
for line in lines:
type = line.split('/')[1]
if type == '0':
music_offset += get_time(line,bpm,lbb,lbt)
if type == '20':
lbt = get_time(line, bpm, lbb, lbt)
bpm = float(line.split('/')[2].replace('\n',''))
lbb = float(line.split('/')[0])
if type in ns:
notes.append({'type':'n','time':get_time(line,bpm,lbb,lbt)})
if type in fs:
notes.append({'type':'f','time':get_time(line,bpm,lbb,lbt)})
return (notes, music_offset)
musiccode = '187'
musiccode = input('Write 3 digit number: ')
notes, music_offset = get_notes(musiccode)
print(notes)
default_offset = 332
music_vol = 0
se_vol = -5
master_vol = 0
normal = AudioSegment.from_file("data/normal.wav")
flick = AudioSegment.from_file("data/flick.wav")
music = AudioSegment.from_file("data/music/bgm" + musiccode + ".mp3")
offset = AudioSegment.silent(duration= default_offset + music_offset)
music = music + music_vol
normal = normal + se_vol
flick = flick + se_vol
sound = AudioSegment.silent(duration=0) + music
for note in notes:
if note['type'] == 'n':
se_type = normal
if note['type'] == 'f':
se_type = flick
pos = int(note['time'])
sound = sound.overlay(se_type, position=pos)
sound = offset + sound
sound = sound + master_vol
sound.export("out.mp3", format="mp3")
video = mp.VideoFileClip('Recorded.avi')
video.write_videofile('output.mp4', audio='out.mp3')